DOI: 10.57760/sciencedb.30578
title: Research on the High-order Moment Risk Spillovers between Carbon and Commodity Futures Markets based on Explainable Machine Learning
title: 基于可解释机器学习的碳市场与商品期货市场间高阶矩风险溢出效应驱动因素研究

description: The code document is divided into two parts: R code and Python code. R code (version 4.4.1, RStudio environment) is used for overflow effect analysis; Python code (version 3.12.4, Jupyter Notebook environment) is used for causal relationship testing, machine learning modeling, and SHAP interpretable analysis, with the SHAP package (version 0.44.1) used for model interpretable analysis. The code flow is organized according to the analysis process of the paper. R code: 1. Apply the ACD model to the logarithmic returns of all carbon markets and commodity futures to obtain the corresponding conditional volatility (CSV), conditional skewness (CSV), and conditional kurtosis (CSV) sequences. 2. Use the TVP-VAR extended joint connectivity model to calculate the dynamic total overflow indices of volatility, skewness, and kurtosis, and save the results for subsequent predictive analysis. Python code: 3. Visualize the overflow index mentioned above. 4. Use the nuclear ridge regression nonlinear Granger causality test method to identify the causal relationship structure between the predictor variable and the target variable. 5. Build a prediction system, focusing on selecting Extreme Gradient Boosting (XGBoost), Random Forest, and Lightweight Gradient Boosting Machine (LightGBM), while incorporating K-Nearest Neighbors (KNN) and Support Vector Regression (SVR) as benchmark models for comparison. Apply Optuna tool to perform hyperparameter optimization, combined with 5-fold time series cross validation to ensure model robustness. 6. Apply SHAP interpretability analysis to the optimal model, quantifying the main effect value and interaction effect value of the impact. After obtaining the main effect value, first calculate the average absolute value of each variable's main effect value in Excel and convert it into a percentage form. Then, use Python to draw a feature importance percentage chart. 8. Draw a dependency relationship diagram based on the SHAP main effect value to reveal the dynamic impact pattern of variables on risk spillover. 9. Calculate the average absolute value of SHAP interaction values between features in Excel, obtain the interaction value matrix, and display the SHAP interaction effect strength between each feature in the form of a heatmap using Python. 
description: The code document is divided into two parts: R code and Python code. R code (version 4.4.1, RStudio environment) is used for overflow effect analysis; Python code (version 3.12.4, Jupyter Notebook environment) is used for causal relationship testing, machine learning modeling, and SHAP interpretable analysis, with the SHAP package (version 0.44.1) used for model interpretable analysis. The code flow is organized according to the analysis process of the paper. R code: 1. Apply the ACD model to the logarithmic returns of all carbon markets and commodity futures to obtain the corresponding conditional volatility (CSV), conditional skewness (CSV), and conditional kurtosis (CSV) sequences. 2. Use the TVP-VAR extended joint connectivity model to calculate the dynamic total overflow indices of volatility, skewness, and kurtosis, and save the results for subsequent predictive analysis. Python code: 3. Visualize the overflow index mentioned above. 4. Use the nuclear ridge regression nonlinear Granger causality test method to identify the causal relationship structure between the predictor variable and the target variable. 5. Build a prediction system, focusing on selecting Extreme Gradient Boosting (XGBoost), Random Forest, and Lightweight Gradient Boosting Machine (LightGBM), while incorporating K-Nearest Neighbors (KNN) and Support Vector Regression (SVR) as benchmark models for comparison. Apply Optuna tool to perform hyperparameter optimization, combined with 5-fold time series cross validation to ensure model robustness. 6. Apply SHAP interpretability analysis to the optimal model, quantifying the main effect value and interaction effect value of the impact. After obtaining the main effect value, first calculate the average absolute value of each variable's main effect value in Excel and convert it into a percentage form. Then, use Python to draw a feature importance percentage chart. 8. Draw a dependency relationship diagram based on the SHAP main effect value to reveal the dynamic impact pattern of variables on risk spillover. 9. Calculate the average absolute value of SHAP interaction values between features in Excel, obtain the interaction value matrix, and display the SHAP interaction effect strength between each feature in the form of a heatmap using Python.