roll_rank¶
Defined in fynance.features.scale
- roll_rank(X, w=None, axis=0)[source]
Rolling percentile rank of each observation within its past window.
For each
treturns the fraction of the strictly-past window[t-w+1, t]that is belowX_t, in[0, 1](0 = lowest, 1 = highest). Robust to outliers and strictly causal — useful as a feature normalisation that ignores the scale/distribution of the raw series.- Parameters:
- Xnp.ndarray[dtype, ndim=1 or 2]
Data to rank.
- wint, optional
Size of the lagged window. If
Noneor0,w = X.shape[axis]. Default None.- axisint, optional
Axis along which to compute the rank. Default 0.
- Returns:
- np.ndarray[dtype, ndim=1 or 2]
Rolling percentile ranks in
[0, 1](0.5 for a single observation).
See also
roll_normalize,roll_standardize
Examples
>>> X = np.array([1., 3., 2., 5., 4.]) >>> roll_rank(X, w=3) array([0.5, 1. , 0.5, 1. , 0.5])