Quarterly sales that grow and also repeat a yearly pattern need a forecast that carries three things forward: where the series is now (the level), how fast it is changing (the trend), and the usual bump for each position in the season. The additive Holt-Winters method tracks all three with three smoothing updates.
Implement holt_winters_additive(series, m, alpha, beta, gamma, horizon).
Inputs. series: a list of n numbers y0,…,yn−1 with n≥2m. m: the season length, m≥2. alpha, beta, gamma: the smoothing weights for the level, the trend and the season, each in [0,1]. horizon: the number of future periods H≥1 to forecast.
Initialization. Let A1 be the mean of the first season y0,…,ym−1 and A2 the mean of the second season ym,…,y2m−1. The starting level, trend and seasonal values are
ℓm−1=A1,bm−1=mA2−A1,si=yi−A1(i=0,…,m−1)
Updates. For t=m,m+1,…,n−1:
ℓt=α(yt−st−m)+(1−α)(ℓt−1+bt−1)
bt=β(ℓt−ℓt−1)+(1−β)bt−1
st=γ(yt−ℓt−1−bt−1)+(1−γ)st−m
Forecast. For h=1,…,H:
y^n−1+h=ℓn−1+hbn−1+sn−m+((h−1)modm)
The forecast uses the last m seasonal values in order and starts over from the first of them when H>m.
Output. A dict with:
"level": ℓn−1
"trend": bn−1
"seasonal": the list [sn−m,…,sn−1]
"forecast": the list of H forecasts
Round every number to 4 decimals.
Notes
- The updates start at t=m, so the second season is used twice: once in the starting trend and again in the updates.
- The seasonal update uses the previous level and trend, ℓt−1+bt−1, not the new level ℓt. Some books use the new level, which gives different numbers.
- n does not have to be a multiple of m.