How it works...
In Step 2, we defined parameters used for this recipe, such as the considered timeframe, the risky assets we wanted to use for building the portfolio, and the number of simulations. An important thing to note here is that we also ran RISKY_ASSETS.sort(), to sort the list alphabetically. This matters when interpreting the results as when downloading data from Yahoo Finance using the yfinance library, the obtained prices are ordered alphabetically, not as specified in the provided list. Having downloaded the stock prices, we calculated simple returns using the pct_change method of a pandas DataFrame, and dropped the first row containing NaNs.
For evaluating the potential portfolios, we needed the average (expected) annual return ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access