What is the windowing logic of function tmsum in DolphinDB?

12 Views Asked by At

Take the first example in tmsum as an example.

tmsum(1 1 3 5 8 15 15 20, 5 2 4 1 2 8 9 10, 3)
// output
[5,7,11,5,2,8,17,10]

Why does the summing calculation in the window of the element “5“ return 5, shouldn’t it be 7 (2+4+1)? Is there an illustration to explain the windowing logic of tmsum?

1

There are 1 best solutions below

0
YaN On

For the windowing logic of tmsum, you may refer to the illustration in Time-Based Moving Functions (tm-functions) (dolphindb.cn).

Windows that involve time-series data slide based on the time units. In your example, since parameter T of tmsum is of integral type, the range of the corresponding window is (Ti - window, Ti].

The window of the first element “1“ is (-2, 1], which contains the value “5“;

The window of the second element “1“ is (-2, 1], which contains values “5“ and “2“;

The window of the third element “3“ is (0, 3], which contains values “5“, “2“, and “4“;

The window of the fourth element “5“ is (2, 5], which contains the values of elements “3“ and “5“, that is “4“ and “1“;

The window of the fourth element “8“ is (5, 8], which contains the values of only the element “8“, that is “2“;

and so on…