macd_hist¶
Defined in fynance.features.indicators
- macd_hist(X, w=9, fast_w=12, slow_w=26, kind='e', axis=0, dtype=None)[source]
Compute Moving Average Convergence Divergence Histogram.
MACD is a trading indicator used in technical analysis of stock prices, created by Gerald Appel in the late 1970s [4]. It is designed to reveal changes in the strength, direction, momentum, and duration of a trend in a stock’s price.
- 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 Noneorw=0, thenw=X.shape[axis]. Default is 9.- fast_wint, optional
Size of the lagged window of the short moving average, must be strictly positive. Default is 12.
- slow_wint, optional
Size of the lagged window of the lond moving average, must be strictly positive. Default is 26.
- kind{‘e’, ‘s’, ‘w’}
If ‘e’ (default) then use exponential moving average, see
emafor details.If ‘s’ then use simple moving average, see
smafor details.If ‘w’ then use weighted moving average, see
wmafor 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]
Moving average convergence/divergence histogram of each series.
See also
z_score,bollinger_band,hma,macd_line,signal_line,cci
References
Examples
>>> X = np.array([60, 100, 80, 120, 160, 80]).astype(np.float64) >>> macd_hist(X, w=3, fast_w=2, slow_w=4) array([ 0. , 5.33333333, -0.35555556, 3.93481481, 6.4102716 , -9.47070947])