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):
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:
| Lags | AIC | BIC | HQ | FPE |
|---|---|---|---|---|
| 0 | 3.7466 | 3.7549 | 3.7497 | 42.3787 |
| 1 | -1.6974 | -1.6728 | -1.6882 | 0.1832 |
| 2 | -1.7054 | -1.6644 | -1.6900 | 0.1817 |
| 3 | -1.7018 | -1.6443 | -1.6802 | 0.1824 |
| 4 | -1.6974 | -1.6235 | -1.6696 | 0.1832 |
| 5 | -1.6945 | -1.6042 | -1.6605 | 0.1837 |
6 rows
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.
| 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" |
max_lag | int | The largest lag 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, 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