Back to Influxdb

doubleEMA() function

content/flux/v0/stdlib/universe/doubleema.md

latest3.1 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/universe/universe.flux#L4468-L4474 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

doubleEMA() returns the double exponential moving average (DEMA) of values in the _value column grouped into n number of points, giving more weight to recent data.

Double exponential moving average rules

  • A double exponential moving average is defined as doubleEMA = 2 * EMA_N - EMA of EMA_N.
    • EMA is an exponential moving average.
    • N = n is the period used to calculate the EMA.
  • A true double exponential moving average requires at least 2 * n - 1 values. If not enough values exist to calculate the double EMA, it returns a NaN value.
  • doubleEMA() inherits all exponentialMovingAverage() rules.
Function type signature
js
(<-tables: stream[{A with _value: B}], n: int) => stream[C] where B: Numeric, C: Record

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

n

({{< req >}}) Number of points to average.

tables

Input data. Default is piped-forward data (<-).

Examples

Calculate a three point double exponential moving average

js
import "sampledata"

sampledata.int()
    |> doubleEMA(n: 3)

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

_time_value*tag
2021-01-01T00:00:00Z-2t1
2021-01-01T00:00:10Z10t1
2021-01-01T00:00:20Z7t1
2021-01-01T00:00:30Z17t1
2021-01-01T00:00:40Z15t1
2021-01-01T00:00:50Z4t1
_time_value*tag
2021-01-01T00:00:00Z19t2
2021-01-01T00:00:10Z4t2
2021-01-01T00:00:20Z-3t2
2021-01-01T00:00:30Z19t2
2021-01-01T00:00:40Z13t2
2021-01-01T00:00:50Z1t2

Output data

_time_value*tag
2021-01-01T00:00:40Z16.333333333333336t1
2021-01-01T00:00:50Z7.916666666666668t1
_time_value*tag
2021-01-01T00:00:40Z15.027777777777779t2
2021-01-01T00:00:50Z5.034722222222221t2

{{% /expand %}} {{< /expand-wrapper >}}