VAR Lag Order Selection

Calculate the information criteria of a Vector Autoregression (VAR) across every ticker for every lag order: how many past periods the VAR of get_var_forecast needs.

More lags always fit the sample better but cost \(k^{2}\) coefficients each, with k the number of tickers. The criteria weigh the fit against those coefficients; the order with the lowest value is the one to use, and get_var_forecast(lags="bic") picks it directly.

The formula is as follows, with every order fitted on the same T observations (those after the first max_lag) and \(\hat{\Sigma}_{p}\) = E’E / T the residual covariance of the VAR(p) with a constant on every ticker’s column (Return by default):

\[\text{AIC}(p) = \ln\left(\text{Det}(\hat{\Sigma}_{p})\right) + \frac{2 \cdot m}{T}\] \[m = p \cdot k^{2} + k\] \[\text{BIC}(p) = \ln\left(\text{Det}(\hat{\Sigma}_{p})\right) + \frac{\ln\left(T\right) \cdot m}{T}\] \[\text{HQ}(p) = \ln\left(\text{Det}(\hat{\Sigma}_{p})\right) + \frac{2 \cdot \ln\left(\ln\left(T\right)\right) \cdot m}{T}\] \[\text{FPE}(p) = \left(\frac{T + k \cdot p + 1}{T - k \cdot p - 1}\right)^{k} \cdot \text{Det}(\hat{\Sigma}_{p})\]

with m the coefficients, k the tickers and Det the determinant.

The BIC and HQ pick the true order as the sample grows; the AIC and FPE tend to pick longer lags, which can suit forecasting.

Also known as: VAR lag selection, lag order selection, VARselect, information criteria.

Example · ^VIX, ^VIX3M · 2021 to 2025

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

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_lag_order(column="Adj Close", max_lag=5)

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

How many lags should a VAR of the VIX and the three-month VIX levels have, by the AIC, BIC, HQ and FPE criteria up to five lags, on data from 2021 to 2025?

Which returns:

Using Your Own Data

get_var_lag_order 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_lag_order()

Parameters

get_var_lag_order 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"
max_lagintThe largest lag order. 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 Lütkepohl, H. (2005). “New Introduction to Multiple Time Series Analysis.” Springer, section 4.3.
  • Paper Akaike, H. (1974). “A New Look at the Statistical Model Identification.” IEEE Transactions on Automatic Control, 19(6), 716-723.
  • Paper Schwarz, G. (1978). “Estimating the Dimension of a Model.” Annals of Statistics, 6(2), 461-464.
  • Paper Hannan, E.J. and Quinn, B.G. (1979). “The Determination of the Order of an Autoregression.” Journal of the Royal Statistical Society, Series B, 41(2), 190-195.
  • Library Referenced against statsmodels’ VAR.select_order
Share