Pairs Trading Spread Calculator (Z-Score and Half-Life)

Measure a spread in standard deviations from its mean and estimate the half-life of reversion from a lagged-level regression.

Spread z-score 1.79 Inside the 2 sigma threshold, no signal
Half-life of reversion 3.0 periods
Spread mean 0.514
Spread standard deviation 0.193
Inputs
Try:
Amounts are treated in the selected currency; no foreign-exchange conversion is applied.
The spread between the two legs, one observation per period, separated by commas.
sigma
How many standard deviations from the mean before the spread is considered tradeable.
Results & Graph
Spread z-score
1.79
Inside the 2 sigma threshold, no signal
Half-life of reversion
3.0 periods
Spread mean
0.514
Spread standard deviation
0.193
Latest spread
0.860
Distance to the mean
0.346

Spread Against Its Mean and Entry Bands

Graph 1 • The Spread Against Its Mean and Entry Bands The shaded envelope is the entry threshold; a reading outside it is the signal.
0.1 0.5 0.9 P1P6P11P16P21P26P30
Graph 2 • Current Reading Against the Threshold A z-score inside the threshold is not a trade, however wide the spread looks.
Current z-score 1.79 Entry threshold 2.0 sigma
Graph 3 • How Long Half the Gap Takes to Close The half-life decides the holding period, and therefore whether the carry is survivable.
Half-life, periods 3.0 periods Observations supplied 30
Summary: Mean 0.514 with 2 sigma bands at 0.901 and 0.127; the latest reading is 0.860.
Summary: The spread sits 1.79 standard deviations above its mean. The lagged-level regression gives a half-life of 3.0 periods, so half the gap would be expected to close in that time if the relationship holds.
Interactive chart & math engine powered by CalculatorGraph

Formula: Z-Score and Ornstein-Uhlenbeck Half-Life

z = (St - mean(S)) / sd(S)
regress dS on Slagged to get slope L
half-life = ln(2) / |L| when L < 0
z = (S_t - mean(S)) / sd(S) ; regress dS on S_lagged to get slope L ; half-life = ln(2) / |L| when L < 0
  • St: The latest spread observation
  • L: Slope from regressing the change in the spread on its lagged level; negative means reversion
  • half-life: Periods for half the deviation from the mean to close, if the relationship holds

Rounding: Z-scores to two decimal places; half-life to one.

Worked example: Example: 30 spread observations with a 2 sigma entry

A spread that has drifted to the top of its range.

  1. Compute the mean and standard deviation of the whole series.
  2. The z-score is the latest observation expressed in standard deviations from that mean.
  3. Regress each period change in the spread on the previous level; a negative slope means the spread pulls back toward its mean.
  4. Half-life is ln(2) divided by the magnitude of that slope.
Result: The spread sits 1.79 standard deviations above its mean, inside the 2 sigma threshold so there is no signal yet, with a half-life of 3.0 periods.

Frequently Asked Questions

Why does the half-life matter more than the z-score?

The z-score tells you the spread is stretched; the half-life tells you whether you can afford to wait. A 3 sigma spread with a 5-day half-life is a trade. The same 3 sigma spread with a 90-day half-life means three months of borrow cost, financing and mark-to-market pain before the thesis has a chance to work, and most books cannot hold that. Size and holding period come from the half-life, not the z-score.

What if the regression slope is positive?

Then the series is not mean reverting over your sample and the calculator says so instead of reporting a half-life. A positive slope means deviations tend to grow rather than close, which is a trending spread. Trading it as a pair means adding to a position that is working against you, which is how statistical arbitrage desks lose money on pairs that used to work.

Does a high z-score mean the pair is cointegrated?

No, and conflating the two is the standard error. A z-score only says the current reading is far from its own historical mean, which any series can produce including a random walk. Cointegration is a separate statistical test that asks whether the two legs share a long-run relationship at all. Run that test first; the z-score is only meaningful once it passes.

How many observations should I use?

Enough to cover more than a few half-lives, which is why the two numbers are related. If the half-life is 3 periods, 30 observations covers ten of them and the estimate is reasonable. If the half-life comes back near 50 on a 60-period series, the regression has barely seen one cycle and the number is close to meaningless.

Why does my spreadsheet give a slightly different z-score?

Check which standard deviation it uses. This calculator divides by n minus 1, the sample formula. A spreadsheet using the population version would show about 1.82 for the default series instead of 1.79. Also check that your spreadsheet includes the latest reading in the mean and standard deviation, since this calculator does.

Why is my half-life different from one computed in another tool?

There are two common formulas. This calculator uses ln(2) divided by the absolute regression slope, which gives 3.0 periods for the default data. The discrete version, minus ln(2) divided by ln(1 plus slope), gives about 2.6 on the same slope. Both are reasonable approximations, and the gap widens as the slope gets steeper.

