← All lessons

Z-scores

Measure distance from the mean in standard deviations · 8 min

FreeGoal: Measure distance from the mean in standard deviationsBefore this: A complete trend ruleFurther reading: Chan, Algorithmic Trading
A range market with its 20-day mean and ±2 standard deviations
1101231360159
  • Close
  • 20-day mean
  • ±2 σ bands

The shaded band is where price spent most of its time.

Predict first

A rule buys whenever price is 2 standard deviations below its 20-day mean and sells at the mean. On which kind of market does it make money?

A z-score measures how far a value is from its mean, in standard deviations. Computed on the last n closes, it turns "far from normal" into one number that means the same on any price scale.

z = (price − mean of last n) ÷ standard deviation of last n
buy when z ≤ −k · sell short when z ≥ +k · exit when z returns to 0

If prices were normal and steady, |z| above 2 would happen about 5% of the time. Real and simulated returns have fat tails, so big z-scores come more often, and they come in storms. A mean-reversion rule bets that the gap closes. That is true for markets with a pull back to a fair value, and false for trends, where far from the mean is where price is going.

Try it: lookback, entry level and the z-score
87951030259
  • Close
  • 20-day mean
  • ±2 σ
-3.5-0.32.90259
  • z-score
  • Entry levels

Last close 92.17, mean 94.23, z = -1.01.

Sharpe ratio1.56
Return a year16.2%
Volatility10.0%
Max drawdown-10.8%
Trades68
Winners85%

Generated markets, not real data. They show how a rule depends on the market it meets; they do not predict how real markets behave.

Worked calculation

One reversion trade in z terms

20-day mean, standard deviation
100.00, 3.00
Close
94.00
z
(94 − 100) ÷ 3 = −2.0: buy
Target: back to the mean
100 − 94 = +6.00 if the mean holds still
Stop at z = −3.5
100 − 3.5 × 3 = 89.50, a risk of 4.50
Reward-to-risk
6.00 ÷ 4.50 = 1.33
Check yourself
3 questions

You bought at z = −2.3 with an exit at the mean. Two days later z is −0.4. What does the rule do?

Mean 48.00, standard deviation 1.50, close 51.30. What is z?

A rule enters at ±2 σ. Mean 80, σ 2.5. Which close triggers a long?

Missed questions come back for review after one day, then three, then a week.

Practice

The 20-day mean is 200 and the 20-day standard deviation is 10. Price closes at 180. What is its z-score?

Hint: z = (price − mean) ÷ standard deviation.

More in Drills →

Closing round

Three years of a fresh generated market are on screen; the next two years do not exist yet. Tune the rule on what you can see, commit to two predictions, then generate the future.

0.63×0.83×1.04×0625
  • Your rule so far
Sharpe before split-1.44
Return before split-31.7%
Max drawdown before-39.8%
Dickey–Fuller t (log price)0.35

Over the next two years, after costs, this rule will…

What kind of market is this?

Generated markets, not real data. They show how a rule depends on the market it meets; they do not predict how real markets behave.

Want to feel it candle by candle? Fade the edges in the choppy-range market →