Skip to content
Prev 10421 / 398513 Next

R-help Digest V2 #377

A simple exponential weighted moving average procedure would be

ewma <- function (x, lambda = 1, init = 0)
{
  y <- filter(lambda*x, filter=1-lambda, method="recursive", init=init)
  return (y)
}

Using ewma as a forecast function is known as exponential smoothing.
Try, e.g.:

x <- ts(diffinv(rnorm(100)))
y <- ewma(x,lambda=0.2,init=x[1])
plot(x)
lines(y,col="red")

best
Adrian

--
Dr.  Adrian Trapletti,  Olsen  &  Associates Ltd.
Seefeldstrasse 233, CH-8008  Z?rich,  Switzerland
Phone: +41 (1) 386 48 47   Fax: +41 (1) 422 22 82
E-mail: adrian at olsen.ch  WWW: http://www.olsen.ch




-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._