Module 1 · Chapter 2 · Lesson 9

Trimmed and Winsorized Means for Outlier-Heavy Markets

5 min readTypes of Means and Averages
The Black Book of Day Trading Strategies
Free Book

The Black Book of Day Trading Strategies

1,000 complete strategies · 31 chapters · Full trade plans

Issues with Simple Averages

Mean reversion strategies use an asset's average price. A simple arithmetic mean is highly sensitive to outliers. Extreme price movements skew the average. This distortion causes incorrect entry and exit signals. For instance, a flash crash or sudden price spike can significantly alter the mean. This makes a security appear oversold or overbought when it is not. Traders need sound measures of central tendency. These measures lessen the impact of extreme data points.

Consider daily closing prices for XYZ stock over 20 trading days:

DayPrice ($)
199.50
2100.10
399.80
4100.20
5100.00
699.90
7100.30
899.70
9100.10
1099.60
11100.20
12100.00
1399.80
14100.30
1599.90
16100.10
17100.00
1899.70
19100.20
20110.00

The simple arithmetic mean for these 20 prices is $100.40. The outlier price of $110.00 on day 20 greatly inflates this average. If a mean reversion strategy uses this simple mean as its anchor, it would incorrectly signal XYZ is undervalued at $100.00. This prompts a long entry. The outlier creates a false reversion target.

Trimmed Means for Outlier Exclusion

A trimmed mean calculates the average after removing a specified percentage of data points from both ends of the sorted data. This method discards the most extreme observations. It directly addresses the outlier problem. The trimming percentage is an important parameter. A 5% trimmed mean removes the bottom 5% and the top 5% of data.

To calculate a trimmed mean:

  1. Sort the data in ascending order.
  2. Determine the number of data points to remove from each end. For a 5% trimmed mean with 20 data points, remove 1 observation from the bottom (20 * 0.05 = 1) and 1 from the top.
  3. Calculate the arithmetic mean of the remaining data.*

Let's re-evaluate XYZ stock prices using a 5% trimmed mean. Sorted prices:

Original Prices: 99.50, 100.10, 99.80, 100.20, 100.00, 99.90, 100.30, 99.70, 100.10, 99.60, 100.20, 100.00, 99.80, 100.30, 99.90, 100.10, 100.00, 99.70, 100.20, 110.00

Sorted Prices: 99.50, 99.60, 99.70, 99.70, 99.80, 99.80, 99.90, 99.90, 100.00, 100.00, 100.00, 100.10, 100.10, 100.10, 100.20, 100.20, 100.20, 100.30, 100.30, 110.00

For a 5% trimmed mean with 20 data points, we remove 1 value from the bottom (99.50) and 1 value from the top (110.00). The remaining 18 values are: 99.60, 99.70, 99.70, 99.80, 99.80, 99.90, 99.90, 100.00, 100.00, 100.00, 100.10, 100.10, 100.10, 100.20, 100.20, 100.20, 100.30, 100.30

Sum of remaining values: 1801.90 Trimmed Mean: 1801.90 / 18 = 100.105

The trimmed mean of $100.105 represents the data's central tendency more accurately. It remains unaffected by the $110.00 outlier. This offers a more dependable anchor for mean reversion.

Winsorized Means for Outlier Capping

A Winsorized mean also addresses outliers, but differently. Instead of removing extreme values, it replaces them. The lowest values below a certain percentile are replaced by the value at that percentile. Similarly, the highest values above a certain percentile are replaced by the value at that percentile. This method includes all data points in the calculation. It reduces outlier influence without discarding information.

To calculate a Winsorized mean:

  1. Sort the data in ascending order.
  2. Determine the number of data points to Winsorize from each end. For a 5% Winsorized mean with 20 data points, the 1st value is replaced by the 2nd value, and the 20th value is replaced by the 19th value.
  3. Calculate the arithmetic mean of the modified data set.

