VAR Diagnostics
Calculate the diagnostics of a Vector Autoregression (VAR) across every ticker: whether the VAR of get_var_forecast is stable and whether its residuals are free of autocorrelation, normal and without volatility clustering.
A VAR whose largest root reaches 1 explodes or wanders instead of returning to its mean, so its forecasts and impulse responses do not settle. Autocorrelated residuals say it needs more lags; non-normal residuals and volatility clustering, which daily returns nearly always have, leave the coefficients valid but make the classical standard errors and forecast intervals too narrow.
The formula is as follows, with k the tickers, T the observations of the fit, p its lags and \(u_{t}\) its residuals, \(C_{j} = \sum_{t} u_{t} u_{t - j}' / T\) their autocovariances:
\[Q = T^{2} \cdot \sum_{j=1}^{h} \frac{\text{Tr}\left(C'_{j} \cdot C_{0}^{-1} \cdot C_{j} \cdot C_{0}^{-1}\right)}{T - j}\] \[w_{t} = P^{-1} \cdot (u_{t} - \bar{u})\] \[\text{JB} = \frac{T \cdot b'_{1} \cdot b_{1}}{6} + \frac{T \cdot b'_{2} \cdot b_{2}}{24}\] \[R_{m}^{2} = 1 - \frac{2 \cdot \text{Tr}\left(\hat{\Omega} \cdot \hat{\Omega}_{0}^{-1}\right)}{k \cdot (k + 1)}\] \[\text{LM} = \frac{T_{a} \cdot k \cdot (k + 1) \cdot R_{m}^{2}}{2}\]The stability check takes the moduli of the eigenvalues of the companion matrix of \(A_{1}\), \(\ldots , A_{p}\): the VAR is stable when the largest is below 1. Q is the portmanteau (Hosking) statistic, chi-squared with \(k^{2} \cdot (h - p)\) degrees of freedom, h = max_lag (10 by default), and Tr the trace. The normality (Lütkepohl) test uses P with P * P’ the residual covariance and \(b_{1}\) and \(b_{2}\) the skewness and excess kurtosis of every component of w; JB is chi-squared with 2k degrees of freedom. The ARCH (multivariate LM) test regresses vech(u_t * \(u_{t}'\)) on a constant and its \(q = 5\) lags, with hat(Omega) and hat(Omega_0) the residual covariances of that regression and of the constant only; LM is over its \(T_{a}\) observations and chi-squared with \(q \cdot k^{2}\) * (k + 1)^2 / 4 degrees of freedom.
Also known as: VAR stability, VAR roots, multivariate portmanteau test, multivariate Ljung-Box test, multivariate Jarque-Bera test, multivariate ARCH test, VAR residual diagnostics.
Example · ^VIX, ^VIX3M · 2021 to 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_var_diagnostics:
from financetoolkit import Toolkit
toolkit = Toolkit(
["^VIX", "^VIX3M"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.econometrics.get_var_diagnostics(lags="bic")
Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:
Is a VAR of the returns of the VIX and the three-month VIX, with its lags chosen by the BIC, stable and are its residuals free of autocorrelation, on data from 2021 to 2025?
Which returns:
| Item | 0 |
|---|---|
| Largest Root Modulus | 0.1361 |
| Stable | 1.0000 |
| Portmanteau Statistic | 50.7538 |
| Portmanteau Degrees of Freedom | 36.0000 |
| Portmanteau P-Value | 0.0524 |
| Normality Statistic | 18,869.1000 |
| Normality Degrees of Freedom | 4.0000 |
| Normality P-Value | 0.0000 |
| ARCH Statistic | 465.6230 |
| ARCH Degrees of Freedom | 45.0000 |
| ARCH P-Value | 0.0000 |
11 rows
Using Your Own Data
get_var_diagnostics 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_var_diagnostics()
Parameters
get_var_diagnostics accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”. | "weekly" |
column | str | The historical data column to model. Defaults to “Return”. | "Return" |
lags | int | str | The VAR order, or the information criterion that selects it, as in get_var_forecast. Defaults to 1. | 2 |
max_lag | int | The autocorrelation lags h of the portmanteau test, more than the VAR order. Defaults to 10. | 10 |
include_benchmark | bool | Whether to include “Benchmark” among the tickers modeled jointly. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |
show_columns | str | list[str] | None | The 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 Lütkepohl, H. (2005). “New Introduction to Multiple Time Series Analysis.” Springer, sections 2.1.1, 4.4, 4.5 and 16.5.
- Paper Hosking, J.R.M. (1980). “The Multivariate Portmanteau Statistic.” Journal of the American Statistical Association, 75(371), 602-608.
- Library Referenced against statsmodels’ VARResults.is_stable, test_whiteness and test_normality