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

How to add expense ratio to the list of fields we can source from yahoo #335

Closed
Courvoisier13 opened this issue Jun 11, 2021 · 2 comments
Closed
Assignees

Comments

@Courvoisier13
Copy link

Courvoisier13 commented Jun 11, 2021

Description

For a fund or ETF, SPY for example:
I would like to add the Expense Ratio (net) (under Summary) or Annual Report Expense Ratio (net) (under profile) to the list of fields that can be scraped. Using my best guess and looking at the html, I added

"Expense Ratio (net)", "Expense Ratio (net)", "annualReportExpenseRatio"

to the end of the variable .yahooQuoteFields in the file getQuote.R. After building the package and try it out, unfortunately I get the following error:

Error in `[.data.frame`(sq, , "regularMarketTime") : 
  undefined columns selected
Called from: `[.data.frame`(sq, , "regularMarketTime"

Is it possible to get some help on rules for .yahooQuoteFields and is it possible to add new fields to extract new info?

Expected behavior

I expect to get the expense ratio for a fund, SPY for example.

Minimal, reproducible example

syms <- "SPY"
what_metrics <- yahooQF(c("Name", "Expense Ratio (net)"))
getQuote(syms, what=what_metrics)

Session Info

R version 4.0.5 (2021-03-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] quantmod_0.4.18.1 TTR_0.24.2        xts_0.12.1        zoo_1.8-9        

loaded via a namespace (and not attached):
[1] compiler_4.0.5  tools_4.0.5     yaml_2.2.1      curl_4.3.1      grid_4.0.5      jsonlite_1.7.2  lattice_0.20-41 fortunes_1.5-4 
@joshuaulrich
Copy link
Owner

I don't know how to do this. It doesn't look like it's returned by the quote API. You can hit the API in your browser: https://query1.finance.yahoo.com/v7/finance/quote?symbols=SPY&fields=annualReportExpenseRatio

Here's the result:

{
    "quoteResponse": {
        "error": null,
        "result": [
            {
                "esgPopulated": false,
                "exchange": "PCX",
                "exchangeDataDelayedBy": 0,
                "exchangeTimezoneName": "America/New_York",
                "exchangeTimezoneShortName": "EDT",
                "firstTradeDateMilliseconds": 728317800000,
                "fullExchangeName": "NYSEArca",
                "gmtOffSetMilliseconds": -14400000,
                "language": "en-US",
                "market": "us_market",
                "marketState": "CLOSED",
                "priceHint": 2,
                "quoteSourceName": "Delayed Quote",
                "quoteType": "ETF",
                "region": "US",
                "sourceInterval": 15,
                "symbol": "SPY",
                "tradeable": false,
                "triggerable": true
            }
        ]
    }
}

@Courvoisier13
Copy link
Author

Ah I see. Where can I see the endpoints of this API? I went on Rapid API and found that it is on get-profile endpoint. But that is a different API to the one you use.

@joshuaulrich joshuaulrich self-assigned this Jul 27, 2023
@joshuaulrich joshuaulrich added this to the Release 0.4.25 milestone Jul 28, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jan 4, 2025
### Changes in 0.4.25 (2023-08-21)

1. Fix `getQuote.yahoo()` for API changes. Thanks to Ethan B. Smith for the
    report and patch! Also add error message for users in GDPR countries, since
    we cannot automatically consent to GDPR and the request fails without
    consent.
    [#392](joshuaulrich/quantmod#392)
    [#393](joshuaulrich/quantmod#393)
    [#395](joshuaulrich/quantmod#395)

1. Fix `getQuote.yahoo()` when the user only requested metrics that do not have
    have a value for 'regularMarketTime'. Set the value to NA in these cases
    so the output remains the same regardless of whether the endpoint returns
    a 'regularMarketTime' or not. Thanks to @mehdiMBH for the report!
    [#255](joshuaulrich/quantmod#255)

1. Add fields to `getQuote.yahoo()` that are returned when no fields are
    explicitly requested. Thanks to @Courvoisier13 for the report!
    [#335](joshuaulrich/quantmod#335)

1. Add intraday endpoint to `getSymbols.yahoo()`. Thanks to @kapsner for the
    report and patch! Also allow suppressing the warning if more than 7 days
    of data are requested (@eddelbuettel).
    [#351](joshuaulrich/quantmod#351)
    [#381](joshuaulrich/quantmod#381)
    [#399](joshuaulrich/quantmod#399)

1. Add warning if `getSymbols()` is called with tickers that are reserved words
    because accessing them requires back-quotes (e.g. ``NA``).
    [#401](joshuaulrich/quantmod#401)

1. Fix `allReturns()` when 'subset' is specified. Thanks to @Panagis1980 for
    the report!
    [#402](joshuaulrich/quantmod#402)

### Changes in 0.4.24 (2023-07-17)

1. Fix `getSymbols.oanda()` URL. Thanks to @macray76 for the report.
    [#387](joshuaulrich/quantmod#387)

### Changes in 0.4.23 (2023-06-14)

1. Fix `getQuote.yahoo()` error. Thanks to Ethan B. Smith for the report and
    patch!
    [#382](joshuaulrich/quantmod#382)
    [#383](joshuaulrich/quantmod#383)

1. Add `name` argument to `add_TA()`. Thanks to @SamoPP for the suggestion!
    [#377](joshuaulrich/quantmod#377)
    [#205](joshuaulrich/quantmod#205)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants