#' fun_dailyDf
#'
#' @param xtsObj a xts object
#' @param dateFrom date at which period one want to get the date from. Choose beginning period if one want all
#' @param delta weight used in the exponential weighted average and volatility
#' @param annu to annualize data. From daily to year use 261 if assets and 365 for crypto (since they are traded all year round all day)
#'
#' @return Dataframe with prices, mean and standard deviation where mean and standard deviation is calculated using exponential weighted average and sum of squares
#' @export
#'
fun_dailyDf <- function(xtsObj, dateFrom, delta = 60/61, annu = 261) {
if(ncol(xtsObj) > 1) {
out <- quantmod::Cl(xtsObj)
} else {
out <- xtsObj
}
out <- out[dateFrom]
out.df <- cbind(Price = out,
mean = c(NA, ExpWeiAvgReCpp(diff(out)[-1], delta, annu)),
sd = c(NA, sqrt(ExpWeiVarCpp(diff(out)[-1], delta, annu))))
colnames(out.df) <- c("Price", "mean", "sd")
return(out.df)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.