Connectedness (Diebold-Yilmaz)

Calculate the Diebold-Yilmaz connectedness of the tickers: how much of each ticker’s forecast error variance comes from shocks to the other tickers, in total, from and to each ticker and between each pair.

A VAR(lags) is fitted on every ticker’s column (Return by default) and its Generalized Forecast Error Variance Decomposition (Pesaran and Shin 1998) at horizon periods is read as a network: the share in row i and column j is how much ticker j transmits to ticker i. Unlike get_variance_decomposition, the generalized decomposition does not depend on the order of the tickers. On returns it measures return spillovers, on volatilities volatility spillovers. A total connectedness that rises sharply marks a crisis, when shocks travel between markets; a positive net connectedness marks a transmitter of shocks and a negative one a receiver.

The formula is as follows:

\[\theta_{ij}(H) = \frac{\sigma_{jj}^{- 1} \cdot \sum_{h=0}^{H-1}(e_{i}' \Psi_{h} \sum e_{j})^{2}}{\sum_{h=0}^{H-1}(e_{i}' \Psi_{h} \sum \Psi_{h}' e_{i})}\] \[\tilde{\theta}_{ij}(H) = \frac{\theta_{ij}(H)}{\sum_{j} \theta_{ij}(H)}\] \[\text{From}\; \text{Others}_{i} = \sum(\text{j≠i}) \tilde{\theta}_{ij}(H)\] \[\text{To}\; \text{Others}_{j} = \sum(\text{i≠j}) \tilde{\theta}_{ij}(H)\] \[\text{Net}_{i} = \text{To}\; \text{Others}_{i} - \text{From}\; \text{Others}_{i}\] \[\text{Total Connectedness} = \frac{\sum(\text{i≠j}) \tilde{\theta}_{ij}(H)}{N}\]

Where \(\Psi_{h}\) are the moving-average matrices of the VAR (\(\Psi_{0} = I\)), \(\Sigma\) the residual covariance matrix with diagonal \(\sigma_{jj}\), \(e_{i}\) the i-th unit vector, H = periods and N the number of tickers. Every value is a decimal: a total connectedness of 0.45 means 45% of the forecast error variance comes from shocks to other tickers.

Also known as: spillover index, Diebold-Yilmaz spillover table, generalized variance decomposition.

Example · AAPL, MSFT, JPM, XOM · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_connectedness:

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["AAPL", "MSFT", "JPM", "XOM"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.econometrics.get_connectedness()

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

How much of the forecast error variance of Apple, Microsoft, JPMorgan Chase and ExxonMobil came from shocks to the others from 2021 to 2025, according to the Diebold-Yilmaz connectedness, and who transmitted shocks on balance?

Which returns:

Using Your Own Data

get_connectedness runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:

from financetoolkit import Economics, Econometrics

economics = Economics(start_date="2000-01-01")

unemployment = economics.get_unemployment_rate(
    countries=["United States", "Germany"], period="monthly"
)

econometrics = Econometrics(data=unemployment, changes="difference")

econometrics.get_connectedness()

Parameters

get_connectedness accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”."weekly"
columnstrThe historical data column to model. Defaults to “Return”."Return"
lagsintThe VAR order. Defaults to 1.2
periodsintThe forecast horizon H. Defaults to 10.10
include_benchmarkboolWhether to include “Benchmark” among the tickers modeled jointly. Defaults to False.True
roundingint | NoneThe number of decimals to round the results to. Defaults to None.2
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Diebold, F.X. and Yilmaz, K. (2009). “Measuring Financial Asset Return and Volatility Spillovers, with Application to Global Equity Markets.” The Economic Journal, 119(534), 158-171.
  • Paper Diebold, F.X. and Yilmaz, K. (2012). “Better to Give than to Receive: Predictive Directional Measurement of Volatility Spillovers.” International Journal of Forecasting, 28(1), 57-66.
  • Paper Diebold, F.X. and Yilmaz, K. (2014). “On the Network Topology of Variance Decompositions: Measuring the Connectedness of Financial Firms.” Journal of Econometrics, 182(1), 119-134.
  • Paper Pesaran, H.H. and Shin, Y. (1998). “Generalized Impulse Response Analysis in Linear Multivariate Models.” Economics Letters, 58(1), 17-29.
  • Library Shares similar logic as statsmodels’ VARResults.ma_rep
Share