Skip to content
Back to formatted view

Raw Message

Message-ID: <1309434248.18549.73.camel@brian-rcg>
Date: 2011-06-30T11:44:08Z
From: Brian G. Peterson
Subject: Rolling Correlation Problem
In-Reply-To: <1309428712418-3635256.post@n4.nabble.com>

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