There's more...

We can also plot the two Efficient Frontiers for comparison—the one calculated by minimizing the volatility per expected level of return, and the other one using the convex optimization and maximizing the risk-adjusted return.

The code is as follows:

x_lim = [0.25, 0.6]y_lim = [0.125, 0.325]fig, ax = plt.subplots(1, 2)ax[0].plot(vols_range, rtns_range, 'g-', linewidth=3)ax[0].set(title='Efficient Frontier - Minimized Volatility',          xlabel='Volatility',           ylabel='Expected Returns',          xlim=x_lim,           ylim=y_lim)ax[1].plot(portf_vol_cvx_ef, portf_rtn_cvx_ef, 'g-', linewidth=3)ax[1].set(title='Efficient Frontier - Maximized Risk-Adjusted Return',          xlabel='Volatility',           ylabel='Expected Returns',          xlim=x_lim,           ylim=y_lim)

The only thing ...

Get Python for Finance Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.