emmax_tick
emmax_tick
creates a tick-based (row-based) EMMAX (exponential moving maximum) for an update_by
table operation. The formula for the tick-based EMMAX of a column is:
Where:
- is
decay_ticks
, an input parameter to the method. - is the exponential moving maximum of at step .
- is the current value.
- denotes the time step, ranging from to , where is the number of elements in .
Syntax
emmax_tick(
decay_ticks: int,
cols: list[str],
op_control: OperationControl = None,
) -> UpdateByOperation
Parameters
Parameter | Type | Description |
---|---|---|
decay_ticks | int | The decay rate in ticks. |
cols | list[str] | The column(s) to be operated on. These can include expressions to rename the output (e.g., |
op_control | OperationControl | Defines how special cases should behave. When |
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) EMMAX of the X
column, renaming the resulting column to EmMaxX
. The decay rate, decay_ticks
is set to 2. No grouping columns are specified, so the EMMAX is calculated over all rows.
from deephaven.updateby import emmax_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=emmax_tick(decay_ticks=2, cols=["EmMaxX = X"]))
- result
- source
One EMMAX column, one grouping column
The following example builds on the previous by specifying Letter
as the key column. Thus, the EMMAX is calculated on a per-letter basis.
from deephaven.updateby import emmax_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=emmax_tick(decay_ticks=2, cols=["EmMaxX = X"]), by=["Letter"]
)
- result
- source
Multiple EMMAX columns, multiple grouping columns
The following example builds on the previous by calculating the EMMAX 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 emmax_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=emmax_tick(decay_ticks=2, cols=["EmMaxX = X", "EmMax_Y = Y"]),
by=["Letter", "Truth"],
)
- result
- source
Multiple UpdateByOperations
, multiple grouping columns
The following example builds on the previous by calculating the EMMAX of multiple columns, each with its own UpdateByOperation
. This allows each EMMAX to have its own decay rate. The different decay rates are reflected in the renamed resultant column names.
from deephaven.updateby import emmax_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)",
]
)
emmax_x = emmax_tick(decay_ticks=2, cols=["EmMaxX2rows = X"])
emmax_y = emmax_tick(decay_ticks=4, cols=["EmMaxY5rows = Y"])
result = source.update_by(ops=[emmax_x, emmax_y], by=["Letter", "Truth"])
- result
- source