1

I am trying to pull Historical data of Indices from Google Finance, but it's not working. While I am able to pull historical data of an individual stock easily. Am I doing something wrong with Indices?

My code for Stock

from pandas_datareader import data
from dateutil.relativedelta import relativedelta
import datetime as dt

enddate = dt.datetime.today()
begdate = enddate + relativedelta(years=-1)


x= data.get_data_google("GOOGL",begdate,enddate)
print(x.head())

Output

              Open    High     Low   Close   Volume
Date                                               
2016-05-24  719.85  734.20  719.64  733.03  1890195
2016-05-25  735.00  739.89  732.60  738.10  1610773
2016-05-26  736.00  741.10  733.00  736.93  1298295
2016-05-27  737.51  747.91  737.01  747.60  1738913
2016-05-31  748.76  753.48  745.57  748.85  2124248

My code for Index

x= data.get_data_google(".DJI",begdate,enddate)

Error

RemoteDataError: Unable to read URL: http://www.google.com/finance/historical
vicky113
  • 351
  • 1
  • 6
  • 19

1 Answers1

2

I am not sure where the issue is, however there is a difference on GOOGLE Finance website.

When you try to see historical data for GOOGL:
https://finance.google.com/finance/historical?q=NASDAQ:GOOGL

On right hand side of the website (under chart) you will see Export section with link to CSV.

However for DJI:
https://finance.google.com/finance/historical?q=INDEXDJX:.DJI

There is no such link.

It could be that implementation of pandas_datareader uses that link to get the data. I changed the csv download link for the INDEXDJX:.DJI and it returned an error.

Update:
I see that the function is trying to reach
http://www.google.com/finance/historical?q=INDEXDJX%3A.DJI&startdate=Oct+20%2C+2016&enddate=Oct+20%2C+2017&output=csv

This does not exist. When I replace above for google ticker it downloads the file.

In the meantime I found this comment that seems to confirm the above i.e. export to csv is not supported for all exchanges see google doc for more info.

  • 2
    This may be related, but probably isn't the problem itself. Check to see what endpoint the "export csv" link actually points to (e.g. using firebug), search through the pandas code to make sure it's trying to visit that same link, then try to visit a comparable link for DJI. This would show that the thing pandas is trying to retrieve is not available from google. – Him Oct 20 '17 at 14:52
  • 1
    Seems like the link it tries to hit is: http://www.google.com/finance/historical?q=INDEXDJX%3A.DJI&startdate=Oct+20%2C+2016&enddate=Oct+20%2C+2017&output=csv and this does not exists on google finance. – Gabriel Hudak Oct 20 '17 at 17:14