R/fct_tcycle.R

Defines functions tcycle

Documented in tcycle

#' tcycle
#'
#' @description Whether a day for US or Canadian crude is within trade cycle
#' @param x A date class object
#' @param mkt A string of "canada" or "usdomestic"
#' @return A string of "tcycle" or "post"
#' @export
#' @author Philippe Cote

tcycle <- function(x, mkt = "canada") {
  market <- flowmonth <- trade.cycle.end <- NULL
  tmp <- RTL::tradeCycle %>% dplyr::filter(market == mkt)
  tcycleEnd <- as.Date(tmp %>%
                         dplyr::filter(flowmonth == lubridate::rollback(x,roll_to_first = TRUE) + months(1)) %>%
                         dplyr::pull(trade.cycle.end))
  return(ifelse(x <= tcycleEnd, "tcycle","post"))
}
risktoollib/RTLappStrat documentation built on Sept. 11, 2022, 10:27 p.m.