Weighted Moving Average in R

This web presents a way to do weigthed moving average, extremely fast using Reduce:

http://quanttrader.info/public/FasterRCode.pdf

The code is:

lambda <­ 0.95

f <­ function(prv,nxt) {lambda*prv + (1­lambda)*nxt }

ewma <­ Reduce(f,prices,accumulate=T)

Anuncios