Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-079

Volatility Autocorrelation

Problem

Compute the lag-k autocorrelation of squared returns, a standard measure of volatility clustering, using the biased 1/n estimator.

Return 0.0 if k is negative or at least the number of returns, or if the squared returns have zero variance.

Hint

Square the returns first so negative and positive shocks both count.

Test cases

case 1
in: [[0.1,-0.2,0.1,-0.2],1]
expected: -0.75
case 2
in: [[1,2,3],0]
expected: 1
case 3
in: [[0,0],1]
expected: 0
case 4
in: [[1,-1,1,-1,1],2]
expected: 0
case 5
in: [[0.1,-0.2,0.3,-0.2,0.1],2]
expected: -0.6794392523364485
Starter codePython
def volatility_autocorrelation(returns, k):
    # Your code here
    pass

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