'Python Finance: get_data_yahoo Not Retrieving Data

I ran this code about a year ago and it was working fine. Now it has stopped working, and I think it has to do with the get_data_yahoo function. Here is part of the code I am trying to run:

pd.options.display.width = 0

stocklist = si.tickers_sp500()
index_name = '^GSPC'  # S&P 500: ^GSPC  Dow Jones: ^DJI   Nasdaq: ^IXIC

# Initiate stock index
n = -1

for stock in stocklist:
    n += 1

    # Set a time delay between each stock
    time.sleep(0.25)

    # Inform user which stock is being evaluated
    print("\nPulling {} with Index {}".format(stock, n))

    # Set 1-year time duration starting from 365 days ago today
    start_date = datetime.datetime.now() - datetime.timedelta(days=365)
    end_date = datetime.date.today()

    # Download stock data for set time duration
    # (Optional??) stock = [stock + '.AX' for stock in stocklist]
    df = pdr.get_data_yahoo(stock, start=start_date, end=end_date)

Now this is returning no data. What am I missing?



Solution 1:[1]

Probably the syntax of the library has changed. I changed your code and tried to request a few 10 shares. After 40, I stopped it myself. It seems to me that there is no need to abuse and request data often and not so much. And also reduced the depth of the request by four days. It is quite possible, if you request deep data, that you will come across a stock that is not traded and the script will shut down (I have seen questions like this).

import pandas_datareader.data as web
import yahoo_fin.stock_info as si
import pandas as pd
import datetime
import time

pd.options.display.width = 0

stocklist = si.tickers_sp500()
index_name = '^GSPC'  # S&P 500: ^GSPC  Dow Jones: ^DJI   Nasdaq: ^IXIC
n = -1

for stock in stocklist:
    n += 1

    # Set a time delay between each stock
    time.sleep(0.25)

    # Inform user which stock is being evaluated
    print("\nPulling {} with Index {}".format(stock, n))

    # Set 1-year time duration starting from 365 days ago today
    start_date = datetime.datetime.now() - datetime.timedelta(days=4)
    end_date = datetime.date.today()

    df = web.DataReader(stock, 'yahoo', start=start_date, end=end_date)
    print(df)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 E_net4 - Krabbe mit Hüten