Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

johnnymo87
Copy link

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.

As reported in issue ranaroussi#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.

```py
>>> 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 johnnymo87 marked this pull request as ready for review February 5, 2021 14:41
Base automatically changed from master to main March 24, 2021 11:20
@ranaroussi ranaroussi closed this Mar 24, 2021
@carlos-ventura
Copy link

carlos-ventura commented Apr 16, 2022

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

@ValueRaider
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants