Skip to main content

Better, faster EMAs

· One min read
DALL·E prompt: exponential moving average, 3d UI, minority report floating hologram display
Chip Kent
Brought to you by Deephaven's update_by

Without a doubt, the most requested Deephaven feature has been more powerful moving averages.
In version 0.15.0, Deephaven improved aggregations through update_by.

Now, you can compute exponential moving averages (EMAs) that are more efficient and properly update when values in the middle of your table change.

Let's look at an example:

from deephaven import time_table
from deephaven.updateby import ema_time

t1 = time_table('PT00:00:00.1') \
.update(["Label = ii%2 == 0 ? `cos` : `sin`", "X = ii%2 == 0 ? cos(0.05*ii)+0.7*random() : sin(0.01*ii)+0.7*random()"])

t2 = t1.update_by([ema_time("Timestamp", "PT00:00:01", "XEma=X")], by="Label")

from deephaven.plot import Figure

p = Figure() \
.plot_xy("Value", t=t2, x="Timestamp", y="X", by=["Label"]) \
.plot_xy("EMA", t=t2, x="Timestamp", y="XEma", by=["Label"]) \
.show()

Future releases will support Simple Moving Averages (SMAs), moving standard deviations, and more. See the updateby Python module for the latest list of supported update_by aggregations. If there is a new aggregation you want to see, tell us on Slack.