rolling_formula_tick
rolling_formula_tick
creates a rolling formula column in an update_by
table operation for the supplied column names, using ticks as the windowing unit.
Ticks are row counts, and you may specify the reverse and forward window in number of rows to include. The current row is considered to belong to the reverse window, but not the forward window. Also, negative values are allowed and can be used to generate completely forward or completely reverse windows. Here are some examples of window values:
rev_ticks = 1, fwd_ticks = 0
- contains only the current row.rev_ticks = 10, fwd_ticks = 0
- contains 9 previous rows and the current row.rev_ticks = 0, fwd_ticks = 10
- contains the following 10 rows, but excludes the current row.rev_ticks = 10, fwd_ticks = 10
- contains the previous 9 rows, the current row, and the 10 rows following.rev_ticks = 10, fwd_ticks = -5
- contains 5 rows, beginning at 9 rows before, ending at 5 rows before the current row (inclusive).rev_ticks = 11, fwd_ticks = -1
- contains 10 rows, beginning at 10 rows before, ending at 1 row before the current row (inclusive).rev_ticks = -5, fwd_ticks = 10
- contains 5 rows, beginning 5 rows following, ending at 10 rows following the current row (inclusive).
Syntax
rolling_formula_tick(
formula: str,
formula_param: str,
cols: Union[str, list[str]],
rev_ticks: int,
fwd_ticks: int = 0
) -> UpdateByOperation
Parameters
Parameter | Type | Description |
---|---|---|
formula | str | The user-defined formula to apply to each group. The formula can contain a combination of any of the following:
|
formula_param | str | The parameter name for the input column’s vector within the formula. If formula is |
cols | Union[str, list[str]] | The column(s) to be operated on. These can include expressions to rename the output (e.g., |
rev_ticks | int | 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_ticks | int | 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 prices
table using a rolling_formula_tick
operation to calculate a rolling some of squares of prices:
from deephaven.updateby import rolling_formula_tick, rolling_formula_time
from deephaven import empty_table
prices = empty_table(20).update(
[
"Timestamp = '2024-02-23T09:30:00 ET' + ii * SECOND",
"Ticker = (i % 2 == 0) ? `NVDA` : `GOOG`",
"Price = randomDouble(100.0, 500.0)",
]
)
formula_tick = rolling_formula_tick(
formula="sum(x * x)",
formula_param="x",
cols="SumPriceSquared_Tick = Price",
rev_ticks=5,
)
result = prices.update_by(ops=[formula_tick], by="Ticker")
- prices
- result