vicky113
vicky113

Reputation: 351

Python - Pulling Indices data from Google Finance

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

Upvotes: 1

Views: 812

Answers (1)

Gabriel Hudak
Gabriel Hudak

Reputation: 71

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.

Upvotes: 2

Related Questions