All problems
Damped Trend Forecast
Problem
Forecast with a damped trend: level + trend * (phi + phi^2 + ... + phi^h).
When phi is between 0 and 1 the trend contribution flattens as the horizon grows. h <= 0 returns the level itself.
Hint
The geometric sum converges to phi / (1 - phi) as h grows.
Test cases
case 1
in: [10,2,0.5,1]
expected: 11
case 2
in: [10,2,0.5,2]
expected: 11.5
case 3
in: [10,2,0.5,3]
expected: 11.75
case 4
in: [5,0,0.9,5]
expected: 5
Starter codePython
def damped_trend_forecast(level, trend, phi, h):
# Your code here
pass4 test cases · run your code against them in the editor