R/income_statement.R

Defines functions income_statement

Documented in income_statement

#' @title Income Statement
#' @description Income statments for a company - annual, quarterly, ttm
#'  
#' @param symbol Ticker symbol
#' @param freq Frequency - annual, quarterly or ttm
#' 
#' @importFrom purrr set_names
#' @importFrom dplyr mutate select everything
#' @importFrom lubridate ymd now
#' 
#' @return
#' @export
#' 
#' @examples
#' income_statement('BAC', freq = 'annual')
#' income_statement('BAC', freq = 'quarterly')
#' income_statement('BAC', freq = 'ttm')
income_statement <- function(symbol, freq = 'annual', ...){
  
  url <- finnhub_endpoint('income_statement')
  
  df <- retry_get(url,
                  query = list(token = finnhub_key(),
                               symbol = symbol,
                               statement = 'ic',
                               freq = freq)) 
  df  %>% 
    .[['financials']] %>%
    dplyr::mutate(symbol = symbol,
                  period = lubridate::ymd(period, tz = finnhub_timezone),
                  frequency = freq,
                  statement = 'income_statement',
                  query_date = lubridate::now(tz = finnhub_timezone)) %>%
    dplyr::select(symbol, frequency, statement, period, dplyr::everything())
}
threadingdata/finnhubr documentation built on Aug. 10, 2020, 12:48 a.m.