Skip to main content
Version: Python

emmin_tick

emmin_tick creates a tick-based (row-based) EMMIN (exponential moving minimum) for an update_by table operation. The formula for the tick-based EMMIN of a column XX is:

a=e1τa = e^{\frac{-1}{\tau}}

min0(X)=x0\min_0(X) = x_0

mini(X)=min(amini1(X),  xi)\min_i(X) = \min(a*\min_{i-1}(X), \; x_i)

Where:

  • τ\tau is decay_ticks, an input parameter to the method.
  • mini(X)\min_i(X) is the exponential moving minimum of XX at step ii.
  • xix_i is the current value.
  • ii denotes the time step, ranging from i=1i=1 to i=n1i = n-1, where nn is the number of elements in XX.

Syntax

emmin_tick(
decay_ticks: int,
cols: list[str],
op_control: OperationControl = None,
) -> UpdateByOperation

Parameters

ParameterTypeDescription
decay_ticksint

The decay rate in ticks.

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 count is calculated for all applicable columns.

op_controlOperationControl

Defines how special cases should behave. When None, the default OperationControl settings will be used.

Returns

An UpdateByOperation to be used in an update_by table operation.

Examples

One column, no groups

The following example calculates the tick-based (row-based) EMMIN of the X column, renaming the resulting column to EmMinX. The decay rate, decay_ticks is set to 2. No grouping columns are specified, so the EMMIN is calculated over all rows.

from deephaven.updateby import emmin_tick
from deephaven import empty_table

source = empty_table(10).update(
["Letter = (i % 2 == 0) ? `A` : `B`", "X = randomInt(0,25)"]
)

result = source.update_by(ops=emmin_tick(decay_ticks=2, cols=["EmMinX = X"]))

One EMMIN column, one grouping column

The following example builds on the previous by specifying Letter as the key column. Thus, the EMMIN is calculated on a per-letter basis.

from deephaven.updateby import emmin_tick
from deephaven import empty_table

source = empty_table(10).update(
["Letter = (i % 2 == 0) ? `A` : `B`", "X = randomInt(0,25)"]
)

result = source.update_by(
ops=emmin_tick(decay_ticks=2, cols=["EmMaxX = X"]), by=["Letter"]
)

Multiple EMMIN columns, multiple grouping columns

The following example builds on the previous by calculating the EMMIN of multiple columns in the same UpdateByOperation. Also, the groups are defined by unique combinations of letter and boolean in the Letter and Truth columns, respectively.

from deephaven.updateby import emmin_tick
from deephaven import empty_table

source = empty_table(20).update(
[
"Letter = (i % 2 == 0) ? `A` : `B`",
"Truth = randomBool()",
"X = randomInt(0,25)",
"Y = randomInt(0,25)",
]
)

result = source.update_by(
ops=emmin_tick(decay_ticks=2, cols=["EmMinX = X", "EmMinY = Y"]),
by=["Letter", "Truth"],
)

Multiple UpdateByOperations, multiple grouping columns

The following example builds on the previous by calculating the EMMIN of multiple columns, each with its own UpdateByOperation. This allows each EMMIN to have its own decay rate. The different decay rates are reflected in the renamed resultant column names.

from deephaven.updateby import emmin_tick
from deephaven import empty_table

source = empty_table(20).update(
[
"Letter = (i % 2 == 0) ? `A` : `B`",
"Truth = randomBool()",
"X = randomInt(0,25)",
"Y = randomInt(0,25)",
]
)

emmin_x = emmin_tick(decay_ticks=2, cols=["EmMinX2rows = X"])
emmin_y = emmin_tick(decay_ticks=4, cols=["EmMinY5rows = Y"])

result = source.update_by(ops=[emmin_x, emmin_y], by=["Letter", "Truth"])