I mentioned in a previous post on how to get (nearly) live stock data from Google Finance. However, if you start pulling data from different markets, daily historical rates won’t make sense as different markets are closed on different days. This causes problems when trying to figure out the correlation between stocks. A solution to this is to pull monthly rates as the adjusted stock price for each month will be a better indicator of correlation.
Python has a great library called pandas_datareader that allows you to pull in historical information right into a pandas dataframe. The only downside is if an API is deprecated, your code breaks. Hence, I’ve elected to create this tutorial using Yahoo Finance’s Historical data download function. The objective of this article is to pull a large amount of worldwide historical data (over 20 years worth) and then use Modern Portfolio Theory (Mean Variance Optimization) to create an efficient frontier. The efficient frontier can help decide asset allocations in your portfolio based on a given risk tolerance and expected return.