R/cashflow_statement.R

Defines functions cashflow_statement

Documented in cashflow_statement

#' @title Cashflow Statement
#' @description Cashflow statments for a company - annual, quarterly, ttm, ytd
#'  
#' @param symbol Ticker symbol
#' @param freq Frequency - annual, quarterly, ttm or ytd
#' 
#' @importFrom purrr set_names
#' @importFrom dplyr mutate select everything
#' @importFrom lubridate ymd now
#' 
#' @return
#' @export
#' 
#' @examples
#' cashflow_statement('BAC', freq = 'annual')
#' cashflow_statement('BAC', freq = 'quarterly')
#' cashflow_statement('BAC', freq = 'ttm')
#' cashflow_statement('BAC', freq = 'ytd')
cashflow_statement <- function(symbol, freq = 'annual', ...){
  
  url <- finnhub_endpoint('cashflow_statement')
  df <- retry_get(url,
                  query = list(token = finnhub_key(),
                               symbol = symbol,
                               statement = 'cf',
                               freq = freq)) 
  df  %>% 
    .$financials %>%
    mutate(symbol = symbol,
           period = lubridate::ymd(period, tz = finnhub_timezone),
           frequency = freq,
           statement = 'cashflow_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.