Charting stocks price from Yahoo Finance using fix-yahoo-finance library

Gerry Sabar
2 min readMay 23, 2019

It’s just unfortunate that Pandas DataReader is no longer able to scrap data from Yahoo finance URL since May 16th 2017. However as the alternative we can use fix-yahoo-finance. In this article I’ll introduce how to use this awesome library to chart 3 company stocks with Dow Jones index.

Charting like this is the basic of scrapping data in finance industry. After we fetch the data later we can analyze the meaning behind it so in the future we can take action which company we should invest to earn more money for example. To simplify the study case I’m using jupyter notebook so I don’t need to install & do any setup in my local environment. However, if you like to use another tool, that’s also great. First of all below are libraries we need to use:

import numpy as np #python library for scientific computing
import pandas as pd #python library for data manipulation and analysis
import matplotlib.pyplot as plt #python library for charting
from pandas_datareader import data as pdr #extract data from internet sources into pandas data frame

Next we’ll implement fix-yahoo-finance library to replace broken yahoo-finance from pandas (you can install here):

yf.pdr_override()

Let’s scrap all financial historical data from Dow Jones index(^DJI), Microsoft (MSFT), Apple (APPL) and Blackberry(BB.TO):

data = pdr.get_data_yahoo('^DJI', start='2006-01-01')
data2 = pdr.get_data_yahoo('MSFT', start='2006-01-01')
data3 = pdr.get_data_yahoo('AAPL', start='2006-01-01')
data4 = pdr.get_data_yahoo('BB.TO', start='2006-01-01')

each stock has different scale, statistically let’s normalize it to 100 then insert each stock closing price data for plotting:

ax = (data['Close'] / data['Close'].iloc[0] * 100).plot(figsize=(15, 6))
(data2['Close'] / data2['Close'].iloc[0] * 100).plot(ax=ax, figsize=(15,6))
(data3['Close'] / data3['Close'].iloc[0] * 100).plot(ax=ax, figsize=(15,6))
(data4['Close'] / data4['Close'].iloc[0] * 100).plot(ax=ax, figsize=(15,6))

last add additional information for the chart:

plt.legend(['Dow Jones', 'Microsoft', 'Apple', 'Blackberry'], loc='upper left')
plt.show()

The result will be like this when executed:

without chart it’s difficult to interpret what’s going on for Apple stocks for since more than 10 years ago for example. Now we can notice Apple’s stock price raises significantly. Then later we can study deeply based from this data for example what products those are apple introduced that impact Apple stock price and company performance. Here is full working code example:

--

--