Downloading multiple stocks at once from Yahoo Finance

Updated as of 2021-01-19

tickers = ['msft', 'aapl', 'intc', 'tsm', 'goog', 'amzn', 'fb', 'nvda']
df = pdr.DataReader(tickers, data_source="yahoo", start="2017-01-01", end='2020-09-28')

Original Answer

If you read through Pandas DataReader’s documentation, they issued an immediate depreciation on multiple data source API’s, one of which is Yahoo! Finance.

v0.6.0 (January 24, 2018)

Immediate deprecation of Yahoo!, Google Options and Quotes and EDGAR.
The end points behind these APIs have radically changed and the
existing readers require complete rewrites. In the case of most Yahoo!
data the endpoints have been removed. PDR would like to restore these
features, and pull requests are welcome.

This could be the culprit to why you been getting IndexError‘s (or any other normally none-existant errors).


However, there is another Python package whose goal is to fix the support for Yahoo! Finance for Pandas DataReader, you can find that package here:

https://pypi.python.org/pypi/fix-yahoo-finance

According to their documentation:

Yahoo! finance has decommissioned their historical data API, causing many programs that relied on it to stop working.

fix-yahoo-finance offers a temporary fix to the problem by scraping the data from Yahoo! finance using and return a Pandas
DataFrame/Panel in the same format as pandas_datareader’s
get_data_yahoo().

By basically “hijacking” pandas_datareader.data.get_data_yahoo()
method, fix-yahoo-finance’s implantation is easy and only requires
to import fix_yahoo_finance into your code.

All you need to add is this:

from pandas_datareader import data as pdr
import fix_yahoo_finance as yf

yf.pdr_override() 

stocks = ["stock1","stock2", ...]
start = datetime.datetime(2012,5,31)
end = datetime.datetime(2018,3,1)

f = pdr.get_data_yahoo(stocks, start=start, end=end)

Or without Pandas DataReader:

import fix_yahoo_finance as yf

stocks = ["stock1","stock2", ...]
start = datetime.datetime(2012,5,31)
end = datetime.datetime(2018,3,1)
data = yf.download(stocks, start=start, end=end)

Leave a Comment