WARNING
This module is still under development
If you are familiar with python programming maybe you could check stockpandas which provides powerful statistic indicators support, and is backed by numpy
and pandas
, The performance of stockpandas is many times higher than JavaScript libraries, and can be directly used by machine learning programs.
movingaverages
The complete collection of utility methods for Moving average, including:
 simple moving average (MA)
 dynamic weighted moving average (DMA)
 exponential moving average (EMA)
 smoothed moving average (SMA)
 weighted moving average (WMA)
And movingaverages
will also handle empty values.
install
$ npm i movingaverages
usage
import { dynamicWeightedMA, smoothingMA, ExponentialMA, MA, WeightedMA } from "movingaverages";
ma([1, 2, 3, 4, 5], 2);
// [<1 empty item>, 1.5, 2.5, 3.5, 4.5]
ma(data, size)
Simple Moving Average: 
data
Array.<Number>
the collection of data inside which empty values are allowed. Empty values are useful if a stock is suspended. 
size
Number
the size of the periods.
Returns Array.<Number>  null
Special Cases
import { MA } from "movingaveragets";
// If the size is less than `1`
MA([1, 2, 3], 0.5); // [1, 2, 3]
// If the size is larger than data length
MA([1, 2, 3], 5); // [<3 empty items>]
MA([, 1, , 3, 4, 5], 2);
// [<2 empty items>, 0.5, 1.5, 3.5, 4.5]
And all of the other moving average methods have similar mechanism.
dma(data, alpha, noHead)
Dynamic Weighted Moving Average:  data

alpha
NumberArray.<Number>
the coefficient or list of coefficientsalpha
represents the degree of weighting decrease for each datum. If
alpha
is a number, then the weighting decrease for each datum is the same.  If
alpha
larger than1
is invalid, then the return value will be an empty array of the same length of the original data.  If
alpha
is an array, then it could provide different decreasing degree for each datum.
 If

noHead
Boolean=
whether we should abandon the first DMA.
Returns Array.<Number> undefined
import { dynamicWeightedMA } from "movingaveragets";
dynamicWeightedMA([1, 2, 3], 2); // [<3 empty items>]
dynamicWeightedMA([1, 2, 3], 0.5); // [1, 1.5, 2.25]
dynamicWeightedMA([1, 2, 3, 4, 5], [0.1, 0.2, 0.1]); // [1, 1.2, 1.38]
ema(data, size)
Exponential Moving Average: Calulates the most frequent used exponential average which covers about 86% of the total weight (when alpha = 2 / (N + 1)
).
 data

size
Number
the size of the periods.
Returns Array.<Numberundefined>
sma(data, size, times)
Smoothed Moving Average: Also known as the modified moving average or running moving average, with alpha = times / size
.
 data
 size

times
Number=1
Returns Array.<Numberundefined>
wma(data, size)
Weighted Moving Average: Calculates convolution of the datum points with a fixed weighting function.
Returns Array.<Numberundefined>
MIT