Winsorization

June 30, 2011

Winsorization replaces extreme data values with less extreme values.

But why

Extreme values sometimes have a big effect on statistical operations.  That effect is not necessarily a good effect.  One approach to the problem is to change the statistical operation — this is the field of robust statistics.

An alternative solution is to just change the data.  You can then use whatever statistical procedure you want.

In my experience in finance only mildly robust statistics (and hence only mildly winsorized data) are called for.  There seems to be a surprising amount of information in the tails of financial returns.

Trimming

There is an alternative to winsorization, which is just throwing out the extreme values.  That is called “trimming”.  The mean function in R has a trim argument so that you can easily get trimmed means:

> mean(c(1:10, 300))[1] 32.27273
> mean(c(1:10, 300), trim=.05)[1] 32.27273
> mean(c(1:10, 300), trim=.1)[1] 6

Trimming removes a certain fraction of the data from each tail.

Winsorizing — one way

One approach to winsorization is just to copy trimming, but replace the extreme values rather than throw them out.  Here is an R function that does this:
> winsor1
function (x, fraction=.05)
{
if(length(fraction) != 1 || fraction < 0 ||
fraction > 0.5) {
stop("bad value for 'fraction'")
}
lim <- quantile(x, probs=c(fraction, 1-fraction))
x[ x < lim[1] ] <- lim[1] x[ x > lim[2] ] <- lim[2] x
}

Figures 1 and 2 show this function in action.

Figure 1: The winsor1 function with some normally distributed data.
Figure 2: The winsor1 function with some Cauchy distributed data.

Winsorizing — another way

Another approach to winsorization is to try to just move the datapoints that are likely to be troublesome.  That is, only move data that are too far from the rest.  Here is such an R function:

> winsor2
function (x, multiple=3)
{
if(length(multiple) != 1 || multiple <= 0) {
stop("bad value for 'multiple'")
}
med <- median(x)
y <- x - med
sc <- mad(y, center=0) * multiple
y[ y > sc ] <- sc
y[ y < -sc ] <- -sc
y + med
}

Figures 3 and 4 show the results of this function using the same data as in Figures 1 and 2.

Figure 3: The winsor2 function with some normally distributed data.
Figure 4: The winsor2 function with some Cauchy distributed data.

Comments

I think the second form of winsorization usually makes more sense.  In the examples the normal data are not changed at all by the second method and the Cauchy data look to be changed in a more logical way.

Production quality implementations of the R functions would probably include an na.rm argument to deal with missing values.

Subscribe to the Portfolio Probe blog by Email

Leave a Reply

  1. safa 2012-12-27 at 01:44 - Reply

    Hi Pat,
    My background is biology so could you please tell me the meaning of the “multiple” option in winsor2 function?
    Thanks
    Safa

    • Pat 2012-12-27 at 10:51 - Reply

      Safa,

      multiple is multiplying the computed value of mad (a robust estimate of the standard deviation). So when multiple is 3, we are pulling values in that are farther than 3 (estimated) standard deviations from the center.

      An improvement to the function would be to add a center argument that defaulted to the median.

      • safa 2012-12-27 at 21:18 - Reply

        thanks, i get it now

Related posts

  • March 17, 2013

    How variable are garch predictions? Previously There have been several posts on garch, in particular: A practical introduction to garch modeling The components garch model in the rugarch package [...]

  • March 14, 2013

    Highlighted LondonR is soon -- see the "Previously Announced" section. New Events Thirsty Quants 2013 March 21, London. Some thirsty quants will be going for a drink on the [...]

  • March 5, 2013

    What effect do predicted correlations have when optimizing trades? Background A concern about optimization that is not one of "The top 7 portfolio optimization problems" is that correlations spike during [...]