2012issue C0478-81
Construct a pairs-trading worksheet from residuals and quantile ranks
A pairs-trading worksheet is specified as one procedure: fit linear-regression baselines on each leg, convert residuals and the spread-ratio into quantile ranks, and hold a mid-rank spread-signal-line as the abstention threshold.
- A sequential index column is required before intercept and slope can be estimated, and those coefficients are fit once on the full lookback, separately for returns and for cumulative returns.
- Each residual is the observed value minus the fitted intercept-and-slope line, and regression and residual formulas must cover the full-sample-range.
- Quantile-analysis ranks each observation as the share of the sample that is less than or equal to it, and the same transform is applied to returns, residuals, and the spread-ratio.
- The spread-signal-line is a constant 0.5 copied through the sample. Chart construction and extra checks for whether a pair is tradable are deferred.
One worksheet, one procedure
Pairs-trading is a two-leg procedure that turns a constructed spread into entry, exit, and no-trade rules. The archive workflow builds that spread by fitting a linear-regression baseline on each leg, isolating residuals, ranking the series, and holding a constant mid-rank line as the decision threshold.
Editorial note: TradersWeek reads these steps as one testable procedure so entry, exit, and abstention can be specified together. That reading is editorial and is not attributed to the archive.
Index the lookback before you fit
A sequential index column is required before intercept and slope can be estimated for the residual calculations. Intercept and slope are estimated once on the full lookback, separately for returns and for cumulative returns.
Linear-regression is used here as a fitted intercept-and-slope baseline that isolates residuals from returns and from cumulative returns.
Isolate residuals on the full-sample-range
Each residual is the observed series value minus the fitted intercept-plus-slope line at that observation. Residuals are computed separately for returns and for cumulative returns.
Regression and residual formulas must span the entire entered data range or the worksheet does not function as specified. The full-sample-range is the complete lookback window that intercept, slope, residual, and rank formulas must cover together.
Rank returns, residuals, and the spread-ratio
Return series are converted to chart inputs by ranking each observation as the share of the sample that is less than or equal to it. Quantile-analysis is that rank transform.
The same less-than-or-equal rank transform is applied to residuals of returns and to residuals of cumulative returns.
The spread-ratio is the period return of one series divided by the period return of the other. The spread series is the ratio of one leg's returns to the other leg's returns. The spread plot uses the same full-sample rank transform applied to that return ratio.
Hold the mid-rank spread-signal-line
The spread-signal-line is a constant mid-rank reference used as the decision threshold on the ranked spread. The required formula set is completed by copying a constant 0.5 through the sample.
Editorial note: TradersWeek treats that mid-rank line as the explicit abstention threshold. That interpretation is editorial and is not attributed to the archive.
BA–GE residual ranks, spread rank, and 0.5 signal line

Quantile ranks use COUNTIF over the full sample G10:G118 / H10:H118 (and matching residual and spread ranges). Regression intercepts and slopes in J9:M9 are fitted on that same full lookback, then applied row-wise. Red cells in the source are negative signed values.
What this installment leaves out
Chart construction and extra quality checks for whether a pair is tradable are deferred to a later installment.
All readings on this track · 6 readings
- 1986Evaluate the price random-walk question as a gated quantile lab
- 1989Path quantiles versus net return for index velocity regimes
- 1992Opening-referenced percentile stops for same-session gaps
- 1995Read one equity position on a joint yield-regime card
- 2012Construct a pairs-trading worksheet from residuals and quantile ranks
- 2015Constructing mean, median, and mode from ordered prices