ByEmaSimple
ByEmaSimple
calculates Exponential Moving Averages (EMA) in the Deephaven Query Language.
Syntax
The constructor for ByEmaSimple
is shown below.
ByEmaSimple(
nullBehavior,
nanBehavior,
mode,
timescale,
timeUnit,
type
)
Parameters
Parameter | Type | Description |
---|---|---|
nullBehavior | BadDataBehavior | |
nanBehavior | BadDataBehavior | |
mode | enum |
|
timescale | double | The number of units for the EMA window. |
timeUnit | enum |
|
type | enum |
|
Returns
Parameterized constructor to use for calculating an EMA.
Examples
In the following example, we use the time-table and update methods to create a table with random data to simulate real-time data. We then use ByEmaSimple
to configure what we want for our EMA.
ema1sec
is set to use BD_SKIP
to skip null values and skip NaN values. The type is set to LEVEL
and we are using TIME
rather than TICKS
.
ema_data
then uses ema1sec
to calculate the total EMA on a timescale of 10 seconds.
from deephaven.experimental.ema import ByEmaSimple
from deephaven import time_table
import random
def random_char():
return random.choice(['A', 'B', 'C', 'D', 'E', 'F'])
ema1sec = ByEmaSimple('BD_SKIP','BD_SKIP','TIME',10,'SECONDS', type='LEVEL')
result = time_table('00:00:01').update(formulas=["Sym = (String)random_char()", "Numbers = (int)random.randint(0, 100)"])
ema_data = result.view(formulas=["EMA_data = ema1sec.update(Timestamp, Numbers)"]).tail(1)
ema_data_grouped = result.view(formulas=["Sym", "EMA_data = ema1sec.update(Timestamp, Numbers, Sym)"]).last_by(by=["Sym"]).tail(5)
- result
- ema_data
- ema_data_grouped