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
you mean, given n series, return n*(n+1) series of covariances computed on
a fixed observation window?
If so, try this:
<hansl>
function list rolling_vcv(list X, scalar length)
list ret = null
n = nelem(X)
m = n*(n+1)/2
scalar T = $nobs
set warnings off
matrix wrk = mshape(NA, T, m)
matrix mX = {X}
ini = 1
fin = length
loop t = length .. T --quiet
matrix cX = mX[ini:fin,]
wrk[t,] = vech(mcov(cX))'
ini++
fin++
endloop
k = 1
loop i=1..n --quiet
sname = sprintf("var_%02d", i)
ret += genseries(sname, wrk[, k])
k++
loop j = i+1..n --quiet
sname = sprintf("cov_%02d_%02d", i, j)
ret += genseries(sname, wrk[, k])
k++
endloop
endloop
return ret
end function
open AWM --quiet
list RATES = STN LTN
list R = rolling_vcv(RATES, 16)
</hansl>
hope this helps
-------------------------------------------------------
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
-------------------------------------------------------