Plot efficient frontier
We can finally plot the results of our MPT portfolios, which shows the "efficient frontier". This is a plot of the volatility vs the returns. This can help us visualize our risk-return possibilities for portfolios. The upper left boundary of the points is the best we can do (highest return for a given risk), and that is the efficient frontier.
To create this plot, we will use the latest date in our covariances dictionary which we created a few exercises ago. This has dates as keys, so we'll get the sorted keys using sorted() and .keys(), then get the last entry with Python indexing ([-1]). Lastly we'll use matplotlib to scatter variance vs returns and see the efficient frontier for the latest date in the data.
Deze oefening maakt deel uit van de cursus
Machine Learning for Finance in Python
Oefeninstructies
- Get the latest date from the
covariancesdictionary -- remember the dates are the keys. - Plot the volatility vs returns (portfolio_returns) for the latest date in a scatter plot, and set the
alphavalue for transparency to be0.1.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Get latest date of available data
date = sorted(covariances.____)[____]
# Plot efficient frontier
# warning: this can take at least 10s for the plot to execute...
plt.scatter(x=portfolio_volatility[date], y=____, alpha=____)
plt.xlabel('Volatility')
plt.ylabel('Returns')
plt.show()