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

Theta Forecast

Install and import#

bash
npm install fintech-algorithms
ts
import { forecastTheta } from "fintech-algorithms/statistical-time-series/forecast-models/theta-forecast";

Signature#

forecastTheta(values, alpha, horizon)

The Theta method: decompose, extrapolate, recombine. It won the M3 forecasting competition and is roughly equivalent to simple exponential smoothing with drift — a useful benchmark precisely because it is so simple.

Parameters#

NameTypeNotes
valuesnumber[]Observation series in chronological order, oldest first.
alphanumberSmoothing factor for the exponential component, 0…1.
min: 0
horizonnumberSteps ahead.
min: 1 · integer: true

Returns#

{ forecast, fitted, state }

Forecasts and fitted values.

Errors#

  • When alpha falls outside 0…1 — throws

Complexity: time O(n), 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
[10, 12, 14, 16]
alpha
0.5
horizon
2

Call#

forecastTheta(values, alpha, horizon)

Returns#

object with 1 field: forecast

{
  "forecast": [16.125, 17.125]
}

Diagrams#

Theta Forecast — boundary failure
Theta Forecast — diagnostic workbench
Theta Forecast — family handoff
Theta Forecast — forecast origin
Theta Forecast — recursion anatomy

Calculation flow#

Theta Forecast 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#