1
import pandas_datareader.data as web

df = web.DataReader('^GSPC', 'yahoo', start='1950-01-03', end='2017-09-14')

If I go on the Yahoo Finance website I can manually download data from 1950, so why can't I do that using pandas datareader? I mean I got the data already, just curious about why it didn't work.

Edit: I get this error:

Traceback (most recent call last):
  File "C:/Users/x/PycharmProjects/Programming for Finance/getsp.py", line 7, in <module>
    df = web.DataReader('^GSPC', 'yahoo', start='1950-01-03', end='2017-09-14')
  File "C:\Users\x\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas_datareader\data.py", line 121, in DataReader
    session=session).read()
  File "C:\Users\x\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas_datareader\yahoo\daily.py", line 115, in read
    df = super(YahooDailyReader, self).read()
  File "C:\Users\x\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas_datareader\base.py", line 181, in read
    params=self._get_params(self.symbols))
  File "C:\Users\x\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas_datareader\yahoo\daily.py", line 99, in _get_params
    unix_start = int(time.mktime(self.start.timetuple()))
OverflowError: mktime argument out of range
Chisq
  • 117
  • 1
  • 9
  • I am able to see entries from 1950 when I run your code snippet. Can you paste the output of df.head()? – ShreyasG Sep 15 '17 at 06:37
  • I actually get an error, sorry forgot to mention that. I edited the question with the error. – Chisq Sep 15 '17 at 06:50
  • This appears to be a Windows issue with how it reads time. Check [this](https://stackoverflow.com/questions/2518706/python-mktime-overflow-error). You can try creating a separate python datetime object and use that for the start datetime. – ShreyasG Sep 15 '17 at 06:56
  • Ah, I see. Using datetime I still get the same error though. – Chisq Sep 15 '17 at 07:03
  • Yes, so this is a platform issue. You can either submit an issue on the pandas_datareader git or go and fix the line in the package yourself. Look for the time.mktime line and replace it with datetime.datetime. – ShreyasG Sep 15 '17 at 07:15
  • 1
    Thanks a lot! Very helpful. – Chisq Sep 15 '17 at 07:16

2 Answers2

0

You may try package yfinance.

sp500 = yf.Ticker('^GSPC')

sp500.history(period = 'max')
RiveN
  • 2,595
  • 11
  • 13
  • 26
0

It is because 1970,1,1 is the beginning of time as far as datetime is concerned.

Refer to: https://kb.narrative.io/what-is-unix-time

Nasz
  • 1