Unable to download data for multiple tickers from Yahoo Finance

I haven't been able to download the price data for multiple tickers from Yahoo off late. Is anyone else experiencing the same issue and if there is a solution. I try to loop through my tickers (a list of about 2000 stocks) and was working fine until end of March. But now I am not able to go through even 10-15 tickers at one time. 



My code is as below:



import yfinance as yf



for ticker_name in ticker_list: #looping through my list of tickers

    df = yf.Ticker(ticker_name)

    # get daily historical market data from Yahoo

    hist = df.history(period="1mo",interval="1d") # pulling data for last 1 month



 

Hi Gaurav,



I am not able to replicate this issue, but can I suggest another way to retrieve the data? Can you try downloading the data using "yf.download" function. I have attached a sample code that downloads price data of the stocks listed in S&P500. I think you can modify it to include the list which you have created. Please find the code below.


Import packages


import yfinance as yf

import pandas as pd


# Read and print the stock tickers that make up S&P500

tickers = pd.read_html(

'https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')[0]

print(tickers.head())

# Get the data for this tickers from yahoo finance

data = yf.download(tickers.Symbol.to_list(),'2021-1-1','2021-7-12', auto_adjust=True)['Close']

print(data.head())


Hope this helps.

Thanks for your interest Rekhit. 



I have a few requirements I am trying to fulfill in my data download. I am looking to download OHLC + Volume data for about 2000 stocks. So I assume I will have to run the script above 5 times for each data point individually, which is fine as time taken is not a big concern for me as long as data can be downloaded. 



I tried your code as well, it seems Yahoo stops the code after 400ish tickers. Not sure how to get around this…



I am not able to attach the picture here but this is what I see in results section in my Jupyter notebook:



Code: 



data = yf.download(tickers,'2022-3-25','2022-04-06', auto_adjust=True)['Close']




here tickers is a list of 1970 tickers



RESULT:

[**********            21%                       ]  409 of 1970 completed

this is where my notebook is now frozen

 

Hi Gaurav,



There can be a few reasons why Yahoo is stopping the code. One could be because one of the stock might have been delisted or Yahoo does not have the financial data for the stock. 

If you can, you could try splitting your list of tickers and check if the issue is still persisting. It can be a matter of trial and error. Or if you are comfortable, you can send your list of tickers to "quantra@quantinsti.com" so that a solution can be found. You can also send a screenshot of the error if possible.



Hope this helps.