#' Creates a price history rank by averaging three look-back periods.
#' Uses the \code{TTR::ROC} function for rate-of-change value.
#' Uses the discrete ROC type.
#' @param x price
#' @param n an array of three look-back periods in the same periodicity as x.
#' Default values if not provided \code{n=c(1,3,6)}.
#' @return a row rank as determined by \code{row_rank}.
#' @seealso row_rank, TTR::ROC
#' @examples
#' \dontrun{
#' library(quantmod)
#' options("getSymbols.warning4.0"=FALSE)
#' getSymbols("XLE",auto.assign=TRUE)
#' ranking <- ave_3ROC(XLE,n=c(3,6,12))
#' head(ranking)
#' }
ave_3ROC <- function(x, n = c(1, 3, 6)) {
roc1 <- TTR::ROC(x, n = n[1], type = "discrete")
roc2 <- TTR::ROC(x, n = n[2], type = "discrete")
roc3 <- TTR::ROC(x, n = n[3], type = "discrete")
ave <- (roc1 + roc2 + roc3) / 3
row_rank(ave)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.