All problems
AR(1) h-Step Forecast
Problem
Compute the h-step-ahead forecast of an AR(1) model with intercept c, autoregressive coefficient phi, and last observed value y_last. For phi not equal to one the closed form is c * (1 - phi^h) / (1 - phi) + phi^h * y_last.
A unit root (phi = 1) requires the separate form y_last + c * h, and a horizon of zero or less returns the last observed value.
Hint
Stationary forecasts decay toward the unconditional mean c / (1 - phi).
Test cases
case 1
in: [0.5,0.5,2,2]
expected: 1.25
case 2
in: [0,0.9,10,3]
expected: 7.29
case 3
in: [1,1,3,4]
expected: 7
case 4
in: [0.5,0.5,2,0]
expected: 2
Starter codePython
def ar1_h_step_forecast(c, phi, y_last, h):
# Your code here
pass4 test cases · run your code against them in the editor