Before you start
Forecast a series with Holt's linear trend method, which is double exponential smoothing.
Simple exponential smoothing tracks a level and forecasts a flat line. Holt's
method also tracks a trend, so the forecast is a sloped line. Both are updated
with exponential smoothing at every step, with alpha for the level and beta
for the trend.
Start with level = x[0] and trend = x[1] - x[0]. Then for t = 1, ..., n-1:
new_level = alpha * x[t] + (1 - alpha) * (level + trend)
trend = beta * (new_level - level) + (1 - beta) * trend
level = new_level
After the last value, the forecast h steps ahead is level + h * trend, for
h = 1, ..., horizon.
def holt_forecast(x, alpha, beta, horizon):
Input
holt_forecast(np.array([3.0, 5.0, 4.0, 6.0]), alpha=0.5, beta=0.5, horizon=2)
Output
array([7.4375, 8.5 ])
Reasoning
The start is level 3, trend 2. At t = 1 the level becomes 5 and the
trend stays 2. At t = 2 the value 4 is below the forecast 7, so the
level becomes 5.5 and the trend drops to 1.25. At t = 3 the level becomes
6.375 and the trend 1.0625. The forecasts are 6.375 + 1.0625 and
6.375 + 2 * 1.0625.
len(x) >= 2, and alpha and beta are in [0, 1].(horizon,).Check runs the visible cases against a fresh kernel. Submit runs the hidden ones too.
⇧↵run cell