Version: Python

# rolling_avg_tick

rolling_avg_tick creates a simple moving average in an update_by table operation using table ticks as the windowing unit. Ticks are row counts. The moving average can be calculated using forward and/or backward windows. The equation for a tick-based simple moving average is:

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

Where:

• $n$ is the window size in ticks
• $x_{i}$ is the current value

For a tick-based SMA, n is the window size, determined by fwd_ticks and rev_ticks.

## Syntax​

rolling_avg_tick(cols: list[str], rev_ticks: int, fwd_ticks: int) -> UpdateByOperation

## Parameters​

ParameterTypeDescription
colslist[str]

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

rev_ticksint

The look-behind window size in rows. If positive, it defines the maximum number of rows before the current row that will be used. If negative, it defines the minimum number of rows after the current row that will be used. Includes the current row.

fwd_ticksint

The look-forward window size in rows. If positive, it defines the maximum number of rows after the current row that will be used. If negative, it defines the minimum number of rows before the current row that will be used.

## 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_tick operations. Each operation uses different rev_ticks and fwd_ticks values to show how they affect the output.

from deephaven.updateby import rolling_avg_tickfrom deephaven import empty_tablesource = empty_table(10).update(    ["Letter = (i % 2 == 0) ? A : B", "X = randomInt(0, 100)"])op_before = rolling_avg_tick(cols=["OpBefore = X"], rev_ticks=3, fwd_ticks=-1)op_after = rolling_avg_tick(cols=["OpAfter = X"], rev_ticks=-1, fwd_ticks=3)op_middle = rolling_avg_tick(cols=["OpMiddle = X"], rev_ticks=1, fwd_ticks=1)result = source.update_by(ops=[op_before, op_after, op_middle], by="Letter")