getQuote "what" possible fields in Quantmod (R)

Solution 1:

You can check the fields available in yahooQF by just calling the function:

yahooQF()

This will return 61 fields.

You can also check the yahoo query that getQuote uses via:

https://query1.finance.yahoo.com/v7/finance/quote?symbols=AAPL

This will return all the fields that are available via the api call. As you can see when you check both of these options, "1y target Est" is not available. Which means you will need to scrape this info. This is not too difficult and I hacked some code to do this. You will get the complete summary table, you just need to select the row you need. Note that all values are character values.

library(rvest)
library(purrr)
library(dplyr)

symbol = "AAPL" 

get_summary_table <- function(symbol){

  url <- paste0("https://finance.yahoo.com/quote/",symbol)
  df <- url %>%
    read_html() %>%
    html_table(header = FALSE) %>%
    map_df(bind_cols) %>%
    as_tibble()
  
  names(df) <- c("name", "value")
  df["stock"] <- symbol
  
  df
}

get_summary_table("AAPL")

# A tibble: 16 x 3
   name                     value           stock
   <chr>                    <chr>           <chr>
 1 Previous Close           166.23          AAPL 
 2 Open                     166.98          AAPL 
 3 Bid                      0.00 x 900      AAPL 
 4 Ask                      0.00 x 800      AAPL 
 5 Day's Range              164.23 - 169.64 AAPL 
 6 52 Week Range            116.21 - 182.94 AAPL 
 7 Volume                   91,420,515      AAPL 
 8 Avg. Volume              93,065,537      AAPL 
 9 Market Cap               2.687T          AAPL 
10 Beta (5Y Monthly)        1.20            AAPL 
11 PE Ratio (TTM)           29.32           AAPL 
12 EPS (TTM)                5.61            AAPL 
13 Earnings Date            Jan 27, 2022    AAPL 
14 Forward Dividend & Yield 0.88 (0.53%)    AAPL 
15 Ex-Dividend Date         Nov 05, 2021    AAPL 
16 1y Target Est            179.87          AAPL