gs_quant.timeseries.statistics.median¶
- median(x, w=<gs_quant.timeseries.helper.Window object>)[source]¶
Median value of series over given window
- Parameters:
x (
Series
) – series: timeseriesw (
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 median value
Usage
Computes the median value over a given window. For each window, this function will return the middle value when all elements in the window are sorted. If the number of observations in the window is even, will return the average of the middle two values. If the window size is greater than the available data, will return median of available values:
\(d = \frac{w-1}{2}\)
\(R_t = \frac{X_{\lfloor t-d \rfloor} + X_{\lceil t-d \rceil}}{2}\)
where \(w\) is the size of the rolling window. If window is not provided, computes median over the full series
Examples
Generate price series and compute median over \(22\) observations
>>> prices = generate_series(100) >>> median(prices, 22)
See also