Rolling Connectedness

Calculate the Diebold-Yilmaz connectedness of the tickers over a rolling window: how the total connectedness and each ticker’s net connectedness move over time.

Every window of window observations gets its own VAR(lags) fit on every ticker’s column (Return by default) and its own Generalized Forecast Error Variance Decomposition at horizon periods (see get_connectedness), dated by the last observation of the window, so a value only uses data up to its date. Diebold and Yilmaz (2012) use 200-day windows and a 10-day horizon. A total connectedness that jumps marks a period in which shocks travel between the tickers (2008, March 2020); a ticker whose net connectedness turns positive becomes a transmitter of shocks.

The formula is as follows:

\[\text{Total}\; \text{Connectedness}_{t} = \frac{\sum(\text{i≠j}) \tilde{\theta}_{ij,t}(H)}{N}\] \[\text{Net}_{i,t} = \sum(\text{j≠i}) \tilde{\theta}_{ji,t}(H) - \sum(\text{j≠i}) \tilde{\theta}_{ij,t}(H)\]

Where \(\tilde{\theta}_{ij} , \text{\_} \{t\} (H)\) is the normalized generalized variance share of ticker i’s H-step forecast error variance due to shocks to ticker j, from the VAR fitted on the window observations up to t, and N the number of tickers. Both are decimals.

Also known as: rolling spillover index, dynamic connectedness.

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

Install the Finance Toolkit with pip install financetoolkit -U, then call get_rolling_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_rolling_connectedness()

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

What were the total Diebold-Yilmaz connectedness of Apple, Microsoft, JPMorgan Chase and ExxonMobil and each one's net connectedness over 200-day windows on the last five trading days of 2025, with data from 2021?

Which returns:

Using Your Own Data

get_rolling_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_rolling_connectedness()

Parameters

get_rolling_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
windowintThe number of observations of every VAR fit. Defaults to 200.20
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
transformstr | list[str] | NoneTime series steps applied to the result in order, such as “sma:12” (moving average), “ema:12”, “std:12”, “zscore:60”, “percentile:120”, “yoy”, “pct_change:3,annualize:3”, “log”, “diff”, “cumsum” or “hp_trend” and “hp_cycle” (Hodrick-Prescott), along the dates of each series. A window needs that many periods of the result, so its first periods are empty. Defaults to None.None
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. (2012). “Better to Give than to Receive: Predictive Directional Measurement of Volatility Spillovers.” International Journal of Forecasting, 28(1), 57-66.
  • 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