Home › Templates › Pairs trading spreadsheet

Pairs Trading Spreadsheet: Hedge Ratio, Z-Score Signals and Trade Log

A free pairs trading spreadsheet for Excel and Google Sheets. Paste daily closes for two stocks (up to 500 rows). The sheet estimates the hedge ratio by regression, builds the spread and its rolling z-score, applies your entry, exit and stop levels, sizes both legs dollar-neutral or beta-neutral, and logs every round trip with P/L per leg, commissions and short borrow fees. It also reports correlation, the half-life of mean reversion and a cointegration test statistic.

Download Excel template (.xlsx) 400 KB · 500 rows · 60-trade log · no macros · Excel 2016+ and Google Sheets · v1.0, 12 Nov 2026

Use it in Google Sheets: choose File → Import → Upload in Sheets and pick the .xlsx, or upload it to Google Drive and open it with Google Sheets. No sign-up, no add-in, no price feed: you paste the prices.

Preview: the Example tab. The pair is synthetic: “Synthetic A” and “Synthetic B” were generated in Python with a fixed random seed. They are not real stocks and the results say nothing about real markets.
1.2382hedge ratio beta (rows 1–250)
5.7 rowshalf-life of mean reversion
−3.79cointegration t (5% value −3.36)
12trades in rows 251–500 (1 stop)
$128.72net P/L after $159.45 of costs
Formation rows 1–250 (beta, half-life, test)Trading rows 251–500−4−20+2+4row 250row 300row 400row 500z-score of the spread (Example tab). Dots: entry signals. Squares: exit signals (red = stop).stopentry
#SpreadEntryExitDaysz inz outReasonLeg ALeg BCostsNet P/L
1Short2025-11-122025-11-175+2.69+0.46Exit$60.30−$165.15$11.78−$116.63
2Short2025-11-192025-11-289+2.57+0.31Exit$491.92−$349.44$13.11$129.37
3Long2025-12-192025-12-245−2.22−0.24Exit$254.52−$106.43$12.31$135.78
4Long2026-01-012026-01-076−2.20+0.21Exit$714.87−$343.68$12.78$358.41
5Short2026-02-102026-03-0220+2.15−0.25Exit$460.00−$339.45$17.73$102.82
6Long2026-03-172026-04-0216−2.41−0.50Exit$742.22−$659.75$18.30$64.17
7Short2026-04-132026-04-229+2.50+0.46Exit$190.74$107.01$13.22$284.53
8Long2026-05-272026-06-1519−2.33−0.17Exit$937.60−$640.80$19.20$277.60
9Long2026-06-252026-06-294−2.01−0.27Exit−$179.19$159.84$10.82−$30.17
10Short2026-07-092026-07-156+2.22+3.69Stop−$1,148.40−$194.88$11.08−$1,354.36
11Short2026-09-012026-09-021+2.12−0.30Exit$210.94−$125.87$7.47$77.60
12Long2026-09-072026-09-169−2.46−0.22Exit$36.09$175.16$11.67$199.58
Total, 12 trades (9 above 0, 1 stop)$128.72

What pairs trading is

Pairs trading buys one stock and shorts a related one when the gap between them is unusually wide, then closes both when the gap narrows. The bet is on the spread, not on the market. The best-known academic test describes the rule like this:

“We open a position in a pair when prices diverge by more than two historical standard deviations, as estimated during the pairs formation period. We unwind the position at the next crossing of the prices.”Gatev, Goetzmann and Rouwenhorst, NBER Working Paper 7032 (1999)

The published version, “Pairs Trading: Performance of a Relative-Value Arbitrage Rule” (Review of Financial Studies 19(3), 2006, pp. 797–827, doi:10.1093/rfs/hhj020), tested US stocks “with daily data over 1962–2002” and paired stocks by “minimum distance between normalized historical prices” (abstract on EconPapers). In the working paper, pairs were formed over twelve months and traded over the next six.

