Theta Forecast
Install and import#
npm install fintech-algorithmsimport { 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#
| Name | Type | Notes |
|---|---|---|
values | number[] | Observation series in chronological order, oldest first. |
alpha | number | Smoothing factor for the exponential component, 0…1. min: 0 |
horizon | number | Steps 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#
[10, 12, 14, 16]0.52Call#
forecastTheta(values, alpha, horizon)Returns#
object with 1 field: forecast
{
"forecast": [16.125, 17.125]
}Diagrams#
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.
References#
- The theta model: a decomposition approach to forecasting — V. Assimakopoulos and K. Nikolopoulos
- Unmasking the Theta method — Rob J. Hyndman and Md Baki Billah
- The Theta Model — 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