The Yahoo Finance S&P500 data (^GSPC) reaches back to 1950, why can I only download data from 1970 onwards?

3k views Asked by At
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
2

There are 2 answers

0
Chenyang Shi On

You may try package yfinance.

sp500 = yf.Ticker('^GSPC')

sp500.history(period = 'max')
0
Nasz On

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