Skip to content
DeepForgeby svx
All problems
HardTime Seriests-345

Correlated Error Variance Accumulation

Problem

Compute the variance of the sum of h forecast errors when each error has variance v and errors k steps apart have correlation rho^k. The result is v * (h + 2 * sum over k from 1 to h-1 of (h - k) * rho^k), which accounts for every correlated pair in the horizon.

Return 0.0 when h is not positive.

Hint

There are h - k pairs of errors exactly k steps apart in a horizon of h.

Test cases

case 1
in: [1,0.5,2]
expected: 3
case 2
in: [2,0,3]
expected: 6
case 3
in: [1,0.5,1]
expected: 1
case 4
in: [1,1,3]
expected: 9
case 5
in: [4,0.25,2]
expected: 10
Starter codePython
def correlated_error_variance(v, rho, h):
    # Your code here
    pass

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