mcovarp

Syntax

mcovarp(X, Y, window, [minPeriods])

Please see mFunctions for the parameters and windowing logic.

Details

Calculates the population covariance of X and Y over a sliding window of the specified length, measured by either element count or time.

Returns

The result is of type DOUBLE, with the same form as the input parameters.

Examples

x=1..10;
y=9 5 3 4 5 4 7 1 3 4;
mcovarp(x,y,5);
// output: [,,,,-1.8,0,1.6,-0.8,-1.4,-0.8]

mcovarp(x, y, 5, 3);
// output: [,,-2,-2.13,-1.8,0,1.6,-0.8,-1.4,-0.8]


x1 = indexedSeries(date(2026.01.05)+1..10, x)
y1 = indexedSeries(date(2026.01.05)+1..10, y)
mcovarp(x1,y1,5d)
0
2026.01.06 0
2026.01.07 -1
2026.01.08 -2
2026.01.09 -2.125
2026.01.10 -1.8
2026.01.11 0
2026.01.12 1.6
2026.01.13 -0.8
2026.01.14 -1.4
2026.01.15 -0.8

Related Function: covarp