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

Holt-Winters

Install and import#

bash
npm install fintech-algorithms
ts
import { forecastHoltWintersAdditive } from "fintech-algorithms/statistical-time-series/forecast-models/holt-winters";

Signature#

forecastHoltWintersAdditive(values, alpha, beta, gamma, period, horizon, initialLevel, initialTrend, initialSeasonals)

Additive Holt-Winters: exponential smoothing of level, trend and seasonality. Unfashionable and frequently competitive with far more complex methods on short seasonal series.

Parameters#

NameTypeNotes
valuesnumber[]Observation series in chronological order, oldest first.
alphanumberLevel smoothing factor, 0…1.
min: 0
betanumberTrend smoothing factor, 0…1.
min: 0
gammanumberSeasonal smoothing factor, 0…1.
min: 0
periodnumberSeasonal period.
min: 2 · integer: true
horizonnumberSteps ahead.
min: 1 · integer: true
initialLevelnumberStarting level.
initialTrendnumberStarting trend.
initialSeasonalsnumber[]Starting seasonal factors, one per period step. Additive factors should sum to approximately zero.

Returns#

{ forecast, fitted, residuals, trace, state }

Forecasts with a trace of level, trend and seasonal components at each step.

Errors#

  • When any smoothing factor falls outside 0…1, or initialSeasonals is not of length period — 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, 11, 13]
alpha
0.5
beta
0.5
gamma
0.5
period
2
horizon
2
initialLevel
9
initialTrend
1
initialSeasonals
[-1, 1]

Call#

forecastHoltWintersAdditive(values, alpha, beta, gamma, period, horizon, initialLevel, initialTrend, initialSeasonals)

Returns#

object with 1 field: forecast

{
  "forecast": [12.35546875, 14.58203125]
}

Diagrams#

Holt-Winters — boundary failure
Holt-Winters — diagnostic workbench
Holt-Winters — family handoff
Holt-Winters — forecast origin
Holt-Winters — recursion anatomy

Calculation flow#

Holt-Winters 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#