How it works...
In Steps 2 and 3, we downloaded data using pandas_datareader and yfinance. This is very similar to what we did in the Implementing the Fama-French three-factor model in Python recipe, so at this point, we will not go into too much detail about this.
In Step 4, we calculated the portfolio returns as a weighted average of the portfolio constituents. This is possible as we are working with simple returns – for more details, please refer to the Converting prices to returns recipe in Chapter 1, Financial Data and Preprocessing. Bear in mind that this simple approach assumes that, at the end of each month, we have exactly the same asset allocation (as indicated by the weights). This can be achieved with portfolio rebalancing, that ...
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