Re: [R] Rolling Correlations

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue, 4 Dec 2007 03:31:19 -0500

If you want to use just zoo alone then its done like this. See ?rollapply and the two zoo vignettes.

> library(zoo)
> set.seed(1)
> z <- zoo(cbind(a = rnorm(25), b = 1:25))
> rollapply(z, 5, function(x) cor(x[,1], x[,2]), by.column = FALSE)

          3 4 5 6 7 8  0.54680491 -0.13300909 0.03576759 -0.28297639 0.52062842 0.26441877

          9 10 11 12 13 14  0.24494114 0.05774863 -0.32294217 -0.68658780 -0.35636555 0.11012008

         15 16 17 18 19 20  0.43888843 0.61623274 0.10862581 0.71947286 0.60338376 -0.25653111

         21 22 23
-0.61338395 -0.79316968 -0.44360374

On Nov 30, 2007 7:38 AM, Shubha Vishwanath Karanth <shubhak_at_ambaresearch.com> wrote:
> Hi R,
>
>
>
> I want to do some rolling correlations. But before, I searched for
> "?rollingCorrelation" and tried the example in it. But I was not
> successful. What could be the problem? Here is the code I tried:
>
>
>
> > library(zoo)
>
> > library(PerformanceAnalytics)
>
> > rollingCorrelation(manager.ts_at_Data[,1],edhec.ts_at_Data,n=12)
>
> Error in inherits(object, "zoo") : object "manager.ts" not found
>
>
>
>
>
> BR, Shubha
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 04 Dec 2007 - 08:40:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 04 Dec 2007 - 10:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.