R/revenue_estimate.R

Defines functions revenue_estimate

Documented in revenue_estimate

#' @title Revenue Estimates
#' @description Get forecast and history of revenue estimates - quarterly or annual
#'  
#' @param symbol Stock ticker
#' @param freq Frequency - quarterly or annual
#' 
#' @importFrom tibble as_tibble
#' @importFrom purrr set_names
#' @importFrom dplyr mutate select everything
#' @importFrom lubridate ymd
#' 
#' @return
#' @export
#' 
#' @examples
#' revenue_estimates('NVDA', freq = 'quarterly')
#' revenue_estimates('NVDA', freq = 'annual')
revenue_estimate <- function(symbol, freq = 'quarterly', ...){
  
  url <- finnhub_endpoint('revenue_est')
  
  df <- retry_get(url,
                  query = list(token = finnhub_key(),
                               symbol = symbol,
                               freq = freq)) 
  df %>% 
    .[['data']] %>% 
    tibble::as_tibble() %>% 
    dplyr::mutate(symbol = symbol,
                  date = lubridate::ymd(period, tz = finnhub_timezone)) %>% 
    dplyr::select(symbol, date, dplyr::everything()) %>% 
    purrr::set_names(c('symbol', 'date', 'num_of_analysts', 'period', 'revenue_avg',
                       'revenue_high', 'revenue_low'))
}
threadingdata/finnhubr documentation built on Aug. 10, 2020, 12:48 a.m.