Variance Decomposition
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.
Variance Decomposition in Python
get_variance_decomposition is part of the Econometrics module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_variance_decomposition as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(["AAPL", "MSFT"], api_key="FINANCIAL_MODELING_PREP_KEY")
toolkit.econometrics.get_variance_decomposition(period="quarterly", periods=5)
Which returns:
| Horizon | (‘AAPL’, ‘AAPL’) | (‘AAPL’, ‘MSFT’) | (‘MSFT’, ‘AAPL’) | (‘MSFT’, ‘MSFT’) |
|---|---|---|---|---|
| 1 | 1 | 0 | 0.5984 | 0.4016 |
| 2 | 0.7993 | 0.2007 | 0.4935 | 0.5065 |
| 3 | 0.7965 | 0.2035 | 0.5049 | 0.4951 |
| 4 | 0.7942 | 0.2058 | 0.502 | 0.498 |
| 5 | 0.7936 | 0.2064 | 0.5022 | 0.4978 |
Parameters
get_variance_decomposition accepts the following parameters:
- period (str, optional): The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”.
- column (str, optional): The historical data column to model. Defaults to “Return”.
- lags (int, optional): The VAR order. Defaults to 1.
- periods (int, optional): The forecast horizon to decompose out to. Defaults to 10.
- include_benchmark (bool, optional): Whether to include “Benchmark” among the tickers modeled jointly. Defaults to False.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.