hma

Defined in fynance.features.indicators

hma(X, w=21, kind='w', axis=0, dtype=None)[source]

Compute the Hull Moving Average of size w for each X’ series’.

The Hull Moving Average, developed by A. Hull [3], is a financial indicator. It tries to reduce the lag in a moving average.

Parameters:
Xnp.ndarray[dtype, ndim=1 or 2]

Elements to compute the indicator. If X is a two-dimensional array, then an indicator is computed for each series along axis.

wint, optional

Size of the main lagged window of the moving average, must be positive. If w is None or w=0, then w=X.shape[axis]. Default is 21.

kind{‘e’, ‘s’, ‘w’}
  • If ‘e’ then use exponential moving average, see ema for details.

  • If ‘s’ then use simple moving average, see sma for details.

  • If ‘w’ (default) then use weighted moving average, see wma for details.

axis{0, 1}, optional

Axis along wich the computation is done. Default is 0.

dtypenp.dtype, optional

The type of the output array. If dtype is not given, infer the data type from X input.

Returns:
np.ndarray[dtype, ndim=1 or 2]

Hull moving average of each series.

See also

z_score, bollinger_band, rsi, macd_hist, cci

Notes

Let \(ma^w\) the moving average function of lagged window size w.

\[hma^w_t(X) = ma^{\sqrt{w}}_t(2 \times ma^{\frac{w}{2}}_t(X)) - ma^w_t(X))\]

References

Examples

>>> X = np.array([60, 100, 80, 120, 160, 80])
>>> hma(X, w=3, dtype=np.float64)
array([ 60.        , 113.33333333,  76.66666667, 136.66666667,
       186.66666667,  46.66666667])