tmcovarp
Syntax
tmcovar(T, X, Y, window)
Please see tmFunctions 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 time).
Returns
A DOUBLE vector.
Examples
T = 1 1 1 2 5 6
X = 1 4 2 -1 2 4
Y = 2 5 -3 6 9 1
m = table(T as t,X as x, Y as y)
select *, tmcovarp(t, y, x, 3) from m
| t | x | y | tmcovarp_t |
|---|---|---|---|
| 1 | 1 | 2 | 0 |
| 1 | 4 | 5 | 2.25 |
| 1 | 2 | -3 | 2.2222222222222223 |
| 2 | -1 | 6 | -1.25 |
| 5 | 2 | 9 | 0 |
| 6 | 4 | 1 | -4 |
T = 2026.01.02 2026.01.02 2026.01.04 2026.01.05 2026.01.07 2026.01.08
X = 1 4 2 -1 2 4
Y = 2 5 -3 6 9 1
m = table(T as t,X as x, Y as y)
select *, tmcovarp(t, y, x, 3d) from m
| t | x | y | tmcovarp_t |
|---|---|---|---|
| 2026.01.02 | 1 | 2 | 0 |
| 2026.01.02 | 4 | 5 | 2.25 |
| 2026.01.04 | 2 | -3 | 2.2222222222222223 |
| 2026.01.05 | -1 | 6 | -6.75 |
| 2026.01.07 | 2 | 9 | 2.25 |
| 2026.01.08 | 4 | 1 | -4 |
select *, tmcovarp(t, y, x, 1w) from m
| t | x | y | tmcovarp_t |
|---|---|---|---|
| 2026.01.02 | 1 | 2 | 0 |
| 2026.01.02 | 4 | 5 | 2.25 |
| 2026.01.04 | 2 | -3 | 2.2222222222222223 |
| 2026.01.05 | -1 | 6 | -1.25 |
| 2026.01.07 | 2 | 9 | -0.48 |
| 2026.01.08 | 4 | 1 | -1.3333333333333333 |
Related Function: covarp
