R/price_target.R

Defines functions price_target

Documented in price_target

#' @title Stock price target
#' @description Get price target for a company
#'  
#' @param symbol Stock ticker
#' 
#' @importFrom purrr set_names
#' @importFrom dplyr bind_rows mutate select
#' @importFrom lubridate ymd_hms
#' 
#' @return
#' @export
#' 
#' @examples
#' price_target('NVDA')
price_target <- function(symbol, ...){
  
  url <- finnhub_endpoint('price_target')
  
  df <- retry_get(url,
                  query = list(token = finnhub_key(),
                               symbol = symbol)) 
  df %>% 
    dplyr::bind_rows() %>% 
    dplyr::mutate(last_updated = lubridate::ymd_hms(lastUpdated, 
                                                    tz = finnhub_timezone)) %>% 
    dplyr::select(symbol, last_updated, targetHigh:targetMedian) %>% 
    purrr::set_names(c('symbol', 'last_updated', 'target_high', 'target_low', 
    'target_mean', 'target_median'))
}
threadingdata/finnhubr documentation built on Aug. 10, 2020, 12:48 a.m.