All problems
Cointegration Spread Z-Score
Problem
Given paired series y and x and a hedge ratio beta, form the spread y - beta * x and return the z-score of its latest value: (last - mean) / population_std.
Return 0.0 when the spread is constant or contains fewer than two points.
Hint
Standardizing the spread tells you how stretched the mean-reversion trade is.
Test cases
case 1
in: [[10,12,9],[8,9,7],0.5]
expected: -0.9805806756909198
case 2
in: [[1,2,3],[0,0,0],1]
expected: 1.224744871391589
case 3
in: [[5,6],[2,2],1]
expected: 1
case 4
in: [[2,4,6],[1,1,1],2]
expected: 1.224744871391589
case 5
in: [[1,2],[0,0],1]
expected: 1
Starter codePython
def cointegration_spread_zscore(y, x, beta):
# Your code here
pass5 test cases · run your code against them in the editor