yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

(#244) Fix .info['annualReportExpenseRatio'] for ETFs

Open johnnymo87 opened this issue 4 years ago • 2 comments

As reported in issue #244, there is a bug with querying for an ETF's expense ratio. For mutual funds, this value is found in .info['annualReportExpenseRatio'], but for ETFs it is not.

>>> import yfinance as yf
>>> print(yf.Ticker('VTSAX').info['annualReportExpenseRatio'])
0.0004
>>> print(yf.Ticker('VTI').info['annualReportExpenseRatio'])
None

The github user @ycc1107 commented on the issue, identifying the root cause, which is that for some reason this value is only available inside the 'fundProfile' key of the data dictionary, a key that is only present when querying mutual funds and ETFs. The 'fundProfile' key leads to a dictionary with a 'feesExpensesInvestment' key, which leads to a dictionary with an 'annualReportExpenseRatio' key, which has the value we need.

The github user @ycc1107 opened a PR to fix this issue, but I'm concerned that it changes too much, as it recursively merges the entirety of the 'fundProfile' dictionary into the .info dictionary. So I'm proposing an alternative fix here that attempts to write only .info['annualReportExpenseRatio'] and nothing else.

johnnymo87 avatar Jan 17 '21 21:01 johnnymo87

MR closed without any changes. Dont think it is to hard to update it as it only requires 4/5 added lines of code and constitues important info for ETFs

carlos-ventura avatar Apr 16 '22 00:04 carlos-ventura

I'm going through old issues/PRs, and see this was closed when looks to me like should have been merged. But codebase has changed a lot since - can someone create a fresh new PR?

ValueRaider avatar Jan 05 '23 21:01 ValueRaider