Existing risk measurement methods often fail to fully consider the impact of climatic conditions on stock market risk, making it difficult to capture dynamic patterns and long-term dependencies. To address these issues, we propose the TS-GRU method: this approach utilizes a temporal convolutional network (TCN) to extract underlying features from historical data, capturing key characteristics of time series data. Subsequently, a gated recurrent unit (GRU) model is employed to capture dynamic patterns and long-term dependencies within the stock market. Finally, the TS-GRU model is optimized using the Sparrow algorithm based on collective behavior, iteratively evaluating and refining model parameters to obtain improved solutions. Experimental results demonstrate the effectiveness of the TS-GRU method in providing accurate risk assessment and forecasting. This comprehensive approach takes into account carbon finance, climate change, and environmental factors, offering valuable insights to investors to help them to understand and manage investment risks in the ever-changing stock market.