Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataReader google finance date not working

I was just using pandas datareader to get the stock data for the past two weeks or so and it was working fine. All of a sudden since yesterday the date provided wasnt working anymore. It just gives me the past year data and I cant change the date. Used to work with the one commented out, but now its not. I even changed it to use datetime object, but still not working. Any idea? I updated pandas and pandas_datareader still no luck. Used another computer still didnt work. Did they just recently change the API?

from pandas_datareader import data
import datetime

#start = '2010-01-01'
#end = '2017-7-31'
start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2017,7, 31)
f = data.DataReader('AAPL', 'google', start, end)
print(f.head())

output:

              Open    High     Low   Close    Volume
Date                                                
2016-09-19  115.19  116.18  113.25  113.58  47023046
2016-09-20  113.05  114.12  112.51  113.57  34514269
2016-09-21  113.85  113.99  112.44  113.55  36003185
2016-09-22  114.35  114.94  114.00  114.62  31073984
2016-09-23  114.42  114.79  111.55  112.71  52481151
like image 349
user1179317 Avatar asked Dec 02 '25 07:12

user1179317


1 Answers

Google has changed the Google Finance URL to finance.google.com/finance/historical rather than www.google.com/finance/historical, which is used as the URL in the pandas_datareader.

Server returns HTTP 302 when fetching data from the old URL and redirect to the new URL. However, the parameters startdate/enddate are missing during the HTTP redirection.

The url is set in the source code: https://github.com/pydata/pandas-datareader/blob/master/pandas_datareader/google/daily.py

Maybe you can modify the URL and use your own version of pandas_datareader.

like image 197
Gary Liang Avatar answered Dec 04 '25 22:12

Gary Liang