ARIMA
Install and import#
npm install fintech-algorithmsimport { forecastARIMA } from "fintech-algorithms/statistical-time-series/forecast-models/arima";Signature#
forecastARIMA(values, ar, ma, intercept, differenceOrder, horizon)ARMA on a differenced series, with forecasts integrated back to the original level. The integration step is where sign and level errors hide, so both the differenced and the level forecast are returned.
Parameters#
| Name | Type | Notes |
|---|---|---|
values | number[] | Observation series in chronological order, oldest first. |
ar | number[] | Autoregressive coefficients. |
ma | number[] | Moving-average coefficients. |
intercept | number | Constant term. |
differenceOrder | number | Number of differences applied. One is usual for prices; two is rarely justified. min: 0 · integer: true |
horizon | number | Steps ahead. min: 1 · integer: true |
Returns#
{ forecast, fitted, residuals, state, differenced_forecast }
Both the differenced forecast and the integrated one, so the reconstruction can be checked.
Errors#
- When the sample is shorter than the differencing and model order require — 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#
[100, 102, 105, 109, 114, 120][0.5][]112Call#
forecastARIMA(values, ar, ma, intercept, differenceOrder, horizon)Returns#
object with 1 field: forecast
{
"forecast": [124, 127]
}Diagrams#
Calculation flow#
ARIMA 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#
- Forecasting: Principles and Practice — ARIMA models — Rob J. Hyndman and George Athanasopoulos
- statsmodels.tsa.arima.model.ARIMA — statsmodels developers
- 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