Previous topic

fynance.features.indicators.macd_hist

Next topic

fynance.features.indicators.rsi

fynance.features.indicators.macd_line

fynance.features.indicators.macd_line(X, fast_w=12, slow_w=26, kind='e', axis=0, dtype=None)

Compute Moving Average Convergence Divergence Line.

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:
X : np.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.

fast_w : int, optional

Size of the lagged window of the short moving average, must be strictly positive. Default is 12.

slow_w : int, 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 ema for details.
  • If ‘s’ then use simple moving average, see sma for details.
  • If ‘w’ then use weighted moving average, see wma for details.
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.

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

Moving average convergence/divergence line of each series.

References

[4]https://en.wikipedia.org/wiki/MACD

Examples

>>> X = np.array([60, 100, 80, 120, 160, 80]).astype(np.float64)
>>> macd_line(X, fast_w=2, slow_w=4)
array([ 0.        , 10.66666667,  4.62222222, 12.84740741, 21.7331358 ,
       -3.61855473])