Rolling covariance matrix of TemporalData with 3 paths

I know how to use MovingMap with TimeSeries, but MovingMap threads over paths. What if I want to calculate a function of multiple paths?

In my case, I have 3 paths, and for each window I would like to know the corresponding $3\times3$ covariance matrix (and then do something with the eigenvalues). How do I implement this rolling covariance matrix (or any function thereof, e.g., Max[Eigenvalues[covarianceMatrix]]?

P.S. A simple test scenario can be generated using

t = Range[0., 2. Pi, 0.001];
x = Through[{Cos, Sin, Identity}[t]];
td = TemporalData[x, {t}];
covarianceMatrix = Covariance[Transpose[td["ValueList"]]]


or

maxLambda=Max[Eigenvalues[Covariance[Transpose[td["ValueList"]]]]]

Except I would like to have maxLambda to be a (single-path) TimeSeries that maps each time (and an assumed specification of a window around that time) to a maximum eigenvalue.

• Meet us halfway: what formula would you use to compute the covariance matrix for a single window? – J. M. will be back soon Sep 9 '17 at 22:22
• Covariance[Transpose[td["ValueList"]]], – freevillage Sep 10 '17 at 22:36

Are you good with building a composite EventSeries of your TemporalData (the paths have to correspond in time for this to work)? If so, this'll do for you:

pev = {#[[1, 1]], #[[All, 2]]} & /@ Transpose[td["Paths"]] //
EventSeries;
mev = MovingMap[Covariance, pev, 5];


Then looking at a few of these:

mev["ValueList"][[1]]~RandomSample~2 // Map[MatrixPlot]


• Do you mean that I need to first resample my temporal data on [min(firsttimes),max(lasttimes)]? If this is what you mean then yes, that should work. I assume that I can compose that with Eigenvalues and Max (or something else) to get a TemporalData object. I just need (or prefer) to have a TemporalData object at the end. – freevillage Sep 12 '17 at 2:43
• @freevillage do you paths have the same time-component? If not I'm not entirely sure how a moving covarience matrix across the three of them would even work. So yes, resampling is necessary there. If you want a TemporalData object at the end just use TemporalData@mev. – b3m2a1 Sep 12 '17 at 2:59