Page 1 of 1

Rolling window correlation

Posted: Thu Jun 03, 2010 5:47 am
by randomlearning
Hi everyone.

This is my first post in this forum and I am already asking questions. :)

I have two series X, Y, and Z and each one of them has 50 yearly observations. I would like to create a 5-year rolling window for the correlation coefficient for all the possible combinations, but I am struggling with it (I know, I am a newbie...).

I have read this thread, but it seems that that will give me a backward correlation (at each point the statistic give us only the previous 10 years) and I want to use five years of data both before and after. Hope this is clear.

Thanks in advance! :D

Re: Rolling window correlation

Posted: Thu Jun 03, 2010 8:00 am
by EViews Gareth
Just put a lead on your series.

i.e.

Code: Select all

@movcor(x(2),y(2),5)

Re: Rolling window correlation

Posted: Thu Jun 03, 2010 12:23 pm
by randomlearning
Just put a lead on your series.

i.e.

Code: Select all

@movcor(x(2),y(2),5)
Thanks for your answer. :)

Isn't that leading both series? I guess I don't get how leading both series will give me at each point the correlation for both five years after and before.

Thanks once again.

Rolling window correlation

Posted: Thu Jun 03, 2010 12:55 pm
by EViews Gareth
Sorry, misunderstood. Put a lead of 5 years on both.

Re: Rolling window correlation

Posted: Thu Jun 03, 2010 1:37 pm
by randomlearning
Thanks, but still is not working. Even when I use this:

Code: Select all

@movcor(x(5),y(5),10)
It does not give me the correct values (I'm checking with another software). For once, by leading the variable, I am getting rid of the first observations so that does not work.

Maybe this example will clarify what I want: Suppose (annual data) X={x1,x2,x3,x4,x5,x6} and Y={y1,y2,y3,y4,y5,y6} and suppose that I want a two year rolling window (two years before and two years after each observation). Therefore, the series should be Correlation={NA, NA, corr({x1,x2,x3,x4,x5},{y1,y2,y3,y4,y5}), corr({x2,x3,x4,x5,x6},{y2,y3,y4,y5,y6}),NA,NA})}

Please, let me know if you need a numeric example.

Thanks.

Re: Rolling window correlation

Posted: Thu Jun 03, 2010 3:29 pm
by EViews Gareth
Did you check the EViews numbers manually? They seem to work for me:

Code: Select all

create u 6 rndseed 1 series y=rnd series x=rnd group g x y series corr = @movcor(y(2),x(2),5) 'check by making two matrices from the middle two parts, and calculating the correlations smpl 1 5 matrix s1 = @convert(g) freeze(cor1) s1.cor smpl 2 6 matrix s2 = @convert(g) freeze(cor2) s2.cor

Re: Rolling window correlation

Posted: Fri Jun 04, 2010 5:37 am
by randomlearning
Isn't working for me...

Can I post the series that I'm trying to work with as well as the result I'm getting and I `correct' one?

Thanks.

Rolling window correlation

Posted: Fri Jun 04, 2010 7:19 am
by EViews Gareth
Sure

Re: Rolling window correlation

Posted: Fri Jun 04, 2010 8:36 am
by randomlearning
You were right. I used @movcor(y(alpha),x(alpha),2*alpha+1) where alpha is the size of the window and it worked.

Thanks! :)

Re: Rolling window correlation

Posted: Thu Dec 16, 2010 6:35 am
by damenic
Does anybody know how to calculate rolling window correlation for even number of years?
thanks.