Skip to main content

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 import VAR, MinnesotaVAR, mse, 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:

Equation 0

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:

Equation 1

with weights

Equation 2

  • (i): target equation index
  • (j): predictor variable index
  • (l): 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

regularized_var-0.1.0.tar.gz (29.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

regularized_var-0.1.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file regularized_var-0.1.0.tar.gz.

File metadata

  • Download URL: regularized_var-0.1.0.tar.gz
  • Upload date:
  • Size: 29.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for regularized_var-0.1.0.tar.gz
Algorithm Hash digest
SHA256 57944890fd6443769d9c10d5ab0e0640fc2410344ad429269b81eeb7dbf0db4d
MD5 b512221096827a6d70c7bb1517e8cb5d
BLAKE2b-256 b55086a6ab068e639cf48e8f6b5749bf32bc0a9a2618489aace25d481606cbb8

See more details on using hashes here.

File details

Details for the file regularized_var-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for regularized_var-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4147c50799faa6bd384ccf033c0e48cfecea5d16b4d44345b1a8328687730a3e
MD5 1e91f7d46a48cd0cf2fbe0a8e27da0ac
BLAKE2b-256 4060180573232d688eabb04034b41cfe918f230491afcb94fe86ece2f42a84dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page