Bayesian Calibration of a Generalized SIR Model on Multilayer Trade, Financial and Energy Networks to Estimate GDP Losses in the 2022 Energy Crisis
收藏资源简介:
# Multilayer Contagion Analysis A Bayesian generalized SIR model on multilayer trade, financial andenergy networks for quantifying GDP losses during major economic shocks. ## Overview This project implements a full analytical pipeline for studying economiccontagion across 65 economies over the period 2020Q1 – 2024Q4. It combines: 1. A three-layer weighted network — international trade, cross-border financial exposures, and energy dependency — reconstructed at each forecast origin.2. A generalized SIR compartmental model with resilience modulation and a smooth activation threshold, integrated with a fourth-order Runge-Kutta scheme.3. Bayesian estimation of the dynamic parameters by adaptive Metropolis MCMC (Haario 2001), with formal convergence diagnostics.4. A Simulated Method of Moments (SMM) step to estimate the three layer coupling coefficients.5. Prediction of quarterly GDP deviations from the IMF WEO baseline.6. A four-component Shapley decomposition of the losses into trade, financial, energy and feedback contributions.7. External validation against MSCI equity drawdowns, BIS foreign claims and the IMF financial-sector ranking. Three real-world episodes are studied: the COVID-19 shock (training window),the 2022 energy crisis (validation window), and the 2023 banking-sectorturmoil (out-of-sample test window). ## Repository layout ```MultilayerContagion/├── configs/│ └── config.yaml # forecast origins, MCMC settings, grids├── data/ # 15 input data files (see DATA_SOURCES.md)├── src/│ ├── data_loader.py # loads all 15 input files│ ├── preprocessing.py # GDP deviation and vulnerability index│ ├── networks.py # trade / financial / energy layers, M(t)│ ├── dcc_garch.py # DCC-GARCH(1,1) two-step QMLE│ ├── backbone.py # disparity filter + topology metrics│ ├── sir_model.py # generalized SIR + RK4 integrator│ ├── threshold.py # R_eff, R_inf, bifurcation scan│ ├── bayesian_mcmc.py # adaptive Metropolis + R-hat + ESS│ ├── smm.py # Simulated Method of Moments│ ├── benchmarks.py # B0a, B0b, B1, B5, B6, B7 baselines│ ├── pathways.py # RTS, CIS, entropy weights, CCR│ ├── panel_reg.py # two-way FE + Driscoll-Kraay SE│ ├── shapley.py # four-component Shapley decomposition│ ├── external_val.py # IMF / BIS / MSCI drawdown comparisons│ ├── sensitivity.py # Sobol indices, edge deletion, robustness│ ├── figures.py # Figures 3-13 + Supp Figures 3-4│ ├── tables.py # Tables 1-10 as XLSX│ └── run_all.py # main orchestration script├── tests/│ └── test_module.py # unit and smoke tests├── results/ # generated by run_all.py│ ├── figures/ # 13 PNG figures at 800 DPI│ ├── tables/ # 10 XLSX tables│ └── metrics.json # summary metrics├── requirements.txt├── DATA_SOURCES.md # variable-by-variable description└── README.md``` ## Installation ```bashgit clone <this-repo-url>cd MultilayerContagionpip install -r requirements.txt``` Python 3.11 or 3.12 is recommended. The core scientific stack (numpy, scipy,pandas, networkx, matplotlib, scikit-learn, openpyxl) is pinned in`requirements.txt`. ## How to run Standard pipeline (default, approximately 40 seconds on a modern laptop): ```bashpython -m src.run_all``` Full run with expanded MCMC (4 chains x 5000 iterations) and full Sobolsensitivity (approximately 2-3 hours): ```bashpython -m src.run_all --full``` Individual modules can also be executed standalone for quick verification: ```bashpython -m src.data_loader # verify data loadingpython -m src.networks # verify M(t) constructionpython -m src.threshold # test R_eff, R_infpython -m src.bayesian_mcmc # smoke test the MCMC sampler``` Unit tests: ```bashpython -m pytest tests/ -v``` ## Data The `data/` folder contains 15 files covering economy metadata, GDP,vulnerability indicators, bilateral trade and financial exposures, energytrade and prices, capital stocks, distance and gravity variables, renewableenergy shares, and industrial production. A complete variable-by-variabledescription with units, frequency, sample coverage and public sources isprovided in `DATA_SOURCES.md`. Data files (65 economies, 2020Q1 – 2024Q4): | # | File | Content ||---|------|---------|| 01 | `01_Country_Metadata.xlsx` | ISO3, region, IMF development group, IMF financial tier || 02 | `02_GDP_Quarterly_Panel.xlsx` | Quarterly real GDP and growth || 03 | `03_Vulnerability_Indicators.xlsx` | Trade openness, financial openness, energy import dependence, external debt || 04 | `04_Bilateral_Merchandise_Trade.xlsx` | Bilateral exports (annual, USD) || 05 | `05_Bilateral_Energy_Trade.xlsx` | Bilateral energy trade (annual, USD) || 06 | `06_Bilateral_FDI_CDIS.xlsx` | Bilateral inward FDI positions || 07 | `07_Bilateral_Portfolio_CPIS.xlsx` | Bilateral portfolio holdings || 08 | `08_BIS_Foreign_Claims.xlsx` | BIS Locational Banking Statistics claims || 09 | `09_MSCI_Country_Indexes_Daily.csv` | Daily MSCI country indices (USD) || 09 | `09_MSCI_Country_Indexes_Weekly_Pivot.xlsx` | Weekly MSCI pivot || 10 | `10_Energy_Price_Series.xlsx` | Brent, TTF, World Bank energy price index || 11 | `11_Capital_Stocks.xlsx` | Capital stock series || 12 | `12_CEPII_Distances_and_Gravity.xlsx` | Bilateral distances and gravity controls || 13 | `13_Renewable_Energy_Share.xlsx` | Renewable energy share of final consumption || 14 | `14_Industrial_Production_Index.xlsx` | Monthly industrial production | ## Outputs After a successful run, `results/` contains: - `figures/` — 13 PNG figures at 800 DPI, all with a white background and the Nature-style typography and layout used across the analysis.- `tables/` — 10 XLSX tables (topology, posterior parameters, regional dynamics, prediction accuracy, model comparison, key economies, panel regression, Shapley top-10, Shapley regional shares, and sensitivity).- `metrics.json` — machine-readable summary of the main numeric results. ## Key model outputs Representative summary values produced by the pipeline: | Quantity | Value ||---|---|| Coupling coefficients (c_T, c_F, c_E) | 0.42 / 0.31 / 0.27 || Effective reproduction number R_eff | 1.10 (95% CrI 0.98, 1.24) || Fully-activated reproduction number R_inf | 4.62 (95% CrI 3.68, 5.42) || Peak share of infected economies | 0.43 (day 144) || Aggregate amplification A | 2.68 || Panel coefficient on P_bar | -0.38 (DK SE 0.09) || Backbone links / modularity | 258 / 0.36 || RMSE on out-of-sample test window | 1.68 pp | ## Environment - Python 3.11 or 3.12- Core libraries: numpy 1.24+, scipy 1.11+, pandas 2.0+, networkx 3.1+, matplotlib 3.8+, scikit-learn 1.3+, openpyxl 3.1+- Approximate runtime (standard mode): 40 s on 4 cores / 8 GB RAM ## License MIT.



