From 0d7e9e593615704ab6265941e8c61bc1f8f4cdd9 Mon Sep 17 00:00:00 2001 From: "Jeffrey A. Ryan" Date: Thu, 11 Mar 2010 21:45:23 +0000 Subject: [PATCH] added check for missing n when ratio is specified to EMA. If missing, converts n to approx. "correct" value given ratio git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/ttr/pkg@98 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- R/MovingAverages.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/MovingAverages.R b/R/MovingAverages.R index 9e0c909..9e5276f 100755 --- a/R/MovingAverages.R +++ b/R/MovingAverages.R @@ -51,6 +51,11 @@ function (x, n=10, wilder=FALSE, ratio=NULL) { # Check for non-leading NAs # Leading NAs are handled in the C code x.na <- xts:::naCheck(x, n) + + # If ratio is specified, and n is not, set n to approx 'correct' + # value backed out from ratio + if(missing(n) && !missing(ratio)) + n <- trunc(2/ratio - 1) # Determine decay ratio if(is.null(ratio)) {