ARMA
Install and import#
npm install fintech-algorithmsimport { forecastARMA } from "fintech-algorithms/statistical-time-series/forecast-models/arma";Signature#
forecastARMA(values, ar, ma, intercept, horizon)ARMA forecasting with supplied coefficients: autoregressive terms on past values, moving-average terms on past errors.
Parameters#
| Name | Type | Notes |
|---|---|---|
values | number[] | Observation series in chronological order, oldest first. |
ar | number[] | Autoregressive coefficients. |
ma | number[] | Moving-average coefficients applied to past forecast errors. |
intercept | number | Constant term. |
horizon | number | Steps ahead. min: 1 · integer: true |
Returns#
{ forecast, fitted, residuals, state }
Forecasts, fitted values and residuals.
Errors#
- When the sample is shorter than the model order — throws
Complexity: time O(n × (p + q)),
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][0.25]52Call#
forecastARMA(values, ar, ma, intercept, horizon)Returns#
object with 1 field: forecast
{
"forecast": [10.375, 10.1875]
}Diagrams#
Calculation flow#
ARMA 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.arima.model.ARIMA — 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