Module 1 · Chapter 3 · Lesson 7

Interquartile Range (IQR) for Robust Deviation Measurement

5 min readMeasuring Deviation from the Mean
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

Interquartile Range (IQR) for Robust Deviation Measurement

The Interquartile Range (IQR) measures statistical dispersion. It quantifies the spread of the middle 50% of data points. IQR offers a robust alternative to standard deviation. Standard deviation is sensitive to outliers. IQR is not. This makes IQR valuable for identifying mean reversion signals in volatile markets.

Calculate IQR using quartiles. The first quartile (Q1) represents the 25th percentile. The third quartile (Q3) represents the 75th percentile. IQR equals Q3 minus Q1.

$IQR = Q3 - Q1$

The median is the 50th percentile. It sits between Q1 and Q3.

Identifying Outliers with IQR

IQR defines boundaries for outlier detection. A data point is an outlier if it falls below $Q1 - 1.5 \times IQR$ or above $Q3 + 1.5 \times IQR$. These thresholds are the "fences."

Consider daily returns for a stock, XYZ, over 20 trading days.

DayReturn (%)
10.5
2-0.2
31.1
40.3
50.8
6-0.1
70.6
80.4
91.5
100.2
11-0.3
120.7
130.9
140.1
151.2
160.0
170.5
18-0.4
190.6
205.0

First, sort the returns:

RankReturn (%)
1-0.4
2-0.3
3-0.2
4-0.1
50.0
60.1
70.2
80.3
90.4
100.5
110.5
120.6
130.6
140.7
150.8
160.9
171.1
181.2
191.5
205.0

With 20 data points, Q1 is the average of the 5th and 6th values (25th percentile). Q3 is the average of the 15th and 16th values (75th percentile).

Q1 calculation: The 25th percentile position is $(20 + 1) \times 0.25 = 5.25$. Q1 is $0.75 \times \text{value at rank 5} + 0.25 \times \text{value at rank 6}$. $Q1 = 0.75 \times 0.0 + 0.25 \times 0.1 = 0.025$.

Q3 calculation: The 75th percentile position is $(20 + 1) \times 0.75 = 15.75$. Q3 is $0.25 \times \text{value at rank 15} + 0.75 \times \text{value at rank 16}$. $Q3 = 0.25 \times 0.8 + 0.75 \times 0.9 = 0.2 + 0.675 = 0.875$.

$IQR = Q3 - Q1 = 0.875 - 0.025 = 0.85$.

Now, calculate the outlier fences: Lower fence: $Q1 - 1.5 \times IQR = 0.025 - 1.5 \times 0.85 = 0.025 - 1.275 = -1.25$. Upper fence: $Q3 + 1.5 \times IQR = 0.875 + 1.5 \times 0.85 = 0.875 + 1.275 = 2.15$.

Any return below -1.25% or above 2.15% is an outlier. The 5.0% return on Day 20 is an outlier. This large positive return significantly skews standard deviation. IQR-based analysis identifies it as an extreme event.

IQR in Mean Reversion Strategy Development

Mean reversion strategies profit from temporary deviations from an asset's average price. The challenge is distinguishing significant deviations from random noise. IQR helps.

Instead of using standard deviations from a moving average, use multiples of IQR. This creates dynamic bands. These bands adjust to market volatility without being distorted by extreme price spikes.

Consider a mean reversion strategy on the S&P 500 ETF (SPY).

  1. Calculate a 20-period simple moving average (SMA) of SPY's closing price. This is the "mean."
  2. Calculate the 20-period IQR of the price differences from the SMA.
    • For each day, calculate $P_t - SMA_t$.
    • Compute Q1 and Q3 of these differences over the 20-period window.
    • Calculate $IQR = Q3 - Q1$.
  3. Define entry and exit thresholds using IQR multiples.
    • Sell Signal (Overbought): $P_t > SMA_t + K \times IQR$
    • Buy Signal (Oversold): $P_t < SMA_t - K \times IQR$

Here, $K$ is a multiplier, often between 1.0 and 2.0. A common choice is $1.5 \times IQR$, aligning with outlier detection.

Example: SPY Trading Strategy (Hypothetical, 20-day window)

Assume on March 15, 2024:

  • SPY closing price ($P_t$): $510.00
  • 20-day SMA ($SMA_t$): $505.00
  • Recent 20-day price differences from SMA:
    • Sorted: [-4.50, -3.20, -2.80, -2.00, -1.50, -1.00, -0.80, -0.50, -0.20, 0.10, 0.30, 0.60, 0.90, 1.20, 1.80, 2.30, 2.90, 3.50, 4.00, 15.00 (outlier)]

Calculate Q1 and Q3 for these differences (similar method as before):

  • Q1 (25th percentile) of differences: -1.50
  • Q3 (75th percentile) of differences: 2.90
  • $IQR = Q3 - Q1 = 2.90 - (-1.50) = 4.40$.

Using a multiplier $K=1.5$:

  • Upper band: $SMA_t + 1.5 \times IQR = 505.00 + 1.5 \times 4.40 = 505.00 + 6.60 = 511.60$.
  • Lower band: $SMA_t - 1.5 \times IQR = 505.00 - 1.5 \times 4.40 = 505.00 - 6.60 = 498.40$.

On March 15, 2024, SPY is at $510.00. This is below the upper band of $511.60. No sell signal. If SPY had closed at $512.00, it would exceed the upper band. This triggers a short entry signal. The strategy expects a reversion towards the mean ($505.00).

The advantage here is the IQR's resilience to the outlier difference of 15.00. If we had used standard deviation, that outlier would have inflated the standard deviation. This would widen the bands, making signals less frequent and potentially less effective.

Practical Implementation Notes

  1. Lookback Period: The choice of the lookback period (e.g., 20 days) significantly impacts strategy sensitivity. Shorter periods react faster to recent volatility. Longer periods provide smoother, less frequent signals. Backtest different periods (e.g., 10, 20, 30, 60 days).
  2. Multiplier (K): Adjust the multiplier $K$ based on desired signal frequency and risk tolerance. A smaller $K$ generates more signals but increases false positives. A larger $K$ generates fewer signals but targets stronger deviations.
  3. Asset Selection: IQR-based mean reversion works best on assets exhibiting clear mean-reverting tendencies. These include highly liquid ETFs, major index futures, and pairs of co-integrated stocks. Avoid highly trending or thinly traded assets.
  4. Transaction Costs: Account for transaction costs. Fewer, higher-conviction trades generated by wider IQR bands might be more profitable than frequent trades from tighter bands.
  5. Dynamic K: Consider a dynamic multiplier $K$. Adjust $K$ based on overall market volatility or specific asset characteristics. For example, increase $K$ during high volatility to avoid premature entries.
  6. Exit Conditions: Define clear exit conditions. These could be:
    • Price crossing back inside the IQR bands.
    • Price reaching the SMA.
    • A fixed profit target or stop-loss.

IQR provides a robust measure of deviation. It improves mean reversion strategy performance by filtering out noise from extreme price movements. Incorporate it into your quantitative trading framework.