R/backwards_ma.R

Defines functions backwards_ma

Documented in backwards_ma

#' Backwards Looking Moving Average Function
#'
#' Calculates the moving average of object x using the last n (including current) observations
#' @param x Numeric object
#' @param n Number of periods
#'
#' @examples
#' backwards_ma(x, n = 3)
#'

#' @export
backwards_ma <- function(x, n){

  x0 = x

  for(i in 1:(n-1)){x = x + shift(x0, i)}

  return(x/n)

}
joshua-ruf/fidelis documentation built on July 20, 2019, 1:56 a.m.