fynance.features.indicators.rsi¶
-
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.
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.
- w : int, optional
Size of the lagged window of the moving average, must be positive. If
w is None
orw=0
, thenw=X.shape[axis]
. Default is 14.- kind : {‘e’, ‘s’, ‘w’}
- 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]
Relative strength index for each period.
See also
Notes
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^-)}}\]References
[5] https://en.wikipedia.org/wiki/Relative_strength_index Examples
>>> 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, 30.00294321])