R/next_trading_day.R

Defines functions next_trading_day is_trading_day

Documented in next_trading_day

#' Next trading day 
#'
#' This function gets the next trading day as defined by is.trading.day()
#'
#' @param d Date relative to which to get the next trading day. 
#' 
#' @return Date The next trading day of date d.

next_trading_day <- function(d) {
  stopifnot(inherits(d, "Date"))
  week <- seq(d + 1, d + 7, by = 1)
  as.Date(week[is_trading_day(week)][1])
}

## Check if the date d is a trading day 

is_trading_day <- function(d) {
  stopifnot(inherits(d, "Date"))
  
  ! weekdays(d) %in% c("Saturday", "Sunday")
  
}

Try the backtestGraphics package in your browser

Any scripts or data that you put into this service are public.

backtestGraphics documentation built on May 29, 2017, 3:11 p.m.