What does a negative z-score mean?

The latest spread is below its mean. Replacing the last default reading with 0.30 gives a z-score of -1.05 and a gap to the mean of -0.195. The threshold test uses the absolute value, so a reading far enough below the mean is flagged the same way as one far above it.

Does changing the entry threshold change the half-life?

No. The threshold only decides the wording under the z-score and the bands on the chart. In the presets, 1.2, 2 and 3 sigma all return a z-score of 1.79 and a half-life of 3.0 periods. Only the label switches between beyond the threshold and no signal.

Can I paste prices instead of a spread?

You can paste any series, but the result only makes sense if the series is the spread you intend to trade. Pasting one stock's price will give a z-score and maybe a half-life, yet that says nothing about a pair. Build the spread first, using a ratio or a hedge-ratio-weighted difference.

What happens if I paste fewer than 20 readings?

The calculator stops and asks for at least 20 spread observations. With fewer points the mean, the standard deviation and especially the regression slope are too unstable to report. Even at 20, treat the half-life as rough, and compare it with the length of your sample.

Why did the half-life change when I added just one number?

The regression uses every consecutive pair in the list, and a single extreme last value has a real pull on a small sample. Changing the final default reading from 0.86 to 0.98 moves the half-life from 3.0 to 3.9 periods. That sensitivity is a reason to treat the half-life as an estimate with wide error bars.

Is this calculator telling me to enter a trade?

No. It reports where the spread sits relative to its own history and how quickly past gaps closed. It does not test whether the pair is cointegrated, model costs or borrow, or size a position. Use it as one input, and speak to a qualified adviser before risking money on any strategy.

Which order should the observations be in?

Oldest first, newest last. The calculator treats the final number as the current spread and fits the regression forward in time. If you paste a column sorted newest first, the z-score will describe the oldest reading and the half-life will be computed on a reversed series.

What unit is the half-life in?

Periods, meaning whatever spacing your observations have. With daily closes, 3.0 periods is three trading days; with weekly data it is three weeks. The calculator has no time stamps, so it cannot know. Label the result with your data frequency when you write it down.

Why did my z-score go up but the half-life get much longer?

Usually because the latest readings are trending away from the mean rather than wobbling around it. Appending five steadily rising readings to the default series pushes the z-score to 2.35 and the half-life from 3.0 to 17.8 periods. A stretched spread that is reverting more slowly is a warning sign, not a better entry.

Does the calculator remove outliers or bad ticks?

No. Every number that parses is used as given. A single bad print, such as a stale price on one leg, can produce a large z-score and distort the regression slope. Clean the data before pasting it, and check any reading that looks far out of line with its neighbours.

What the sample series says: z of 1.79 and a 3.0 period half-life

The default input is 30 spread readings that start at 0.42, wander between 0.18 and 0.91, and end at 0.86. The entry threshold is 2 sigma. Nothing about the series is special; it exists so you can see every number the calculator produces and check them.

The mean of all 30 readings is 0.514 and the sample standard deviation is 0.193. The latest reading, 0.860, sits 0.346 above the mean. Divide 0.346 by 0.193 and you get 1.79, the z-score at the top of the result. Because 1.79 is below 2, the label reads inside the 2 sigma threshold, no signal.

The second figure is the half-life of 3.0 periods. It comes from a separate regression on the same data and answers a different question: not how stretched the spread is, but how fast past stretches have closed. A half-life of 3 on a 30 point series means the sample contains roughly ten half-lives, which is enough for the estimate to mean something.

This page is a measuring tool, not a recommendation. It tells you where a spread sits relative to its own history. It does not tell you that a trade will work, and nothing here is investment advice.

How the z-score is built, and why the window is the whole list

The z-score is (latest spread minus mean) divided by standard deviation. Both the mean and the standard deviation are taken over every observation you paste in, including the latest one. The standard deviation uses the sample formula, dividing by n minus 1. With the population formula, dividing by n, the same series would give about 1.82 instead of 1.79, so small differences against a spreadsheet are usually this.

Using the whole list as the window has consequences. Add one more reading and every statistic moves. Dropping the first two readings (0.42 and 0.55) and keeping the rest changes the mean to 0.516, the standard deviation to 0.199 and the z-score to 1.72, even though the latest value is unchanged.

That sensitivity is the point to absorb. A z-score is relative to the sample, so choose the length deliberately. Many desks use a rolling window of fixed length, and you can mimic that by always pasting the same number of most recent readings. The calculator requires at least 20 observations and will refuse a shorter list.

Including the latest value in its own mean also pulls the mean slightly toward it, which makes extreme readings look a touch less extreme than a model using only prior data would show.

The regression behind the half-life

