Time-Based Moving Functions (tm-functions)

For most window calculations involving time-series data, it’s often required that the windows slide based on the time units. Therefore, DolphinDB introduces the tm-functions for such cases. The tm-functions act similarly with the m-functions when the parameter window is a DURATION value. However, the tm-functions can be used in SQL statements to perform calculations on the columns of a table without requiring an indexed series or matrix.

First Release

1.30.14/2.00.2

Introduction

$ tmoving(func, T, funcArgs, window)

Note: The tm-functions are optimized for their specialized use cases and therefore have a better performance than the higher-order function tmoving().

  • A template of the tm-functions:

$ tmfunc(T, X, window)
$ tmfunc(T, X, Y, window)

Parameters

T is a non-strictly increasing vector of temporal or integral type. It cannot contain NULL values.

X (Y) is a vector of the same size as T.

window is a scalar of positive integer or DURATION type indicating the size of the sliding window.

List of Functions

See also

tmfunc(T, X, window)

tmsum, tmsum2, tmavg, tmwavg, tmwsum, tmprod,

tmmax, tmmin, tmmed, tmfirst, tmlast,

tmrank, tmcount, tmpercentile, tmstd, tmstdp,

tmkurtosis, tmskew, tmvar, tmvarp.

tmfunc(T, X, Y, window)

tmbeta, tmcorr, tmcovar.

Windowing Logic

For the tm-functions, window can have the positive integral or DURATION type. The window size is measured by time.

For each element Ti in T:

  • When T is an integral value, the range of the corresponding window is (Ti - window, Ti ]

  • When T is a temporal value, the range of the corresponding window is (temporalAdd(Ti, -window), Ti]

The following example explains how the window slides:

$ T = [2022.01.01, 2022.01.02, 2022.01.03, 2022.01.06, 2022.01.07, 2022.01.08, 2022.01.10, 2022.01.11]
$ X = 1..8

$ print tmsum(T, X, window=3)
[1, 3, 6, 4, 9, 15, 13, 15]
../../_images/tmfunc_1.png