R/strength_ROC.R

Defines functions strength_ROC

Documented in strength_ROC

#' Creates a ranking of rate of change representing strength of asset returns.
#' Uses the \code{TTR::ROC} function for rate-of-change value.
#' Applies the \code{TTR::runSD} running standard deviations.
#' Computes strength as \code{strength <- roc / rd}.
#' Uses the discrete ROC type.
#' @param x price history as XTS, more than one column of asset prices.
#' @param roc_n ROC lookback period in same periodicity as \code{x};
#' default 3.
#' @param sd_n standard deviation moving window length;
#' default 3.
#' @return a row rank as determined by \code{row_rank}
#' @seealso row_rank, TTR::ROC, TTR::runSD
#' @examples
#' \dontrun{
#' library(quantmod)
#' getSymbols("XLP",auto.assign=TRUE)
#' getSymbols("XLV",auto.assign=TRUE)
#' ranking <- strength_ROC(cbind(Cl(XLP),Cl(XLV)),6,3)
#' tail(ranking)
#' }
strength_ROC <- function(x, roc_n = 3, sd_n = 3){
  roc <- TTR::ROC(x, n = roc_n, type = "discrete")
  sd <- apply(x, 2, TTR::runSD, n = sd_n)
  strength <- roc / sd
  row_rank(strength)
}
greatgray/scorecard documentation built on May 17, 2019, 8:34 a.m.