On Tue, 17 Jan 2017, Sven Schreiber wrote:
Am 17.01.2017 um 08:06 schrieb Riccardo (Jack) Lucchetti:
> On Mon, 16 Jan 2017, Tomas Nilsson wrote:
>
>> Is there an option to compute the rolling correlation between multiple
>> time series? I'm seeing some mentioning on this topic in 2016 between
>> Fernando and Sven but not sure what happened to it. Thanks
I re-checked, and I think what happened is that Fernando found a solution for
himself ;-)
> you mean, given n series, return n*(n+1) series of covariances computed
> on a fixed observation window?
>
> If so, try this:
Jack, sorry, but your code must look just horrible for regular gretl users.
Why wouldn't a simple loop be enough?
(untested:)
<hansl>
list X = mylist # define variable list here
N = 10 # set how many subsamples here
loop N
corr(X) # prints out the correlation matrix
smpl +1 +1 # moves the subsample forward by one
endloop
</hansl>
If you want to capture the numbers for further use, you can do that with an
array of matrices:
(untested)
<hansl>
matrices MC = array(N)
loop i = 1..N
matrix MC[i] = mcorr( {X} )
smpl +1 +1
endloop
</hansl>
You mean it's too long and complex? Hm, maybe you're right.
Well, storing the results as series does have certain advantages. For
example, it's easy to plot them through time. Besides, I think that the
script I posted is reasonably general while not being horribly
inefficient. Finally, it's a nice showcase for lesser-known features like
the genseries() function.
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------