Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-125

Minimum Variance Weights

Problem

Compute minimum-variance portfolio weights for two assets given their volatilities and correlation: w1 = (sigma2^2 - rho * sigma1 * sigma2) / (sigma1^2 + sigma2^2 - 2 * rho * sigma1 * sigma2), and w2 = 1 - w1.

Return [0.5, 0.5] if the denominator is zero.

Hint

Higher correlation pushes more weight into the less volatile asset.

Test cases

case 1
in: [0.2,0.3,0]
expected: [0.6923076923076923,0.3076923076923077]
case 2
in: [0.2,0.3,0.5]
expected: [0.857142857142857,0.14285714285714302]
case 3
in: [0.2,0.2,1]
expected: [0.5,0.5]
case 4
in: [0.1,0.2,-0.5]
expected: [0.7142857142857143,0.2857142857142857]
Starter codePython
def minimum_variance_weights(sigma1, sigma2, rho):
    # Your code here
    pass

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