All problems
AR(2) One-Step Forecast
Problem
Compute the one-step-ahead forecast of a fitted AR(2) model: c + phi1 * y_t + phi2 * y_{t-1}, where y_t is the most recent observation and y_prev the one before it.
All coefficients are scalars and the forecast is returned as a float.
Hint
An AR(2) forecast is a linear combination of the two most recent values plus the intercept.
Test cases
case 1
in: [0.5,0.5,0.25,2,1]
expected: 1.75
case 2
in: [0,0.7,-0.2,5,4]
expected: 2.7
case 3
in: [1,0,0,3,9]
expected: 1
case 4
in: [0.2,0.5,0.3,0,0]
expected: 0.2
Starter codePython
def ar2_one_step_forecast(c, phi1, phi2, y_t, y_prev):
# Your code here
pass4 test cases · run your code against them in the editor