For the half-life, the calculator takes each change in the spread (this period minus last period) and regresses it on the previous level. With 30 readings there are 29 such pairs. If high levels tend to be followed by falls and low levels by rises, the slope comes out negative, which is what mean reversion looks like in data.

On the default series the slope is about -0.231. The engine then reports ln(2) divided by the size of that slope: 0.693 divided by 0.231 is about 3.0 periods. That is the continuous time Ornstein-Uhlenbeck reading of the slope.

There is a discrete alternative you will see in some textbooks, -ln(2) divided by ln(1 + slope). On the same slope it gives about 2.6 periods. Neither is wrong; they agree closely when the slope is small and drift apart as it gets larger. If you are comparing with someone else's half-life, ask which version they used before debating the gap.

A period is whatever spacing your data has. Daily closes give a half-life in trading days; hourly bars give hours. The calculator has no idea which, so label it yourself.

How the entry threshold changes the label but not the maths

The entry threshold only affects the label under the z-score and the bands drawn on the chart. It does not change the mean, the standard deviation, the z-score or the half-life.

The presets show this. At 1.2 sigma the same 1.79 reads as beyond the 1.2 sigma entry threshold. At 2 sigma and 3 sigma it reads as inside the threshold, no signal. The half-life stays at 3.0 periods throughout.

The chart bands sit at the mean plus and minus the threshold times the standard deviation. At 2 sigma the upper band is about 0.901 and the lower band about 0.127. The latest reading of 0.86 is just under the upper band, which is why the label says no signal.

The threshold must be above 0 and no more than 5, otherwise the calculator stops with an error. The comparison uses the absolute z, so a reading far below the mean triggers the label in the same way as one far above it.

Testing a new reading before you paste the full history

A quick way to use the page is to keep the history fixed and change only the last value to see where a plausible next print would land.

Replace the final 0.86 with 0.98 and the z-score rises to 2.29, now beyond the 2 sigma threshold. Notice that the mean and standard deviation also rise, to 0.518 and 0.202, because the new reading is part of the sample. The half-life lengthens to 3.9 periods, since a reading that far out makes the series look a little less eager to revert.

Replace it with 0.30 instead and the z-score becomes -1.05, the gap to the mean is -0.195, and the half-life drops to 1.5 periods. A big swing back toward the middle in the last step is exactly what a reverting series looks like, so the regression rewards it.

This is useful for setting alerts. Rather than watching the z-score live, you can find roughly what spread level would cross your threshold and set the alert on the spread itself.

When the slope is zero or positive

If the regression slope is not negative, the calculator shows not reverting in place of a number, and the interpretation says that a wide spread without reversion is a trend, not a trade.

An extreme test makes the point. Paste the numbers 1 to 21 in order. Each change is exactly 1, whatever the level, so the slope is zero. The z-score still comes out at 1.61 because the last value is above the average, but there is no half-life at all.

That example is worth remembering because it shows the z-score alone can look interesting on a series that has nothing to do with reversion. Read the two numbers together. A healthy looking z with a missing or very long half-life is a warning, not an opportunity.

A very steep negative slope can also mislead. A slope near -1 says the whole gap closes in a single period, and a slope below -1 says the spread overshoots its mean every period. Both usually point to noisy or badly aligned data rather than fast, tradeable reversion.

What goes into the spread field

The calculator takes the spread as already built. You decide whether it is a price ratio, a log ratio, or one leg minus a hedge ratio times the other. That choice usually matters more than anything on this page, because a poorly chosen hedge ratio leaves a trend inside the spread and the regression will pick it up.

Numbers can be separated by commas, spaces or semicolons. Anything that does not parse as a number is silently dropped, so a stray text label in a pasted column will not cause an error but will shorten your series. Count your observations if the result looks off.

Keep the data in time order with the oldest first. The latest spread is taken as the last number in the list. Paste a column sorted newest first and the calculator will measure the oldest reading against the mean and fit the regression backwards.

The display currency setting does not enter any of the calculations. Spreads are often unitless, and the outputs are reported as plain numbers.

How a regime break shows up in both numbers

The assumptions on this page warn that a regime change contaminates the mean and standard deviation. It is worth seeing what that looks like.

Take the default 30 readings and append five more that climb steadily: 0.95, 1.02, 1.10, 1.18 and 1.25. The z-score rises to 2.35, now beyond the 2 sigma threshold, and the mean drifts up to 0.598. On the z-score alone the spread looks like a stronger entry than before.

The half-life tells a different story. It jumps from 3.0 periods to 17.8 periods. Five readings that keep moving in the same direction have made the series look far less eager to revert, and the regression has noticed even though most of the history is unchanged.

That pattern, a rising z-score with a lengthening half-life, is the one to watch for. It is what you would expect to see if the relationship between the two legs were starting to break. The calculator cannot tell you that it has broken, but running it on the newest data alongside a longer history makes the change visible before you commit to anything.