I am working with seasonal correlations and I have run into a problem for which I hope someone can help. I am looking for an xts or similar solution. Otherwise, can someone point me in the right direction using standard techniques? I am relatively new to financial time series.
 

For definiteness, say that in an xts object I have weekly returns data from January 15, 2005 through December 17, 2010. I have three (actually about a dozen) columns of securities returns data, security1, security2, ., security3.

 

I designate security1 as the base security. I want to find the correlation for security1 with every other security, but I want to do so:

 

1.      By seasons and years

2.      By seasons only

 

A third problem is a standard correlation matrix of all series but the output is by season and year.

 

Typically the season is quarters.

 

In the past when dealing with one column at a time I was able to use something like the following which closely follows code that I found online, 

 

apply.quarterly(xInput, function(x) apply(x,2,mean))

 

However, I was not able to modify the above to get it to work in the present case.

 

This fails.

 

> apply.quarterly(xInput, function(x) apply(x,2,cor))

Error in FUN(newX[, i], ...) : 

  supply both 'x' and 'y' or a matrix-like 'x'

 

Here is how the output matrices would look.

      Correlation between series 1 and all others
     
      By quarter and by year
      
      Date
     Series1
     Series2
     Series3
     
      1Q 2005
     1.00
     0.28
     0.11
     
      2Q 2005
     1.00
     -0.07
     -0.07
     
      3Q 2005
     1.00
     -0.08
     -0.32
     
      4Q 2005
     1.00
     0.16
     -0.34
     
      1Q 2006
     1.00
     0.09
     0.04
     
        
      Output 2
        
      Correlation between series 1 and all others
     
      By quarter only
       
      Date
     Series1
     Series2
     Series3
     
      1Q
     1.00
     -0.06
     0.58
     
      2Q
     1.00
     0.25
     0.48
     
      3Q
     1.00
     0.52
     0.59
     
      4Q
     1.00
     0.54
     0.11
     
        
      Output 3
        
      All correlations
       
      By quarter and by year
      
      Q1 2005
     Series1
     Series2
     Series3
     
      Series1
     1.00
     0.78
     0.73
     
      Series2
     0.78
     1.00
     0.98
     
      Series3
     0.73
     0.98
     1.00
     
        
      Q4 2010
     Series1
     Series2
     Series3
     
      Series1
     1.00
     0.97
     0.95
     
      Series2
     0.97
     1.00
     1.00
     
      Series3
     0.95
     1.00
     1.00
     

 

Thanks.



Ira



	[[alternative HTML version deleted]]

