#' @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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.