# ARIMA

`D09-F02-A03` · Statistical Time Series → Forecast Models · archetype `record-transform` · difficulty 3/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/statistical-time-series/forecast-models/arima/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { forecastARIMA } from "fintech-algorithms/statistical-time-series/forecast-models/arima";
```

## Signature

```ts
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 | Required | Notes |
| --- | --- | --- | --- |
| `values` | `number[]` | yes | Observation series in chronological order, oldest first. |
| `ar` | `number[]` | yes | Autoregressive coefficients. |
| `ma` | `number[]` | yes | Moving-average coefficients. |
| `intercept` | `number` | yes | Constant term. |
| `differenceOrder` | `number` | yes | Number of differences applied. One is usual for prices; two is rarely justified. · min: 0, integer: true |
| `horizon` | `number` | yes | 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

This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

### Input

`values`:

```json
[100, 102, 105, 109, 114, 120]
```

`ar`:

```json
[0.5]
```

`ma`:

```json
[]
```

`intercept`:

```json
1
```

`differenceOrder`:

```json
1
```

`horizon`:

```json
2
```

### Call

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

### Returns

object with 1 field: forecast

```json
{
  "forecast": [124, 127]
}
```

## Verification and provenance

Tier: **verified** (via input-expected).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/statistical-time-series/forecast-models/arima/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/statistical-time-series/forecast-models/arima/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/statistical-time-series/llms.txt
