ema#
- swordfish.function.ema()#
Calculate the Exponential Moving Average (ema) for X in a count-based sliding window of the given length.
The calculation formula is as follows:
warmup=false:
\(EMA(X)_k = \displaystyle{\frac{2}{n+1}}*X_k + \Bigl(1-\displaystyle{\frac{2}{n+1}}\Bigr)*EMA(X)_{k-1}\)
warmup=true:
\(EMA_k=\begin{cases}X_0,\quad\text{k=0}\\\frac{2}{size(X)+1}*X_k+(1-\frac{2}{size(X)+1})*EMA_{k-1}, \quad\text{size(X)<n}\\\frac{2}{n+1}*X_k+(1-\frac{2}{n+1})*EMA_{k-1}, \quad size(X)\geq n\end{cases}\)
where \(EMA_k\) is the k-th exponential moving average, n is the length of sliding window, \(X_k\) is the k-th element of the vector X.
- Parameters:
X (Constant) – A vector/matrix/table.
window (Constant) – A positive integer indicating the size of the sliding window.
warmup (Constant) – A Boolean value. The default value is false, indicating that the first (window-1) elements windows return NULL. If set to true, elements in the first (window-1) windows are calculated based on the formula given in the details.