Previous topic


Next topic



fynance.features.indicators.rsi(X, w=14, kind='e', axis=0, dtype=None)

Compute Relative Strenght Index.

The relative strength index, developed by J. Welles Wilder in 1978 [5], is a technical indicator used in the analysis of financial markets. It is intended to chart the current and historical strength or weakness of a stock or market based on the closing prices of a recent trading period.

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.

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 14.

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.

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

Relative strength index for each period.


It is the average gain of upward periods (noted \(ma^w_t(X^+)\)) divided by the average loss of downward (noted \(ma^w_t(X^-)\)) periods during the specified time frame w, such that :

\[RSI^w_t(X) = 100 - \frac{100}{1 + \frac{ma^w_t(X^+)}{ma^w_t(X^-)}}\]




>>> X = np.array([60, 100, 80, 120, 160, 80]).astype(np.float64)
>>> rsi(X, w=3)
array([ 0.        , 99.99999804, 69.59769254, 85.55610891, 91.72201613,