mcovarpTopN
Syntax
mcovarpTopN(X, Y, S, window, top, [ascending=true],
[tiesMethod='oldest'])
Please see mTopN for the parameters and windowing logic.
Details
Within a sliding window of given length (measured by the number of elements), the function stably sorts X and Y by S in the order specified by ascending, then calculates the population covariance of the first top pairs of elements in X and Y.
Returns
The result is of type DOUBLE, with the same form as the input parameters.
Examples
x = NULL 3 8 4 0
y = 2 3 1 7 3
s = 5 NULL 8 9 4
mcovarpTopN(x, y, s, 3, 2)
// output: [ , , 0, -6, -4]
s2=2026.01.01 2026.02.03 2026.01.23 2026.04.06 2026.12.29
mcovarpTopN(x, y, s2, 3, 2)
// output: [ , 0, 0, -2.5, -6]
x1 = matrix(x, 4 3 6 2 3)
y1=matrix(3 7 9 3 2, y)
s1=matrix(2 3 1 7 3, s)
mcovarpTopN(x, y1, s1, 3, 2)
| 0 | 1 |
|---|---|
| 0 | |
| 0 | 0 |
| 2.5 | -6 |
| 14 | -4 |
mcovarpTopN(x1, y1, s, 3, 2)
| 0 | 1 |
|---|---|
| 0 | |
| 0 | |
| 0 | -0.5 |
| 6 | -6 |
| 14 | -1.5 |
mcovarpTopN(x1, y1, s1, 3, 2)
| 0 | 1 |
|---|---|
| 0 | |
| 0 | 0 |
| 0 | -0.5 |
| 2.5 | -6 |
| 14 | -1.5 |
Related Function: covarp
