Cumulative Window Functions (cum-functions)
The cumulative window starts from a specified data/time point and aggregates data over consecutive data points or time intervals. DolphinDB provides the cumulative window functions (cum-functions) for cases involving cumulative windows.
Introduction
-
higher-order function accumulate:
accumulate(func, X, [init])
If init is specified, the result for the first window is
init + X[0]
. -
Syntax templates for the cum-functions:
cumfunc(X) cumfunc(X, Y)
Parameters:
X (Y) is a scalar/vector/matrix/table/tuple with equal-length vectors.
List of Functions
Windowing Logic
The cum-function performs a cumulative calculation on each element, then returns a vector of the same length (or matrix of the same size) as the input.
The following example illustrates the calculation rules:
X = 1 1 2 3 4 5 NULL 8 9 1 3
cumsum(X)
// output
[1, 2, 4, 7, 11, 16, 16, 24, 33, 34, 37]