ByEmaSimple
ByEmaSimple
calculates Exponential Moving Averages (EMA) in the Deephaven Query Language.
Syntax
The constructor for ByEmaSimple
is shown below.
new ByEmaSimple(
nullBehavior,
nanBehavior,
type,
mode,
timescale,
timeUnit
)
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.
import io.deephaven.numerics.movingaverages.ByEma
import io.deephaven.numerics.movingaverages.AbstractMa
import io.deephaven.numerics.movingaverages.ByEmaSimple
import java.util.concurrent.TimeUnit
ema1sec = new ByEmaSimple(
ByEma.BadDataBehavior.BD_SKIP,
ByEma.BadDataBehavior.BD_SKIP,
AbstractMa.Type.LEVEL,
AbstractMa.Mode.TIME,
10,
TimeUnit.SECONDS
)
chars = "ABCDE".toCharArray()
result = timeTable('00:00:01').update("Sym = chars[ new Random().nextInt(5)]", "Numbers = new Random().nextInt(100)")
ema_data = result.view("EMA_data = ema1sec.update(Timestamp, Numbers)").tail(1)
ema_data_grouped = result.view("Sym", "EMA_data = ema1sec.update(Timestamp, Numbers, Sym)").lastBy("Sym").tail(5)