[R-SIG-Finance] exponential moving avg appears to use future data

Josh Ulrich josh.m.ulrich at gmail.com
Sun Jan 20 16:19:08 CET 2008


On Jan 19, 2008 9:18 AM, BBands <bbands at gmail.com> wrote:
> On Jan 18, 2008 10:09 AM, John Putz <johnputz3655 at yahoo.com> wrote:
> > Hello,
> >
> > As usual, I'm not sure if this is the correct list to ask this, but it appears that the exponential moving average functions (emaTA and EWMA) use future information to calculate the moving average for periods prior to the kick-in of the weightings.  E.g. at one point it sets:
> >
> > ylam[1] = mean(y[1:startup])
> >
> > which, i am not quite able to trace through the rest of the function calls, but seems to be having the effect of starting the moving average calculation based on the average of future prices.  Am I correct in this?  If so, is there a reason why this might work that way?
>
> What you are seeing in a method of finding a seed value for the ema.
> There are many methods, each with its own pros and cons. In any case,
> you need to respect an run-in period after which the seeding method is
> largely moot.
>
> The article here is not a bad intro:
> http://en.wikipedia.org/wiki/Weighted_moving_average#Exponential_moving_average
>
>     jab
> --
> John Bollinger, CFA, CMT
> www.BollingerBands.com
>
> If you advance far enough, you arrive at the beginning.
>

I second John's response.  The EMA function in package TTR uses a
seeding value of
ema[n] <- mean(x[1:n])
and then begins using the exponential smoothing.  You can then compare
the results of emaTA with EMA and see that the results converge after
the run-in period.

TTR contains another 30+ TA functions, many of which are chartable via
the quantmod package.  It is being updated with new functions and
Fortran implementations of existing functions.  TTR's development
source code is here:
https://r-forge.r-project.org/projects/ttr/

HTH,
Josh

PS Sorry if this is my second reply.  I replied on Friday, but it
didn't seem to make it to the list.
--
http://quantemplation.blogspot.com



More information about the R-SIG-Finance mailing list