[R-SIG-Finance] Rolling Correlation Problem

Brian G. Peterson brian at braverock.com
Thu Jun 30 13:44:08 CEST 2011


On Thu, 2011-06-30 at 03:11 -0700, tonyp wrote:
> 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
<...>
> Do you know how to calculate the rolling correlations in the presence of too
> many zeros?

See:

require(TTR)
?runCor

Regards,

  - Brian


-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list