ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
13k stars 2.3k forks source link

annualReportExpenseRatio missing #2040

Open yunhongz opened 2 weeks ago

yunhongz commented 2 weeks ago

Describe bug

With over 1100 ETFs traded in NYSE/Nasdaq, I couldn't find the 'annualReportExpenseRatio' value frrom their info records. Is this field no longer available?

import yfinace as yf

ticker='SPYI'

yf_ticker = yf.Ticker(ticker)

info = yf_ticker.get_info()

info.get('annualReportExpenseRatio')

Simple code that reproduces your problem

import yfinace as yf

ticker='SPYI'; yf_ticker = yf.Ticker(ticker); info = yf_ticker.get_info(); info.get('annualReportExpenseRatio')

ticker='QQQ'; yf_ticker = yf.Ticker(ticker); info = yf_ticker.get_info(); info.get('annualReportExpenseRatio')

ticker='SPY'; yf_ticker = yf.Ticker(ticker); info = yf_ticker.get_info(); info.get('annualReportExpenseRatio')

ticker='SPY'; yf_ticker = yf.Ticker(ticker); info = yf_ticker.get_info(); info.get('annualReportExpenseRatio')

Debug log

yf.enable_debug_mode() ticker='SPY'; yf_ticker = yf.Ticker(ticker); info = yf_ticker.get_info(); info.get('annualReportExpenseRatio') DEBUG get_raw_json(): https://query2.finance.yahoo.com/v10/finance/quoteSummary/SPY DEBUG Entering get() DEBUG url=https://query2.finance.yahoo.com/v10/finance/quoteSummary/SPY DEBUG params={'modules': 'financialData,quoteType,defaultKeyStatistics,assetProfile,summaryDetail', 'corsDomain': 'finance.yahoo.com', 'formatted': 'false', 'symbol': 'SPY'} DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = 'basic' DEBUG Entering _get_cookie_and_crumb_basic() DEBUG reusing cookie DEBUG reusing crumb DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=200 DEBUG Exiting get()

Bad data proof

No response

yfinance version

yfinance 0.2.38

Python version

python3.10

Operating system

No response

ericpien commented 2 weeks ago

There were multiple efforts to support ETF and Mutual Funds Data. Some efforts were specific to expense ratios (https://github.com/ranaroussi/yfinance/pull/557), or holdings (https://github.com/ranaroussi/yfinance/pull/1872). These efforts also attempted to solve the issues in different methods (i.e. scraping html or using api).

Rather than implementing piece-wise, I think fund level data should be supported holistically as started by https://github.com/ranaroussi/yfinance/pull/1784 using the api method.

I will take this issue and also attempt to resolve the following issues/discussions in one go:

ericpien commented 4 days ago

hi @yunhongz, following https://github.com/ranaroussi/yfinance/pull/2041, you are now able to query annualReportExpenseRatio via:

spy = yf.Ticker('SPY')
data = spy.funds_data
data.fund_operations
Attributes SPY Category Average
Annual Report Expense Ratio 0.000945 0.007769
Annual Holdings Turnover 0.020000 0.490600
Total Net Assets 308649.800000 308649.800000