Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-217

AR(1) Covariance

Problem

Return the n-by-n AR(1) covariance matrix with entries sigma_sq * rho^|i-j|. Return [] when n <= 0 or sigma_sq < 0.

Hint

Correlation decays geometrically with the time gap.

Test cases

case 1
in: [1,0.5,3]
expected: [[1,0.5,0.25],[0.5,1,0.5],[0.25,0.5,1]]
case 2
in: [2,0,2]
expected: [[2,0],[0,2]]
case 3
in: [1,-0.5,2]
expected: [[1,-0.5],[-0.5,1]]
case 4
in: [1,0.5,1]
expected: [[1]]
case 5
in: [1,0.5,0]
expected: []
Starter codePython
def ar1_covariance(sigma_sq, rho, n):
    # Your code here
    pass

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