R/eps_estimate.R

Defines functions eps_estimate

Documented in eps_estimate

#' @title Earnings per Share Estimates
#' @description Get EPS estimates - quarterly or annual
#'  
#' @param symbol Stock ticker
#' @param freq Frequency - quarterly or annual
#' 
#' @importFrom purrr set_names
#' @importFrom dplyr mutate select everything
#' @importFrom lubridate ymd
#' 
#' @return
#' @export
#' 
#' @examples
#' eps_estimates('NVDA', freq = 'quarterly')
#' eps_estimates('NVDA', freq = 'annual')
eps_estimate <- function(symbol, freq = 'quarterly', ...){
  
  url <- finnhub_endpoint('eps_estimate')
  
  df <- retry_get(url,
                  query = list(token = finnhub_key(),
                               symbol = symbol,
                               freq = freq)) 
  df %>% 
    .[['data']] %>% 
    dplyr::mutate(symbol = symbol,
                  date = lubridate::ymd(period, tz = finnhub_timezone)) %>%
    dplyr::select(symbol, date, dplyr::everything()) %>% 
    purrr::set_names(c('symbol', 'date', 'eps_avg', 'eps_high', 'eps_low', 
                       'num_analysts', 'period'))
}
threadingdata/finnhubr documentation built on Aug. 10, 2020, 12:48 a.m.