gs_quant.timeseries.statistics.percentiles¶
- percentiles(x, y=None, w=<gs_quant.timeseries.helper.Window object>)[source]¶
Rolling percentiles over given window
- Parameters:
x (
Series
) – value seriesy (
Optional
[Series
]) – distribution seriesw (
Union
[Window
,int
,str
]) – Window or int: size of window and ramp up to use. e.g. Window(22, 10) where 22 is the window size and 10 the ramp up value. If w is a string, it should be a relative date like ‘1m’, ‘1d’, etc. Window size defaults to length of series.
- Return type:
Series
- Returns:
timeseries of percentiles
Usage
Calculate percentile rank of \(y\) in the sample distribution of \(x\) over a rolling window of length \(w\):
\(R_t = \frac{\sum_{i=t-N+1}^{t}{[X_i<{Y_t}]}+0.5\sum_{i=t-N+1}^{t}{[X_i={Y_t}]}}{N}\times100\%\)
Where \(N\) is the number of observations in a rolling window. If \(y\) is not provided (or is NULL), calculates percentiles of \(x\) over its historical values. If window length \(w\) is not provided, uses an ever-growing history of values. If \(w\) is greater than the available data size, returns empty.
Examples
Compute percentile ranks of a series in the sample distribution of a second series over \(22\) observations
>>> a = generate_series(100) >>> b = generate_series(100) >>> percentiles(a, b, 22)
See also