How to Calculate Z-Score for Pairs Trading

Quick Answer

Z-score measures how far the current price relationship between two stocks deviates from its historical average. Calculate it using: Z = (Current Ratio - Mean Ratio) / Standard Deviation. A z-score of +2 means the ratio is 2 standard deviations above its mean, signaling a potential sell opportunity. A z-score of -2 indicates a potential buy opportunity.

What is Z-Score in Pairs Trading?

In pairs trading, the z-score is your primary trading signal. It tells you when two stocks have diverged far enough from their typical relationship to create a profitable trading opportunity.

Think of z-score as a "distance meter" that measures how unusual the current price relationship is:

  • Z-score = 0: Prices are at their normal relationship (no trading signal)
  • Z-score = +2: Stock A is expensive relative to Stock B (sell A, buy B)
  • Z-score = -2: Stock A is cheap relative to Stock B (buy A, sell B)
  • Z-score = ±3 or more: Extreme deviation (strong signal, but rare)

The Z-Score Formula

Z = (Rcurrent - μR) / σR

Rcurrent

Current price ratio = PriceA / PriceB

μR

Mean (average) of historical ratios

σR

Standard deviation of historical ratios

💡 Important: PairParade uses a 90-day lookback period (3 months) for calculating the mean and standard deviation. This balances responsiveness with statistical reliability.

Step-by-Step Calculation

1

Calculate the Price Ratio

Divide Stock A's current price by Stock B's current price.

Rcurrent = PriceA / PriceB

Example:

• JPM (Stock A) current price: $150.00
• BAC (Stock B) current price: $35.00
• Current ratio = $150.00 / $35.00 = 4.286

2

Calculate Historical Mean Ratio

Collect daily price ratios for the past 90 trading days and calculate their average.

μR = (R₁ + R₂ + ... + R₉₀) / 90

Example:

Historical ratios over 90 days: 4.20, 4.25, 4.18, 4.22, ...
Mean ratio = 4.200 (average of all 90 ratios)

3

Calculate Standard Deviation

Measure how much the ratios typically vary from their mean.

σR = √[Σ(Ri - μR)² / n]

Example:

1. Find each ratio's deviation from mean: (4.20 - 4.200)², (4.25 - 4.200)², ...
2. Average these squared deviations
3. Take square root = 0.120

4

Calculate Z-Score

Now plug everything into the z-score formula.

Z = (4.286 - 4.200) / 0.120

Z = 0.717

Interpretation:

A z-score of +0.717 means JPM is currently 0.717 standard deviations more expensive relative to BAC than usual. This is a mild deviation—not extreme enough to trade yet (typically wait for ±2).

Visualizing Price Ratios Over Time

This chart shows how the price ratio between two stocks fluctuates around its mean:

Z-Score Chart

This is how z-scores are typically displayed. Entry signals occur at ±2, exits at 0:

🟢 Buy Signal (Z < -2)

Stock A is undervalued relative to Stock B
Action: Buy A, Sell B

🔴 Sell Signal (Z > +2)

Stock A is overvalued relative to Stock B
Action: Sell A, Buy B

How to Interpret Z-Scores

Z-Score RangeMeaningTrading Action
Z < -3Extreme undervaluationStrong Buy: Buy A, Sell B
-3 < Z < -2Significant undervaluationBuy Signal: Buy A, Sell B
-2 < Z < -1Moderate undervaluationWait or reduce position size
-1 < Z < +1Normal rangeNo Trade: Close to mean
+1 < Z < +2Moderate overvaluationWait or reduce position size
+2 < Z < +3Significant overvaluationSell Signal: Sell A, Buy B
Z > +3Extreme overvaluationStrong Sell: Sell A, Buy B

Choosing a Lookback Period

The lookback period (window size) affects how sensitive your z-score is to recent changes:

30 Days (Short)

Pros: More responsive, catches recent shifts
Cons: Noisier signals, more false positives

Good for: High-frequency trading, volatile pairs

90 Days (Medium) ⭐

Pros: Balanced, statistically robust
Cons: May lag sudden market changes

PairParade uses this. Good for: Most pairs traders

252 Days (Long)

Pros: Stable, fewer signals
Cons: Slow to adapt, misses short-term opportunities

Good for: Long-term position traders

Common Z-Score Mistakes

❌ Using too short a lookback period

Less than 30 days creates unstable statistics with false signals. Minimum 30 days, ideally 60-90.

❌ Trading on z-scores without cointegration

Z-score only works if the pair is actually cointegrated. Always run the Engle-Granger test first.

❌ Entering trades at Z = ±1

Wait for ±2 standard deviations. Z = ±1 is too close to the mean and leads to low profitability.

❌ Forgetting to update daily

Z-scores change every day with new prices. Calculate fresh each trading day for accurate signals.

❌ Using raw prices instead of ratios

Always use the price ratio (A/B), not individual stock prices. The ratio captures the relationship.

Get Real-Time Z-Scores with Pair Parade

Calculating z-scores manually requires downloading price data, writing code, and updating calculations daily. PairParade does all of this automatically, giving you live z-scores for thousands of pairs updated throughout the trading day.

✓ Live Z-Score Charts

Updated every trading hour

✓ Automatic Alerts

Get notified when Z crosses ±2

✓ Historical Analysis

See past z-score patterns

Frequently Asked Questions

What's the difference between z-score and correlation?

Correlation measures if two stocks move together (directionality). Z-score measures how far the current price relationship has deviated from normal (opportunity). You need high correlation for a pair to work, but z-score tells you when to trade it.

Can z-score stay extreme for long periods?

Yes, especially if the cointegration relationship has broken down. This is why you should use stop losses and periodically re-test pairs for cointegration. If z-score stays at ±3 for weeks, the relationship may have permanently changed.

Should I use ±1.5 or ±2 as my entry threshold?

±2 is standard and provides better risk/reward. ±1.5 gives more trading opportunities but lower expected profit per trade. Conservative traders use ±2.5. Test with historical data to see what works for your pairs.

Do I exit at z-score = 0?

Yes, that's the most common exit strategy. When z-score returns to 0, the price relationship has reverted to its mean. Some traders use ±0.5 for earlier exits with more certainty.

How often should I recalculate z-score?

At minimum, once per day after market close. Active traders recalculate intraday (hourly or more frequently) for responsive signals. PairParade updates z-scores every hour during market hours.

Continue Learning