This template uses a regression variant that many traders use instead of the distance method: a log-price hedge ratio, a rolling z-score of the spread, and explicit exit and stop levels. It is a different rule from the paper's, so the paper's results do not carry over to it.

What's inside the spreadsheet

TabWhat it does
Start hereSteps, formulas, colour key, limits, sources, disclaimer. Says the Example data is synthetic.
DataYellow settings (rows 4–17) and an empty paste area: date, price A, price B from row 35, up to 500 rows.
SignalsResults block (beta, alpha, R², correlations, half-life, cointegration t and critical values, data and settings checks) and one formula row per price row: ln prices, spread, rolling mean and SD, z-score, signal, stop lock, executed position.
Trade logUp to 60 round trips: direction, dates, z in and out, exit reason, prices, shares, P/L of each leg, commissions, borrow fee, net P/L, % of gross exposure, running total.
ExampleThe same model filled with a 500-row synthetic pair, including a deliberate regime break.
DashboardYour data next to the Example: pair statistics, trade counts, net P/L, costs, latest z-score and position, plus two native z-score charts with the bands.

Settings

SettingDefaultWhat it controls
Rolling window W20 rowsRows in the rolling mean and SD of the spread.
Entry / exit / stop|z| 2.0 / 0.5 / 3.5Open beyond ±2, close back inside ±0.5, cut beyond ±3.5. After a stop, no new entry until |z| ≤ exit.
Formation rows F250Rows used for beta, half-life and the test. Trades start after row F. Blank = all rows (flagged as in-sample).
ExecutionNext row closeTrade at the close after the signal, or at the signal's own close.
SizingBeta-neutral$beta of B per $1 of A, or equal dollars (dollar-neutral).
Dollars in leg A$10,000Shares A = INT(amount ÷ price A).
Commissions$0.005/share, $1 minPer order; 4 orders per round trip.
Borrow fee, day count1.5% a year, 360On the short leg's entry value, per calendar day held.

How to use it

  1. Download daily closes for two stocks over the same dates. Use adjusted closes if your source has them, and the same source for both.
  2. On the Data tab, paste date, price A and price B from row 35, oldest first, with no blank rows. Paste values only.
  3. Set the formation rows to roughly the first half of your history (it must be below your number of rows), then the window and z levels.
  4. On Signals, check that the data check (E5) and settings check (E6) say OK.
  5. Read the cointegration result and half-life before the trade log. If the test shows no evidence of cointegration, the z-score signals have little basis.
  6. Read the Trade log and Dashboard. Change one setting at a time and note how much results move.

The formulas

These are the formulas on the Signals tab (row 35 is the first data row; settings live on Data). Every column is wrapped in IF($A35="","",…) so empty rows stay blank. No macros, no array formulas, no OFFSET or INDIRECT.

ResultFormula in the file
Hedge ratio beta=SLOPE(INDEX($E$35:$E$534,1):INDEX($E$35:$E$534,F), INDEX($F$35:$F$534,1):INDEX($F$35:$F$534,F)) (ln A on ln B, first F rows); alpha with INTERCEPT
Spread=E35-beta*F35-alpha
Rolling mean, SD=AVERAGE(INDEX($G$35:$G$534,A35-W+1):G35) and the same with STDEV
z-score=(G35-H35)/I35
Signal positionflat → −1 if z>=entry and z<stop; +1 if z<=-entry and z>-stop. Long (+1) → 0 if z>=-exit or z<=-stop. Short (−1) → 0 if z<=exit or z>=stop.
Executed position=IF(lag=1,N(L34),L35): the previous row's signal when you trade at the next close
Shares=INT(amount/A_entry); B: =INT(ratio*amount/B_entry), ratio = beta or 1
P/L per legA: =side*sharesA*(A_exit-A_entry); B: =-side*sharesB*(B_exit-B_entry)
Commissions=2*MAX(min,per_share*sharesA)+2*MAX(min,per_share*sharesB)
Borrow fee=IF(side=1,sharesB*B_entry,sharesA*A_entry)*rate*days/day_count
Half-life=-LN(2)/SLOPE(Δspread rows 2..F, previous spread rows 2..F)
Cointegration t=b/(STEYX(Δspread, previous spread)/SQRT(DEVSQ(previous spread)))

