Trying to optimize a portfolio with 3 stocks. How do I optimize the weightage of each stock to maximize sharpe ratio based on the formula below. I have used a weightage of (0.3,0.2,0.5) for starters but would like a way to optimize it.
Requirement: Minimum weightage per stock needs to be > 0.05
A_return = 0.05
B_return = 0.06
C_return = 0.04
A_stdv = 0.03
B_stdv = 0.05
C_stdv = 0.04
corr_AB = 0.21
corr_AC = 0.08
corr_BC = 0.36
weight_A = 0.3
weight_B = 0.2
weight_C = 0.5
sharpe_ratio = (
(weight_A * A_return) + (weight_B * B_return) + (weight_B * B_return)
) / np.sqrt(
((weight_A**2) * (A_stdv**2))
+ ((weight_B**2) * (B_stdv**2))
+ ((weight_C**2) * (C_stdv**2))
+ (2 * corr_AB * A_stdv * B_stdv * weight_A * weight_B)
+ (2 * corr_AC * A_stdv * C_stdv * weight_A * weight_C)
+ (2 * corr_BC * B_stdv * C_stdv * weight_B * weight_C)
)
print(sharpe_ratio) # 1.3861547395951404
Not sure if I need to use a loop to iterate the different combinations?