[R-SIG-Finance] A possible bug in SMA

Worik Stanton worik.stanton at gmail.com
Tue Dec 6 23:55:38 CET 2011


 > A <- 5
 > L <- 1000
 > W.x <-xts(floor(rnorm(L) *100), as.Date(1:L))
 > S.x <- as.xts(SMA(W.x), A)
 > D.x <- tail(merge(W.x, S.x), n=(A+1))
 > D.x
             W.x   S.x
1972-09-22 -164 -35.9
1972-09-23  -21 -29.8
1972-09-24 -172 -47.7
1972-09-25   60 -40.6
1972-09-26  137 -16.2
1972-09-27   51 -27.3
 > cbind(mean(D.x[2:(A+1),"W.x"]), D.x[A+1,"S.x"])
            ..1   S.x
1972-09-27  11 -27.3


It seams obvious to me that "mean(D.x[2:(A+1),"W.x"])" should be the 
last SMA value, but it is not.

But I am often mistaken....

cheers
Worik

-- 
I am immensely proud of the young people who are driving the Occupy movement.  Outrage at the dominant paradigm is the appropriate response when one understands what has happened.
God Bless the Occupation



More information about the R-SIG-Finance mailing list