window#
- swordfish.function.window()#
Apply func over a sliding window of funcArgs. Each element in funcArgs corresponds to a window that is determined by range. The result has the same dimension as that of funcArgs (If funcArgs is a tuple, the result has the same dimension as that of each element in the tuple).
Suppose range is set to d1:d2, the windows are determined based on the following rules:
When funcArgs is a vector, range must be a pair of integers. For the ith element in funcArgs, the corresponding window contains elements at position [i+d1, i+d2].
When funcArgs is an indexed series or indexed matrix:
If funcArgs is indexed by time, for fi (the ith element in the index of funcArgs), the corresponding window contains elements at index [temporalAdd(fi, d1), temporalAdd(fi, d2)].
If funcArgs is indexed by integral values, range must also be integral. For fi (the ith element in the index of funcArgs), the corresponding window contains elements at index [fi+d1, fi+d2].
Compared with the moving function, the window function has a more flexible window. moving can be roughly considered as a special case of window, where the right boundary of the range parameter is 0. However, please note the following differences:
When the window is based on element counts, moving returns null when the number of windowed elements does not satisfy the minPeriods, whereas window does not have a minimum count requirement.
When the window is based on time, the left boundary of the window of moving is exclusive and the right boundary is inclusive; whereas both boundaries of the window of window are inclusive. In this example:
Suppose a window with the size of “3d” slides over an index of DATETIME type to apply calculation. For the point “2022.01.05T09:00:00” in the index, the range of the corresponding window in moving is (2022.01.02T09:00:00,2022.01.05T09:00:00], whereas it’s [2022.01.03T09:00:00,2022.01.05T09:00:00] in window (with the range parameter specified as “-2d:0d”).
- Parameters:
func (Constant) – An aggregate function.
funcArgs (Constant) – The argument(s) of func. It is a tuple if there are more than one parameter of func.
range (Constant) –
A pair of integers or duration values (both boundaries are inclusive).
Note
If range is of DURATION type, funcArgs must be an indexed matrix or an indexed series.
- Returns:
A vector with the same type as the first window computation result.
- Return type: