Name | regularized-var JSON |
Version |
0.1.1
JSON |
| download |
home_page | None |
Summary | Regularized Vector Autoregression (VAR) with ridge shrinkage, Minnesota prior, metrics, and walk-forward validation. |
upload_time | 2025-09-01 21:43:31 |
maintainer | None |
docs_url | None |
author | Rachel Doehr |
requires_python | >=3.8 |
license | The MIT License (MIT)
Copyright (c) 2025, Rachel Doehr
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
var
econometrics
forecasting
ridge
time series
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[](https://pypi.org/project/regularized-var/)
[](https://pypi.org/project/regularized-var/)
# regularized-var
Vector Autoregression (VAR) with l2 regularization, optional Minnesota prior, error metrics, and walk-forward validation.
## Install
```bash
pip install regularized-var
```
## Quickstart
```python
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"](https://www.jstor.org/stable/1391384)) 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 index
- `j`: 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.
Raw data
{
"_id": null,
"home_page": null,
"name": "regularized-var",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "VAR, econometrics, forecasting, ridge, time series",
"author": "Rachel Doehr",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/2e/71/e594f7f8fed4657a67a0285ef7a560d14a17ef5849f52f9af7ad56bdfa2f/regularized_var-0.1.1.tar.gz",
"platform": null,
"description": "[](https://pypi.org/project/regularized-var/)\n[](https://pypi.org/project/regularized-var/)\n\n# regularized-var\n\nVector Autoregression (VAR) with l2 regularization, optional Minnesota prior, error metrics, and walk-forward validation.\n\n## Install\n```bash\npip install regularized-var\n```\n\n## Quickstart\n\n```python\nimport pandas as pd\nfrom regularized_var.var import VAR, MinnesotaVAR\nfrom regularized_var.metrics import mse\nfrom regularized_var.model_selection import WalkForward, WalkForwardValidator\n\n# Data\ndf = pd.DataFrame(...)\n\n# VAR\nmodel = VAR(n_lags=2, alpha=0.1).fit(df)\nprint(model.predict(steps=5))\n\n# MinnesotaVAR\nmvar = MinnesotaVAR(n_lags=3, alpha_own=1.0, alpha_cross=2.0).fit(df)\nprint(mvar.predict(steps=3))\n\n# Walk-forward validation\nsplitter = WalkForward(train_size=1000, min_train_size=500, horizon=5)\nwf = WalkForwardValidator(VAR, {\"n_lags\": 2, \"alpha\": 0.1}, splitter, metric=mse)\nwf.run(df)\nprint(wf.overall_score_)\n```\n\n## Mathematical Formulation\n\n### Ridge-regularized VAR\nThe baseline `VAR` class solves a ridge-penalized least squares problem:\n\n\n\nwhere Y are the responses, Z is the lagged design matrix,\nand the intercept (if present) is excluded from the penalty.\n\nThis is equivalent to multivariate ridge regression (scikit-learn\u2019s `Ridge`) applied equation-by-equation, but solved in closed form for all equations at once.\n\n### MinnesotaVAR as Weighted Ridge\nThe *Minnesota prior* (see [Litterman, 1986: \"Forecasting with Bayesian Vector Autoregressions \u2014 Five Years of Experience\"](https://www.jstor.org/stable/1391384)) is a Bayesian shrinkage approach that imposes beliefs about how coefficients in a VAR should behave:\n\n- Own-lag coefficients are shrunk toward 0 (for stationary/differenced data: growth rates, returns, etc.)\n- Cross-lag coefficients (other variables) are shrunk more heavily toward 0\n- Higher lags are shrunk more strongly than shorter lags\n\nIn practice, this leads to a **ridge-style penalty** on the coefficient matrix:\n\n\n\nwith weights\n\n\n\n- `i`: target equation index\n- `j`: predictor variable index\n- `\u2113`: lag index\n\nThis weighted \u2113\u2082 penalty reproduces a structure similar to the **Minnesota prior**, where:\n- own lags are shrunk mildly,\n- cross-variable lags are shrunk more heavily,\n- higher-order lags are shrunk progressively more.\n\nThus, `MinnesotaVAR` can be seen as a **structured ridge regression** equivalent of the Minnesota Bayesian prior.\n",
"bugtrack_url": null,
"license": "The MIT License (MIT)\n Copyright (c) 2025, Rachel Doehr\n \n Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "Regularized Vector Autoregression (VAR) with ridge shrinkage, Minnesota prior, metrics, and walk-forward validation.",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/RachelDoehr/regularized-var",
"Issues": "https://github.com/RachelDoehr/regularized-var/issues"
},
"split_keywords": [
"var",
" econometrics",
" forecasting",
" ridge",
" time series"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "f65aa158df0e6793066a369a3bd58d0d551f7b353eb7da2d228d4beee9a442c1",
"md5": "5b75b507ff572f37cd92518660ae2bd6",
"sha256": "0439f47fb4990dbaf2c11d9f57a233883cdab1d06cc463e0e28571336df30dd3"
},
"downloads": -1,
"filename": "regularized_var-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5b75b507ff572f37cd92518660ae2bd6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 10853,
"upload_time": "2025-09-01T21:43:30",
"upload_time_iso_8601": "2025-09-01T21:43:30.470672Z",
"url": "https://files.pythonhosted.org/packages/f6/5a/a158df0e6793066a369a3bd58d0d551f7b353eb7da2d228d4beee9a442c1/regularized_var-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "2e71e594f7f8fed4657a67a0285ef7a560d14a17ef5849f52f9af7ad56bdfa2f",
"md5": "35e4bdd505a06f12e81652e1a41f1618",
"sha256": "320f30adcee35292c7808ff92b65ad993133bd3dcf80e011ab0144ca503f3382"
},
"downloads": -1,
"filename": "regularized_var-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "35e4bdd505a06f12e81652e1a41f1618",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 30085,
"upload_time": "2025-09-01T21:43:31",
"upload_time_iso_8601": "2025-09-01T21:43:31.412836Z",
"url": "https://files.pythonhosted.org/packages/2e/71/e594f7f8fed4657a67a0285ef7a560d14a17ef5849f52f9af7ad56bdfa2f/regularized_var-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-01 21:43:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "RachelDoehr",
"github_project": "regularized-var",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "regularized-var"
}