Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-070

Holt-Winters Seasonal Update

Problem

Perform one additive Holt-Winters update step and return [level, trend, seasonal]. Given the old level, trend and seasonal value plus the new observation x: new_level = alpha * (x - seasonal) + (1 - alpha) * (level + trend); new_trend = beta * (new_level - level) + (1 - beta) * trend; new_seasonal = gamma * (x - new_level) + (1 - gamma) * seasonal.

The level and trend updates use the old level and trend; no forecast is produced.

Hint

Deseasonalize the observation before updating the level.

Test cases

case 1
in: [10,0.5,1,12,0.5,0.3,0.4]
expected: [10.75,0.575,1.1]
case 2
in: [5,0.2,-0.5,6,0.4,0.3,0.2]
expected: [5.720000000000001,0.3560000000000002,-0.34400000000000014]
case 3
in: [0,0,0,1,0.5,0.5,0.5]
expected: [0.5,0.25,0.25]
case 4
in: [10,1,2,10,0.2,0.1,0.9]
expected: [10.4,0.9400000000000001,-0.16000000000000036]
Starter codePython
def holt_winters_seasonal_update(level, trend, seasonal, x, alpha, beta, gamma):
    # Your code here
    pass

4 test cases · run your code against them in the editor