Better, faster EMAs

Brought to you by Deephaven’s update_by

Deephaven Data Labs
1 min readOct 17, 2022

By Chip Kent

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_decay
t1 = time_table("00: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_decay("Timestamp", "00:00:01", "XEma=X")], by="Label")from deephaven.plot import Figurep = 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.

--

--

Deephaven Data Labs

Deephaven is a high-performance time-series query engine. Its full suite of API’s and intuitive UI make data analysis easy. Check out deephaven.io