Skip to content
DeepForgeby svx
All problems
HardTime Seriests-039

AR(2) Simulated Variance

Problem

Simulate an AR(2) process x[t] = phi1 * x[t-1] + phi2 * x[t-2] + e[t] with standard normal innovations and return the population variance of the generated values. Call random.seed(seed), discard the first 100 observations as burn-in, then collect n values.

Return 0.0 if n is not positive. The parameter pair is assumed to satisfy the stationarity conditions.

Hint

Keep the last two simulated values in a small list and append each new draw.

Test cases

case 1
in: [0.5,0.2,200,42]
expected: 1.7542622157049643
case 2
in: [0.3,-0.4,200,7]
expected: 1.2567030545273807
case 3
in: [0.6,0.3,200,1]
expected: 3.835498405994975
case 4
in: [0,0,200,5]
expected: 1.009451643912433
Starter codePython
import random
def ar2_simulated_variance(phi1, phi2, n, seed):
    # Your code here
    pass

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