Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-229

Sharpe Tangency Weights

Problem

Compute the tangency portfolio weights for two risky assets plus a risk-free rate.

With diagonal covariance, weights are proportional to (mu_i - rf) / sigma_i ** 2. Normalize them to sum to 1 and return [w1, w2]. Return [0.0, 0.0] when a volatility or the total is zero.

Hint

The tangency portfolio maximizes the Sharpe ratio, scaling each excess return by its variance.

Test cases

case 1
in: [0.1,0.15,0.2,0.3,0.02]
expected: [0.5806451612903225,0.4193548387096775]
case 2
in: [0.1,0.15,0.2,0.3,0.2]
expected: [0.8181818181818181,0.1818181818181819]
case 3
in: [0.1,0.1,0.2,0.2,0.05]
expected: [0.5,0.5]
Starter codePython
def sharpe_tangency(mu1, mu2, s1, s2, rf):
    # Returns [w1, w2]
    # Your code here
    pass

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