R/calculate_returns.R

Defines functions calculate_returns

Documented in calculate_returns

#' @title calculate_returns
#' @description Wrapper for TTR:ROC() but with easy periodicity changing.
#' @param closes_xts xts, an xts of closing prices
#' @return An xts of asset returns.
#' @examples 
#' \dontrun{
#' if(interactive()){
#'  quantmod::getSymbols('SPY')
#'  clhelpers::calculate_returns(SPY[,4])
#'  }
#' }
#' @export 
#' @importFrom TTR ROC
calculate_returns <- function(closes_xts)
{
  TTR::ROC(closes_xts, type = 'discrete', na.pad = FALSE)
}
causality-loop/clhelpers documentation built on Aug. 31, 2022, 3:39 a.m.