Something like:

cor(tail(merge(ret.SPY, lag(ret.MDY)), 10))

would work. 

Merge your series into a single object, take the last ten obs (tail(x, 10)) and get the correlation matrix thereof.

MW

On Oct 29, 2013, at 7:49, "Martin Bauer" <Bauermartin@gmx.at> wrote:

> hi,
>  
> How can I calculate the correlation on a subset of ie 10d Correl 
>  
> library(quantmod)
> indexes<-c("SPY","MDY")
> sym=getSymbols(indexes,from="2012-01-01",to=Sys.Date())
> ret.SPY=ROC(SPY[,6],type="discrete",n=1)
> ret.MDY=ROC(MDY[,6],type="discrete",n=1)
> now the part which is missing
> something like this 
> Pseudo Code
> Correlation(ret.SPY,lag(ret.MDY,1),10)
>  
> thanks for sharing your knowledge
>  
>  
> _______________________________________________
> R-SIG-Finance@r-project.org mailing list
> 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]]

