fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

ARIMA

Install and import#

bash
npm install fintech-algorithms
ts
import { 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#

NameTypeNotes
valuesnumber[]Observation series in chronological order, oldest first.
arnumber[]Autoregressive coefficients.
manumber[]Moving-average coefficients.
interceptnumberConstant term.
differenceOrdernumberNumber of differences applied. One is usual for prices; two is rarely justified.
min: 0 · integer: true
horizonnumberSteps 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#

values
[100, 102, 105, 109, 114, 120]
ar
[0.5]
ma
[]
intercept
1
differenceOrder
1
horizon
2

Call#

forecastARIMA(values, ar, ma, intercept, differenceOrder, horizon)

Returns#

object with 1 field: forecast

{
  "forecast": [124, 127]
}

Diagrams#

ARIMA — boundary failure
ARIMA — diagnostic workbench
ARIMA — family handoff
ARIMA — forecast origin
ARIMA — recursion anatomy

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.

Read the article →

References#

The rest of the Forecast Models family#