指数移动平均() 函数
exponentialMovingAverage() 计算 _value 列中 n 个值的指数移动平均,给最近的数据赋予更大的权重。
指数移动平均规则
- 指数移动平均的第一个值是
n个值的代数平均数。 - 后续值计算为
y(t) = x(t) * k + y(t-1) * (1 - k),其中:y(t)是在时间t的指数移动平均。x(t)是在时间t的值。k = 2 / (1 + n)。
- 仅由
null值填充的期间的平均值是null。 - 指数移动平均会跳过
null值。
函数类型签名
(<-tables: stream[{A with _value: B}], n: int) => stream[{A with _value: B}] where B: Numeric
有关更多信息,请参见 Function type signatures。
参数
n
(必填) 平均值的数量。
表格
输入数据。默认是管道转发数据 (<-).
示例
计算三点指数移动平均
import "sampledata"
sampledata.int()
|> exponentialMovingAverage(n: 3)
计算带有空值的三点指数移动平均
import "sampledata"
sampledata.int(includeNull: true)
|> exponentialMovingAverage(n: 3)