R/ave_3ROC.R

Defines functions ave_3ROC

Documented in ave_3ROC

#' 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)
}
greatgray/scorecard documentation built on May 17, 2019, 8:34 a.m.