#### Previous topic

fynance.features.momentums.ema

#### Next topic

fynance.features.momentums.wma

# fynance.features.momentums.sma¶

fynance.features.momentums.sma(X, w=None, axis=0, dtype=None)

Compute simple moving average(s) of size w for each X’ series.

$sma^w_t(X) = \frac{1}{w} \sum^{w-1}_{i=0} X_{t-i}$
Parameters: X : np.ndarray[dtype, ndim=1 or 2] Elements to compute the moving average. w : int, optional Size of the lagged window of the moving average, must be positive. If w is None or w=0, then w=X.shape[axis]. Default is None. axis : {0, 1}, optional Axis along wich the computation is done. Default is 0. dtype : np.dtype, optional The type of the output array. If dtype is not given, infer the data type from X input. np.ndarray[dtype, ndim=1 or 2] Simple moving average of each series.

Examples

>>> X = np.array([60, 100, 80, 120, 160, 80])
>>> sma(X, w=3, dtype=np.float64, axis=0)
array([ 60.,  80.,  80., 100., 120., 120.])
>>> X = np.array([[60, 60], [100, 100], [80, 80],
...               [120, 120], [160, 160], [80, 80]])
>>> sma(X, w=3, dtype=np.float64, axis=0)
array([[ 60.,  60.],
[ 80.,  80.],
[ 80.,  80.],
[100., 100.],
[120., 120.],
[120., 120.]])
>>> sma(X, w=3, dtype=np.float64, axis=1)
array([[ 60.,  60.],
[100., 100.],
[ 80.,  80.],
[120., 120.],
[160., 160.],
[ 80.,  80.]])