tmcovarpTopN

Syntax

tmcovarpTopN(T, X, Y, S, window, top, [ascending=true], [tiesMethod='latest'])

Please see tmTopN for the parameters and windowing logic.

Details

Within a sliding window of given length (measured by time), the function stably sorts X and Y by S in the order specified by ascending, then calculates the moving population covariance of the first top pairs of elements in X and Y.

Returns

A vector of DOUBLE type.

Examples

T=2026.01.03+1..7
X = [2, 1, 4, 3, 4, 3, 1]
Y=[1, 7, 8, 9, 0, 5, 8]
S = [5, 8, 1, , 1, 1, 3] 
// The null values in S are ignored in data sorting, and the corresponding elements in X and Y do not participate in calculation
tmcovarpTopN(T,X,Y,S,6,4)
// output: [0,-1.5,1.22,1.22,-0.75,0.875,-2]

T=2026.01.03 2026.01.07 2026.01.08 2026.01.10 2026.01.11 2026.01.12
X=8 3 1 2 5 2
Y=1 7 8 9 0 5
S=1 5 2 3 1 1
t=table(T as time, X as val1, Y as val2, S as id)
select tmcovarpTopN(time,val1,val2,id,4,3) as topN from t
topN
0
0
-0.5
-0.33
-6.44
-4.67

Related Function: covarp