Dollar-neutral or beta-neutral

The spread is ln A − beta × ln B. A 1% move in B moves the spread by beta × 1%, so holding $beta of B for each $1 of A makes the dollar P/L track the spread. That is the beta-neutral option. Dollar-neutral holds equal dollars in both legs; it is simpler and is closer to the one-dollar-long, one-dollar-short pairs in the Gatev study, but it leaves a net exposure of (1 − beta) to B's moves. Shares are rounded down, so legs are never exactly balanced.

Half-life and the cointegration test

Engle and Granger defined the idea that makes pairs trading work: series that each wander, but whose combination does not. In their words, a vector of series “is said to be cointegrated with cointegrating vector a if each element is stationary only after differencing while linear combinations a′xt are themselves stationary” (“Co-Integration and Error Correction: Representation, Estimation, and Testing”, Econometrica 55(2), 1987, pp. 251–276; abstract on EconPapers).

The sheet runs one regression on the formation rows: the change in the spread on the previous spread, Δst = c + b × st−1. Two numbers come out of it.

In the example, b = -0.1224, so the half-life is 5.7 rows (exact 5.3), and t = -3.79 against a 5% value of -3.36 for T = 249. The data were simulated with a true half-life of 9.6 rows, so the estimate is off by about 40% even on 250 clean rows. Treat a half-life as a rough scale, not a timer.

What the test does not do. MacKinnon notes that the test value changes with which series is the regressand, so try swapping A and B when the result is close. The sheet uses no lagged differences (not an augmented test), and the critical values assume the errors are independent. A pass on the formation rows is evidence about the past, not a guarantee about the trading rows.

Worked example from the sample data

Example settings: W = 20, entry 2.0, exit 0.5, stop 3.5, formation rows 250, next-row execution, beta-neutral, $10,000 in leg A, $0.005 a share with a $1 minimum, 1.5% borrow fee on a 360-day count.

Trade 4 (exit). On row 303 the z-score fell to −2.20, below −2. The sheet bought the spread at the next close (row 304): 611 shares of A at $16.34 and 358 shares of B short at $34.51 (beta × $10,000 ÷ $34.51, rounded down). z was back above −0.5 on row 307, so it closed on row 308. Leg A made $714.87, leg B lost $343.68, costs were $9.69 commissions and $3.09 borrow fee: net $358.41.

Trade 10: the stopCalculationResult
Signalrow 438, z = +2.22 ≥ 2: short the spread—
Entry (row 439 close)short 522 A at $19.13; buy 336 B at $36.83—
Stop signalrow 442, z = +3.69 ≥ 3.5 (the synthetic jump)—
Leg A−1 × 522 × ($21.33 − $19.13)−$1,148.40
Leg B+1 × 336 × ($36.25 − $36.83)−$194.88
Commissions2 × max($1, 0.005 × 522) + 2 × max($1, 0.005 × 336)$8.58
Borrow fee522 × $19.13 × 1.5% × 6 ÷ 360$2.50
Net P/Llegs − costs−$1,354.36

Over rows 251–500 the example makes 12 trades: 9 end above 0, and the one stop loses $1,354.36, which wipes out most of the $1,629.88 that the 9 winning trades made together, leaving $128.72 after $108.25 of commissions and $51.20 of borrow fees. The spread was built to mean-revert, and one break still took most of the profit.

Correlation is not cointegration

High correlation is the most common reason people pick a pair, and it is weak evidence. Two trending prices correlate even with no link between them. A check you can repeat: two independent random walks with the same upward drift (500 rows, Python seed 7, the same settings as the example) give a correlation of log prices of 0.93, a correlation of daily returns of 0.06, and a cointegration t of -2.16, which does not get below even the 10% critical value of -3.06. The sheet still reports a “half-life” of 17.9 rows for that pair, which is why the test comes before the half-life.

