Hi Worik,

I think you meant to use "A" as an argument to SMA, not to as.xts.

If you replace
S.x <- as.xts(SMA(W.x), A)
with
S.x <- SMA(W.x, A)

Then your cbind will give 2 identical values
> cbind(mean(D.x[2:(A+1),"W.x"]), D.x[A+1,"S.x"])
             ..1   S.x
1972-09-27 112.6 112.6

Garrett

On Tue, Dec 6, 2011 at 4:55 PM, Worik Stanton <worik.stanton@gmail.com>wrote:

> > 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
>
> ______________________________**_________________
> R-SIG-Finance@r-project.org mailing list
> https://stat.ethz.ch/mailman/**listinfo/r-sig-finance<https://stat.ethz.ch/mailman/listinfo/r-sig-finance>
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

	[[alternative HTML version deleted]]

