gs_quant.timeseries.statistics.winsorize¶
- winsorize(x, limit=2.5, w=<gs_quant.timeseries.helper.Window object>)[source]¶
Limit extreme values in series
- Parameters:
x (
Series
) – time series of priceslimit (
float
) – max z-score of valuesw (
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 winsorized values
Usage
Cap and floor values in the series which have a z-score greater or less than provided value. This function will restrict the distribution of values. Calculates the sample standard deviation and adjusts values which fall outside the specified range to be equal to the upper or lower limits
Lower and upper limits are defined as:
\(upper = \mu + \sigma \times limit\)
\(lower = \mu - \sigma \times limit\)
Where \(\mu\) and \(\sigma\) are sample mean and standard deviation. The series is restricted by:
\(R_t = max( min( X_t, upper), lower )\)
See winsorising for additional information
Examples
Generate price series and winsorize z-score of returns over \(22\) observations
>>> prices = generate_series(100) >>> winsorize(zscore(returns(prices), 22))
See also