Skip to content

Rolling Correlation Problem

3 messages · tonyp, Brian G. Peterson, matthias.kornexl at raiffeisenbank.at

#
Hello Masters of R,

I was wondering if somebody can help with a problem I am facing. I have a
zoo object consisting of 500 vectors representing constituents of a
benchmark. I want to calculate the rolling correlation on 22 window period.
The observations are daily return series. However, when I run  my code 

x22=rollapply(spx,width = 22, FUN = function(x) {y <- cor(x);
 round(mean(y[lower.tri(y)]),3); }, by.column = FALSE, align='right')

I get warning message such as the underneath one due to too many 0000s in
some constituents. 

Warning messages:
1: In cor(x) : the standard deviation is zero
2: In cor(x) : the standard deviation is zero
3: In cor(x) : the standard deviation is zero
4: In cor(x) : the standard deviation is zero
5: In cor(x) : the standard deviation is zero
6: In cor(x) : the standard deviation is zero
7: In cor(x) : the standard deviation is zero
8: In cor(x) : the standard deviation is zero


Do you know how to calculate the rolling correlations in the presence of too
many zeros?

Thanks.

AP

--
View this message in context: http://r.789695.n4.nabble.com/Rolling-Correlation-Problem-tp3635256p3635256.html
Sent from the Rmetrics mailing list archive at Nabble.com.
#
On Thu, 2011-06-30 at 03:11 -0700, tonyp wrote:
<...>
See:

require(TTR)
?runCor

Regards,

  - Brian