Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-290

Cumulative Impulse Response AR(1)

Problem

Compute the cumulative impulse response of an AR(1) process through horizon h: the sum from k = 0 to h of phi^k, evaluated with the closed form (1 - phi^(h+1)) / (1 - phi).

For phi = 1.0 return h + 1, and for negative h return 0.0.

Hint

For a stationary process the cumulative response converges to 1 / (1 - phi).

Test cases

case 1
in: [0.5,3]
expected: 1.875
case 2
in: [0.5,0]
expected: 1
case 3
in: [0,5]
expected: 1
case 4
in: [-0.5,3]
expected: 0.625
case 5
in: [1,4]
expected: 5
Starter codePython
def cumulative_impulse_response(phi, h):
    # Your code here
    pass

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