Creating multiple portfolios using risk bands
Before we can get to the MPT-specific concerns, we need to get some market data and format it specifically for the modules we will be using. If you end up using different modules or writing your own efficient frontier code, you may need different data formatting. Now, let’s download some market data:
df = yf.download("SPY TLT",group_by="Ticker",period="20y") df
We just need one simple command to download a lot of data, in fact, daily prices for 20 years for the two ETFs in our portfolios. To see what we got, you can simply run the DataFrame object by calling df
. We should see something like this:
Figure 8.5 – A sample of our first market data
We can see that the resulting DataFrame has an interesting structure with two layers of columns. We have various numeric values for both SPY
and TLT
one after another, organized by the date as the index. What we need is...