I've tried to download financial data from Yahoo Finance using yahoo_fin package. I would like to ask is it possible to download historical data of Return on Assets, Market Capitalization and Total Assets from multiple stocks in a ticker list or csv file? I used the code below:
import yahoo_fin.stock_info as si
import pandas as pd
import tqdm
ticker_list = ["amzn", "aapl", "ba"]
historical_datas = {}
for ticker in ticker_list:
historical_datas[ticker] = get_data(ticker)
quote_table = si.get_quote_table("aapl", dict_result=False)
quote_table
#Data from DOW list
dow_stats = {}
for ticker in dow_list:
temp = si.get_stats_valuation(ticker)
temp = temp.iloc[:,:2]
temp.columns = ["Attribute", "Recent"]
dow_stats[ticker] = temp
dow_stats
combined_stats = pd.concat(historical_datas)
combined_stats = combined_stats.reset_index()
combined_stats
del combined_stats["level_1"]
# update column names
combined_stats.columns = ["Ticker", "Attribute", "Recent"]
#Example: P/E ratio
pe_ratios = combined_stats[combined_stats["Attribute"]=="Trailing P/E"].reset_index()
#I found an example how to download Return on Assets
dow_extra_stats = {}
for ticker in tqdm(dow_list):
dow_extra_stats[ticker] = si.get_stats(ticker)
combined_extra_stats = pd.concat(dow_extra_stats)
combined_extra_stats = combined_extra_stats.reset_index()
del combined_extra_stats["level_1"]
combined_extra_stats.columns = ["ticker", "Attribute", "Value"]
#Return on Assets
combined_extra_stats[combined_extra_stats.Attribute.str.contains("Return on Assets")]
I've tried to download data using the code from the post Yahoo Finance to download fundamental data but here I can download data for a single stock.