[moving this to the devel list]
Am 13.04.2018 um 21:50 schrieb Sven Schreiber:
 Am 13.04.2018 um 18:24 schrieb Sven Schreiber: 
> I'm wondering how to achieve something that would be the
multivariate 
> generalization of the lrvar function (long-run variance of a series). 
 Duh, dummy me -- it's in my own package CommonTrendsTest. 
I'm reproducing the two private functions autocovar() and longrunvar() 
from the package below. The question is whether it might make sense to 
add these to the extra package, or whether it could be considered to 
generalize the built-in lrvar() to multivariate (like it seems to be the 
case in R, for example).
What do you think?
(I'm also open for suggestions to increase efficiency, but that's not 
very pressing right now. I think I read about fast algorithms that use 
the FFT for example.)
thanks,
sven
----
<from_CommonTrendsTest>
function matrix autocovar (const matrix indatamat,
                            int lag[0::0],
                            bool demeaned[0])
   /*	Computes the autocovariance at lag "lag"
   for a multivariate time series.
   Returns a NxN covariance matrix
   */
   # N = cols(indatamat)
   T = rows(indatamat)
   matrix datademeaned = demeaned ? indatamat : cdemean(indatamat)
   matrix result = datademeaned[lag+1 : T,]'datademeaned[1 : T-lag,]
   result /= T
   /* should hopefully be equivalent to the following loop code:
   matrix result = zeros(N,N)
   loop for tindex=lag..T
     matrix dev1 = datademeaned[tindex,]
     matrix dev2 = datademeaned[tindex-lag,]
     matrix result += dev1'dev2
   endloop
   matrix result /= T
   */
   return result
end function
function matrix longrunvar (const matrix indatamat,
                             bool demeaned[0],
                             int lagtrunc[1::4])
   /* indatamat is a TxN time series matrix
   Bartlett window
   returns an NxN matrix (spectral density at frequency zero)
   */
   N = cols(indatamat)
   matrix result = zeros(N,N)
   loop tau = 1..lagtrunc	-q
     matrix Gamma = autocovar(indatamat, tau, demeaned)
     # positive and negative tau range together:
     result += (1 - tau / (lagtrunc + 1)) * (Gamma + Gamma')
   endloop
   # add the tau=0 part:
   result += autocovar(indatamat, 0, demeaned)
   return result
end function
</from_CommonTrendsTest>