plt.grid(True)
plt.axhline( 0 , color=‘k’, ls=‘—’, lw=2.0)
plt.axvline( 0 , color=‘k’, ls=‘—’, lw=2.0)
plt.xlabel(‘expected volatility’)
plt.ylabel(‘expected return’)
plt.colorbar(label=‘Sharpe ratio’)
Figure 11-14. Capital market line and tangency portfolio (star) for risk-free rate of 1%
The portfolio weights of the optimal (tangent) portfolio are as follows. Only three of the
five assets are in the mix:
In [ 75 ]: cons = ({‘type’: ‘eq’, ‘fun’: lambda x: statistics(x)[ 0 ] - f(opt[ 2 ])},
{‘type’: ‘eq’, ‘fun’: lambda x: np.sum(x) - 1 })
res = sco.minimize(min_func_port, noa * [1. / noa,], method=‘SLSQP’,
bounds=bnds, constraints=cons)
In [ 76 ]: res[‘x’].round( 3 )
Out[76]: array([ 0.684, 0.059, 0.257, -0. , 0. ])