Search code examples
pythonpandasfinanceyahoo-financepandas-datareader

Some ETF Tickers Not Working in Yahoo Finance DataReader


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']

Solution

  • 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())