Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-035

AR(1) Mean and Variance

Problem

For a stationary AR(1) process x[t] = c + phi * x[t-1] + e[t] with innovation variance sigma2, return [mean, variance] where mean = c / (1 - phi) and variance = sigma2 / (1 - phi^2).

If abs(phi) >= 1 return [0.0, 0.0], since no stationary distribution exists.

Hint

The variance inflates by 1 / (1 - phi^2) relative to white noise.

Test cases

case 1
in: [0.5,0.5,1]
expected: [1,1.3333333333333333]
case 2
in: [0,0,2]
expected: [0,2]
case 3
in: [2,-0.5,1]
expected: [1.3333333333333333,1.3333333333333333]
case 4
in: [1,0.9,0.5]
expected: [10.000000000000002,2.6315789473684217]
Starter codePython
def ar1_mean_variance(c, phi, sigma2):
    # Your code here
    pass

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