All problems
Risk Parity Weights
Problem
Compute two-asset risk parity weights, which are inversely proportional to volatility: w1 = (1/sigma1) / (1/sigma1 + 1/sigma2).
Return [0.5, 0.5] if both volatilities are non-positive; if only one is non-positive, assign all weight to the other asset.
Hint
Equal risk contributions mean the calmer asset gets the bigger weight.
Test cases
case 1
in: [0.2,0.4]
expected: [0.6666666666666666,0.3333333333333333]
case 2
in: [0.3,0.3]
expected: [0.5,0.5]
case 3
in: [0,0.2]
expected: [0,1]
case 4
in: [0.1,0]
expected: [1,0]
Starter codePython
def risk_parity_weights(sigma1, sigma2):
# Your code here
pass4 test cases · run your code against them in the editor