Lesson 6 of 15

Sharpe Ratio Maximization (Tangency Portfolio)

Tangency Portfolio

The tangency portfolio is the risky portfolio that maximizes the Sharpe ratio:

SR=μprfσpSR = \frac{\mu_p - r_f}{\sigma_p}

It is the point on the efficient frontier where a line from the risk-free rate is tangent to the frontier.

Analytical Solution for Two Assets

To find the tangency weights, we solve the system of equations z = Σ⁻¹(μ − r_f · 1) and normalize:

zi=(Σ1e)i,wi=zijzjz_i = (\Sigma^{-1} \boldsymbol{e})_i, \quad w_i = \frac{z_i}{\sum_j z_j}

For two assets with covariance matrix Σ = [[σ₁², ρσ₁σ₂], [ρσ₁σ₂, σ₂²]]:

z1=σ22e1ρσ1σ2e2det(Σ),z2=σ12e2ρσ1σ2e1det(Σ)z_1 = \frac{\sigma_2^2 e_1 - \rho \sigma_1 \sigma_2 e_2}{\det(\Sigma)}, \quad z_2 = \frac{\sigma_1^2 e_2 - \rho \sigma_1 \sigma_2 e_1}{\det(\Sigma)}

where eᵢ = μᵢ − r_f and det(Σ) = σ₁²σ₂² − (ρσ₁σ₂)².

Your Task

Implement tangency_weights_2(mu1, mu2, s1, s2, corr, rf) that returns a tuple (w1, w2) of the tangency portfolio weights, each rounded to 4 decimal places.

Python runtime loading...
Loading...
Click "Run" to execute your code.