The example pair, by contrast, shows 0.985 for log prices, 0.829 for returns and passes the 5% test, because it was simulated as cointegrated.

Look-ahead bias and regime breaks

Short-side costs

Every pairs trade has a short leg. Investor.gov notes that when you short, “your brokerage firm will charge you interest on the loan, and you are subject to the margin rules,” and “If the stock you borrow pays a dividend, you must pay the dividend to the person or firm making the loan” (Investor Bulletin: An Introduction to Short Sales). The template charges a borrow fee on the short leg and commissions on all four orders. Dividends owed on the short leg, margin interest and slippage are not modelled; use adjusted prices to keep dividends from showing up as fake spread moves. For a full short-side ledger see the short selling spreadsheet.

Common mistakes

Limits

Daily closes only; you paste the prices. One hedge ratio for the whole trading period (no rolling re-estimation, no Kalman filter) and no rebalancing during a trade. The cointegration test has no lagged differences and uses one regression direction. Fills are at closing prices with no slippage or bid-ask spread. Dividends on the short leg, margin interest, taxes and broker recalls are not included. Calendar days drive the borrow fee; rows drive the half-life. US-style per-share commissions; one currency.

FAQ

How do you calculate the hedge ratio for pairs trading?

Regress the log price of stock A on the log price of stock B over a formation window. The slope is the hedge ratio: in Excel, =SLOPE(ln A range, ln B range), with =INTERCEPT for the constant. The spread is then ln A − beta × ln B − alpha. In the synthetic example, 250 rows give beta = 1.2382, so a beta-neutral trade holds about $1.24 of B for every $1 of A.

What z-score should you use to enter a pairs trade?

There is no correct value. Gatev, Goetzmann and Rouwenhorst opened positions when prices diverged by two historical standard deviations. Higher entry levels give fewer trades; a stop level caps how far you let the spread run. Test any choice out of sample.

What is the difference between correlation and cointegration?

Correlation measures whether two series move together; cointegration means a combination of them stays stationary, so gaps tend to close. Two unrelated random walks with the same upward drift can show a high price correlation: in a seeded simulation on this page, 0.93 for log prices, 0.06 for daily returns, and a cointegration t statistic of -2.16, which does not pass even the 10% critical value.

How do you calculate the half-life of mean reversion?

Regress the daily change in the spread on the previous day's spread. If the slope b is negative, the half-life is −ln(2) ÷ b periods (the exact discrete version is ln(0.5) ÷ ln(1 + b)). In Excel: =-LN(2)/SLOPE(change range, lagged spread range). The example gives b = -0.1224 and a half-life of 5.7 rows.

Can you do pairs trading in Excel or Google Sheets?

Yes for daily closes: SLOPE, INTERCEPT, AVERAGE, STDEV, CORREL and INDEX are enough to build the spread, z-score and signals, and this template uses only those. A spreadsheet will not place orders, stream prices or handle intraday data.

Is pairs trading profitable?

No one can promise that. Gatev, Goetzmann and Rouwenhorst (2006) reported positive historical excess returns for US stocks from 1962 to 2002, but their working paper found that waiting one day before trading reduced average excess returns by about 200 basis points. Costs, borrow fees, slippage and broken relationships can erase the edge.

Related tools and templates

Educational template only, not investment advice. Results on past or synthetic data do not predict future returns, and short selling can lose more than the amount invested. The Example pair is synthetic: prices were generated with a fixed random seed and do not describe any real company. Sources: Gatev, Goetzmann and Rouwenhorst, Review of Financial Studies 2006 (doi.org) and NBER Working Paper 7032 (nber.org); Engle and Granger, Econometrica 1987 (econometricsociety.org); MacKinnon, QED Working Paper 1227, 2010 (repec.org); Investor.gov (investor.gov). Retrieved 12 November 2026.