AutoReg
Install and import#
npm install fintech-algorithmsimport { forecastAutoReg } from "fintech-algorithms/statistical-time-series/forecast-models/autoreg";Signature#
forecastAutoReg(values, ar, intercept, horizon)Forecasts from an autoregression with supplied coefficients. Estimation is deliberately separate: this evaluates a model you already have, which keeps the arithmetic checkable.
Parameters#
| Name | Type | Notes |
|---|---|---|
values | number[] | Observation series in chronological order, oldest first. |
ar | number[] | Autoregressive coefficients, lag 1 first. |
intercept | number | Constant term. |
horizon | number | Steps ahead to forecast. Beyond a few steps an AR forecast converges to the unconditional mean. min: 1 · integer: true |
Returns#
{ forecast, fitted, residuals, state }
Forecasts with in-sample fitted values and residuals — the residuals are what Ljung-Box then tests.
Errors#
- When fewer observations are supplied than the AR order requires — throws
Complexity: time O(n × p),
space O(n).
Worked example#
verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.
Input#
[10, 12, 11][0.5]52Call#
forecastAutoReg(values, ar, intercept, horizon)Returns#
object with 1 field: forecast
{
"forecast": [10.5, 10.25]
}Diagrams#
Calculation flow#
AutoReg Calculation Flow
flowchart LR
A["Finalized equally spaced training series"] --> B["Validate cutoff and frozen parameters"]
B --> C["Build selected state or transformed series"]
C --> D["Calculate horizon h conditional mean"]
D --> E{"More horizons?"}
E -- "yes" --> F["Append forecast and zero future innovation"]
F --> D
E -- "no" --> G["Publish path and state trace"]
G --> H["Reveal holdout only for evaluation"]
How it works#
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References#
- statsmodels.tsa.ar_model.AutoReg — statsmodels developers
- Forecasting: Principles and Practice — ARIMA models — Rob J. Hyndman and George Athanasopoulos
- Forecasting: Principles and Practice — Evaluating point forecast accuracy — Rob J. Hyndman and George Athanasopoulos
- Forecasting: Principles and Practice — Time series cross-validation — Rob J. Hyndman and George Athanasopoulos
- Forecasting: Principles and Practice — Evaluating regression and residual behavior — Rob J. Hyndman and George Athanasopoulos