Using the same sorted XYZ stock prices: 99.50, 99.60, 99.70, 99.70, 99.80, 99.80, 99.90, 99.90, 100.00, 100.00, 100.00, 100.10, 100.10, 100.10, 100.20, 100.20, 100.20, 100.30, 100.30, 110.00

For a 5% Winsorized mean, the lowest value (99.50) is replaced by the value at the 5th percentile. With 20 data points, the 5th percentile corresponds to the 1st value. The 1st value is replaced by the 2nd value (99.60). The highest value (110.00) is replaced by the value at the 95th percentile. The 20th value is replaced by the 19th value (100.30).

Modified data set: 99.60, 99.60, 99.70, 99.70, 99.80, 99.80, 99.90, 99.90, 100.00, 100.00, 100.00, 100.10, 100.10, 100.10, 100.20, 100.20, 100.20, 100.30, 100.30, 100.30

Sum of modified values: 2002.40 Winsorized Mean: 2002.40 / 20 = 100.12

The Winsorized mean of $100.12 also withstands the outlier. It offers a slightly different view than the trimmed mean. The choice between trimmed and Winsorized means depends on the strategy and market. Trimmed means discard information. Winsorized means retain it, but alter its size.

Using Robust Averages in Trading Strategies

Implementing trimmed or Winsorized means makes mean reversion strategies more solid. These robust averages replace simple moving averages (SMAs) or exponential moving averages (EMAs) in indicator calculations.

Consider a simple mean reversion strategy:

  1. Calculate a 20-period moving average of price.
  2. Go long when price falls 2 standard deviations below the average.
  3. Go short when price rises 2 standard deviations above the average.

If using an SMA, a single large price shock distorts the average. This causes false signals. By replacing the SMA with a trimmed or Winsorized mean, the strategy becomes more resilient.

Example: Using a 20-period 5% trimmed mean for AAPL daily closing prices. From January 2, 2023, to January 31, 2023, AAPL experienced a large price drop. The closing prices (simplified for illustration): 126.04, 125.07, 125.87, 126.99, 127.33, 127.84, 128.78, 129.62, 130.03, 130.22, 130.15, 129.80, 129.50, 128.90, 128.50, 128.10, 127.70, 127.30, 126.90, 120.00 (Outlier)

Simple 20-day Mean: 128.01 5% Trimmed Mean (removing 1 lowest and 1 highest): Sorted: 120.00, 125.07, 125.87, 126.04, 126.90, 126.99, 127.30, 127.33, 127.70, 127.84, 128.10, 128.50, 128.78, 128.90, 129.50, 129.62, 129.80, 130.03, 130.15, 130.22 Trimmed data: 125.07, 125.87, 126.04, 126.90, 126.99, 127.30, 127.33, 127.70, 127.84, 128.10, 128.50, 128.78, 128.90, 129.50, 129.62, 129.80, 130.03, 130.15 Sum: 2297.02 Trimmed Mean: 2297.02 / 18 = 127.61

The trimmed mean ($127.61) shows AAPL's price more accurately during this period than the simple mean ($128.01). If a mean reversion signal was triggered by price deviating from the mean, the trimmed mean would offer a more stable and reliable reference point. This prevents premature or delayed trades due to outlier distortions.

Implement these in Python or R using libraries like scipy.stats.trim_mean or psych::winsor. Traders must determine the right trimming or Winsorizing percentage. This parameter depends on asset volatility and extreme event frequency. Backtesting different percentages is necessary. Start with 1% to 10% for common financial data. Higher percentages remove more data, potentially losing information. Lower percentages offer less outlier protection.

For high-frequency trading, where microstructure noise and flash events are common, trimmed or Winsorized means prove especially useful. They filter out transient, non-fundamental price movements. This allows strategies to focus on true mean reversion. For long-term strategies, their impact might be less obvious but still helpful during market stress.

A practical implementation involves creating a custom moving average function. This function calculates the trimmed or Winsorized mean over a specified window. This function then replaces standard moving average calls in existing strategy codebases. This modular approach allows for easy testing and integration without rewriting the entire strategy.