rolling_avg_time

rolling_avg_time creates a simple moving average in an update_by table operation using time as the windowing unit. Time can be specified as integer numbers of nanoseconds or strings. The moving average can be calculated using forward and/or backward windows.

SMA=1nxinSMA = \frac{\sum_{1}^{n}x_{i}}{n}

Where:

  • nn is the number window size in ticks
  • xix_{i} is the current value

For a time-based SMA, n is the number of observations in the window, determined by fwd_time and rev_time.

Syntax

Parameters

ParameterTypeDescription
ts_colstr

The name of the column containing timestamps.

colslist[str]

The column(s) to be operated on. These can include expressions to rename the output (e.g., NewCol = Col). If None, the rolling average is calculated for all applicable columns.

rev_timeUnion[int,str]

The look-behind window size. This can be expressed as an integer in nanoseconds or a string duration, e.g., "PT00:00:00.001" or "PTnHnMnS", where H is hour, M is minute, and S is second.

fwd_timeUnion[int,str]

The look-forward window size. This can be expressed as an integer in nanoseconds or a string duration, e.g., "PT00:00:00.001" or "PTnHnMnS", where H is hour, M is minute, and S is second.

Returns

An UpdateByOperation to be used in an update_by table operation.

Examples

The following example performs an update_by on the source table using three rolling_avg_time operations. Each uses different rev_time and fwd_time values to show how they affect the output.