Page 1 of 1

Rolling Covariance

Posted: Mon Jun 25, 2018 7:57 am
by Jules89
Dear Tom,

I have a very simple prolem. When I have two series x and y, how can I calculate a rolling covariance between the two.
For example I want to calculate cov(x(t),y(t)) for t=1,...,20. Then I want to calculate cov(x(t),y(t)) for t=2,...,21 and so on. Then I want to save the covariance for later calculation within each iteration of the loop.

The cross instruction works well for printing the values, but I don't know how to safe the values. My code is

start = some date
end = some date +20

Code: Select all

do i = 0, 1813

   cross(from=0, to=0,covariances,results=cov) x y start+i end+i

end do i
Thank you

best jules

Re: Rolling Covariance

Posted: Mon Jun 25, 2018 10:55 am
by TomDoan
That's a rather short window, isn't it?

At any rate, the bookkeeping for rolling window analyses is largely the same regardless of what you're computing. See rollingcausality.rpf and the handling of causetests series. In your case, the statistic that you want to save on each trip through is cov(1).

Re: Rolling Covariance

Posted: Tue Jun 26, 2018 7:18 am
by Jules89
Thanks Tom,

cov(1) was the command I was serching for.


Best Jules