Regularized Vector Autoregression (VAR) with ridge shrinkage, Minnesota prior, metrics, and walk-forward validation.
Project description
regularized-var
Vector Autoregression (VAR) with l2 regularization, optional Minnesota prior, error metrics, and walk-forward validation.
Install
pip install regularized-var
Quickstart
import pandas as pd
from regularized_var.var import VAR, MinnesotaVAR
from regularized_var.metrics import mse
from regularized_var.model_selection import WalkForward, WalkForwardValidator
# Data
df = pd.DataFrame(...)
# VAR
model = VAR(n_lags=2, alpha=0.1).fit(df)
print(model.predict(steps=5))
# MinnesotaVAR
mvar = MinnesotaVAR(n_lags=3, alpha_own=1.0, alpha_cross=2.0).fit(df)
print(mvar.predict(steps=3))
# Walk-forward validation
splitter = WalkForward(train_size=1000, min_train_size=500, horizon=5)
wf = WalkForwardValidator(VAR, {"n_lags": 2, "alpha": 0.1}, splitter, metric=mse)
wf.run(df)
print(wf.overall_score_)
Mathematical Formulation
Ridge-regularized VAR
The baseline VAR class solves a ridge-penalized least squares problem:
where Y are the responses, Z is the lagged design matrix, and the intercept (if present) is excluded from the penalty.
This is equivalent to multivariate ridge regression (scikit-learn’s Ridge) applied equation-by-equation, but solved in closed form for all equations at once.
MinnesotaVAR as Weighted Ridge
The Minnesota prior (see Litterman, 1986: "Forecasting with Bayesian Vector Autoregressions — Five Years of Experience") is a Bayesian shrinkage approach that imposes beliefs about how coefficients in a VAR should behave:
- Own-lag coefficients are shrunk toward 0 (for stationary/differenced data: growth rates, returns, etc.)
- Cross-lag coefficients (other variables) are shrunk more heavily toward 0
- Higher lags are shrunk more strongly than shorter lags
In practice, this leads to a ridge-style penalty on the coefficient matrix:
with weights
i: target equation indexj: predictor variable indexℓ: lag index
This weighted ℓ₂ penalty reproduces a structure similar to the Minnesota prior, where:
- own lags are shrunk mildly,
- cross-variable lags are shrunk more heavily,
- higher-order lags are shrunk progressively more.
Thus, MinnesotaVAR can be seen as a structured ridge regression equivalent of the Minnesota Bayesian prior.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file regularized_var-0.1.1.tar.gz.
File metadata
- Download URL: regularized_var-0.1.1.tar.gz
- Upload date:
- Size: 30.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
320f30adcee35292c7808ff92b65ad993133bd3dcf80e011ab0144ca503f3382
|
|
| MD5 |
35e4bdd505a06f12e81652e1a41f1618
|
|
| BLAKE2b-256 |
2e71e594f7f8fed4657a67a0285ef7a560d14a17ef5849f52f9af7ad56bdfa2f
|
File details
Details for the file regularized_var-0.1.1-py3-none-any.whl.
File metadata
- Download URL: regularized_var-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0439f47fb4990dbaf2c11d9f57a233883cdab1d06cc463e0e28571336df30dd3
|
|
| MD5 |
5b75b507ff572f37cd92518660ae2bd6
|
|
| BLAKE2b-256 |
f65aa158df0e6793066a369a3bd58d0d551f7b353eb7da2d228d4beee9a442c1
|