R/clean_endpoints.R

Defines functions clean_endpoints

Documented in clean_endpoints

#' @title clean_endpoints
#' @description Trims the series of endpoints so that it can be used with various models.
#' @param rets_xts an xts of asset returns
#' @param offset numeric, the number of periods to lag/lead the endpoints
#' @return A numeric of endpoint values.
#' @export 
#' @importFrom xts endpoints last
clean_endpoints <- function(rets_xts, offset = 0) 
{
  ep <- xts::endpoints(rets_xts) + offset
  ep[ep < 1] <- 1
  ep[ep > nrow(rets_xts)] <- nrow(rets_xts)
  ep <- unique(ep)
  epDiff <- diff(ep)
  if(xts::last(epDiff)==1) ep <- ep[-length(ep)]
  ep
}
causality-loop/clhelpers documentation built on Aug. 31, 2022, 3:39 a.m.