Fit a Vector Autoregression (VAR) across every ticker in the Toolkit instance and compute the (orthogonalized) Forecast Error Variance Decomposition (FEVD) – what fraction of each ticker’s h-step-ahead forecast error variance is attributable to each ticker’s own structural shock, for h = 1, ..., periods.

Also known as: FEVD, variance decomposition.

The other natural companion to get_var_forecast (alongside get_impulse_response_function, which the FEVD is built from) – see time_series_model.get_variance_decomposition for the full formula. A large own-shock share at short horizons that decays as the horizon grows is the classic signature of a ticker that is initially self-driven but increasingly explained by the rest of the system over time.

The formula is as follows:

\[\text{Θₙ} = \text{Ψₙ} \cdot P,\;\; \text{the orthogonalized moving-average matrices of get\_impulse\_response\_function},\;\; \text{from a VAR(p) on every ticker's column (Return by default)},\;\; p = \text{lags} (1 \;\text{by default})\] \[\text{Share of ticker j's shock in ticker i's h-step forecast error variance:}\;\; \operatorname{ωᵢⱼ}(h) = \operatorname{Σ}(n = \text{0..h-1}) \text{Θₙ} \left[i,\; j\right] ^{2} / \operatorname{Σ}(m = 1..k) \operatorname{Σ}(n = \text{0..h-1}) \text{Θₙ} \left[i,\; m\right] ^{2},\;\; \text{for} \;\; h = \text{1..periods}\]

Variance Decomposition in Python or via the MCP

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_variance_decomposition as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["^VIX", "^GVZ"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.econometrics.get_variance_decomposition(column="Adj Close", periods=20)

Or, after setting up the Finance Toolkit MCP, ask:

How much of the forecast error variance of the VIX and the gold volatility index (GVZ) over 20 days came from shocks to each of them, estimated on their daily levels from 2021 to 2025?

Which returns:

Horizon (‘^VIX’, ‘^VIX’) (‘^VIX’, ‘^GVZ’) (‘^GVZ’, ‘^VIX’) (‘^GVZ’, ‘^GVZ’)
1 1 0 0.1832 0.8168
2 1 0 0.1925 0.8075
3 0.9999 0.0001 0.2016 0.7984
4 0.9998 0.0002 0.2104 0.7896
5 0.9997 0.0003 0.219 0.781
6 0.9996 0.0004 0.2273 0.7727
7 0.9995 0.0005 0.2354 0.7646
8 0.9993 0.0007 0.2432 0.7568
9 0.9991 0.0009 0.2506 0.7494
10 0.9989 0.0011 0.2578 0.7422
11 0.9987 0.0013 0.2647 0.7353
12 0.9985 0.0015 0.2714 0.7286
13 0.9983 0.0017 0.2777 0.7223
14 0.9981 0.0019 0.2837 0.7163
15 0.9978 0.0022 0.2895 0.7105
16 0.9976 0.0024 0.2949 0.7051
17 0.9974 0.0026 0.3002 0.6998
18 0.9971 0.0029 0.3051 0.6949
19 0.9969 0.0031 0.3098 0.6902
20 0.9967 0.0033 0.3142 0.6858

Using Your Own Data

get_variance_decomposition 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_variance_decomposition()

Parameters

get_variance_decomposition 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 to decompose out to. Defaults to 10.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
Share