January 2020
Beginner to intermediate
432 pages
11h 24m
English
We can also use the optimization approach to find the weights that generate a portfolio with the highest expected Sharpe ratio—the Tangency Portfolio. To do so, we first need to define the objective function, which is the negative of the Sharpe ratio. The reason why we use the negative is that the optimization algorithms run minimization problems. We can easily approach the maximization problems by changing the sign of the objective metric:
def neg_sharpe_ratio(w, avg_rtns, cov_mat, rf_rate): portf_returns = np.sum(avg_rtns * w) portf_volatility = np.sqrt(np.dot(w.T, np.dot(cov_mat, w))) portf_sharpe_ratio = (portf_returns - rf_rate) / portf_volatility return -portf_sharpe_ratio ...
Read now
Unlock full access