roc¶
Defined in fynance.features.indicators
- roc(X, w=14, axis=0, dtype=None)[source]
Rate of Change momentum indicator.
Percentage change of the series over a lagged window
w: \(ROC^w_t = 100 \cdot (X_t / X_{t-w} - 1)\). Strictly causal — the firstwpoints use the first observation as the base (expanding).- Parameters:
- Xnp.ndarray[dtype, ndim=1 or 2]
Price/level series.
- wint, optional
Lag window. Default 14.
- axis{0, 1}, optional
Axis of computation. Default 0.
- dtypenp.dtype, optional
Output dtype.
- Returns:
- np.ndarray[dtype, ndim=1 or 2]
Rate of change in percent.
Examples
>>> X = np.array([10., 11., 12., 13., 14.]) >>> roc(X, w=2) array([ 0. , 10. , 20. , 18.18181818, 16.66666667])