0

I'm gathering data from a bunch of ETFs through Yahoo Finance using Pandas-Datareader and I'm getting odd errors with a handful of the tickers even though the data seems available. The code is very simple:

start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2017,1,1)

for ticker in TICKERS:
     f = dr.DataReader(ticker, 'yahoo', start, end)

and works for most of my tickers but not all:

EMLP GDVD (Failed to get data for GDVD) AMZA RFDI ARKK ARKW SECT (Failed to get data for SECT)

EMLP works fine. Datareader produces urls like this url for GDVD even though the historical data for GDVD is available on the website. I see the following error in Chrome using the GDVD url:

{"finance": {"error": {"code": "Unauthorized","description": "Invalid cookie"}}}

Is there a way to get historical prices for these tickers? The full list of failed tickers in case anyone can see a pattern:

 ['GDVD', 'SECT', 'DWLD', 'CCOR', 'DFNL', 'DUSA', 'AIEQ', 'CACG', 'QSY', 'ACT', 'TAXR', 'TTAI', 'FLIO', 'FMDG', 'VGFO', 'FFSG', 'LRGE', 'YLDE', 'VESH', 'DEMS', 'SQZZ']
rhaskett
  • 1,864
  • 3
  • 29
  • 48
  • [Possibly related](https://stackoverflow.com/questions/44057580/yahoo-finance-api-changes-2017). – tadman Jan 11 '18 at 21:05
  • Yeah. I'm Yahoo's lack of support is not the issue, but it maybe. I'm getting a little desperate as Google's API is also no longer supported and I'm running out of APIs that work with datareader. – rhaskett Jan 11 '18 at 21:19
  • Historical prices relative to when? – Jim G. Jan 21 '18 at 12:03
  • I'm looking for about 5-7 years of weekly or monthly prices for those tickers with that much history available. – rhaskett Jan 21 '18 at 21:58

1 Answers1

0

Using the yahoo_fin package, I was able to get the data for the tickers you listed. Check out this link: http://theautomatic.net/yahoo_fin-documentation/.

My code looks like this:

from yahoo_fin.stock_info import get_data

tickers =  ['GDVD', 'SECT', 'DWLD', 'CCOR', 'DFNL', 'DUSA', 'AIEQ', 'CACG',
            'QSY', 'ACT', 'TAXR', 'TTAI', 'FLIO', 'FMDG', 'VGFO', 'FFSG', 
            'LRGE', 'YLDE', 'VESH', 'DEMS', 'SQZZ']

stocks = {}

for ticker in tickers:

    stocks[ticker] = get_data(ticker)

So the data gets stored into a dictionary, where the keys are the tickers, and the values are the data frames containing each stock's data.

Alternatively, you could use a dictionary comprehension, like this:

stocks = {ticker : get_data(ticker) for ticker in tickers}

If you want to collapse all of the data sets into a single data frame, you could use the functools package like this:

from functools import reduce

combined = reduce(lambda x,y: x.append(y), stocks.values())
atreadw
  • 289
  • 2
  • 6