我正在尝试获取 S&P500 中所有股票的当前价格和市值,而我目前的做法非常慢,所以我想知道是否有什么可以改进它的方法,或者任何其他方法。这是我当前的方法,只是打印名称、市值和当前价格:
import yfinance as yf
#I am using a csv file with a list of all the tickers which I use to create a pandas dataframe and form a space seperated string of all of the tickers called all_symbols
#I have simplified the pandas dataframe to a list for the purpose of this question
ticker_list = ["A", "AL", "AAP", "AAPL", ... "ZBRA", "ZION", "ZTS"]
all_symbols = " ".join(ticker_list)
tickers = yf.Tickers(all_symbols)
for ticker in ticker_list:
price = tickers.tickers[ticker].info["currentPrice"] …
Run Code Online (Sandbox Code Playgroud)