Research note · Statistical arbitrage

Pairs Trading from Scratch: When TRUMP and MELANIA Argue, the Spread Keeps Score

A visual introduction to linear relationships, residuals, Z-scores, OLS, Kalman filters and cointegration—without needless jargon, using real data and a thematic pair that is hard to beat.

The intuition

1 A pairs strategy does not predict the market: it compares two things

A directional strategy asks: “Will TRUMP rise?”. A pairs strategy asks a different question: “Has TRUMP become too expensive relative to MELANIA, given the relationship they had been maintaining?”. It can make money even if both cryptocurrencies fall, provided their relative relationship moves in the expected direction.

No: the model is not trying to predict who wins an election or who sleeps on the sofa. It only asks whether two prices that usually move together have separated more than usual.

1 · Relationship

We estimate how much TRUMP usually accompanies one unit of MELANIA.

2 · Deviation

We measure how far the observed price moves from the price implied by that relationship.

3 · Convergence

We buy the relatively cheap leg and sell the expensive one, expecting the gap to narrow.

The hypothesis is not “they share a theme, therefore it will work.” The narrative merely proposes a candidate. The data must show a repeatable relationship that remains exploitable after costs.

Pairs-trading strategy flow
The full process in five decisions. Drawing the arrows is the easy part; the hard part is showing that convergence persists beyond the sample used for fitting.

The real example

2 TRUMP and MELANIA: the perfect narrative pair… to put to the test

The example uses the perpetual contracts TRUMPUSDT and MELANIAUSDT on Binance. TRUMP began trading on 18 January 2025; MELANIA on 20 January 2025. The common sample starts when the second contract exists. No earlier history is invented.

56,506common 15-minute bars
0internal gaps and duplicates
588calendar days observed
Normalised prices of TRUMP and MELANIA
Rebasing to 100 makes the paths comparable even though each contract trades on a different scale. The lower line shows that sharing a narrative surname does not fix a constant proportion.

Why Binance when the main research programme uses OKX? Because MELANIA is not currently listed as an active perpetual on OKX, while both contracts are active on Binance. This didactic example remains separate from the main research programme on the OKX universe.

The statistical contract

3 The line, the agreement, and the bill for the argument

We call Y the price of MELANIA and X the price of TRUMP. The model attempts to explain Y through X:

MELANIAt = αt + βt · TRUMPt + residualt

β · proportion

If β = 0.03, one unit of MELANIA is hedged with approximately 0.03 units of TRUMP. It is the slope of the relationship.

α · baseline

It allows the line not to pass through the origin. That adds flexibility—and another moving part.

Residual · distance

It is what MELANIA is worth minus what the model says it should be worth. This is the object we expect to revert.

One global line would hide changes in the relationship. We therefore compare, over the same period, how the four models translate TRUMP's price into an explained value for MELANIA. The larger the orange area, the larger the discrepancy the strategy would try to monetise.

Comparison of the four linear relationships
All four panels share the same period and scale. The turquoise line is MELANIA; the blue line is the value explained by TRUMP; the orange distance is the residual. This makes the intercept's contribution—and Kalman's faster adaptation—immediately visible.

The four lines, with the geometry in plain sight

To see the linear relationship literally, we freeze each model's coefficients at the final bar. The points are observations from the last 90 days aggregated to four hours. In OLS and Kalman without an intercept, the line must pass through the origin; with an intercept, α can shift it.

OLS and Kalman lines with and without an intercept
This is a snapshot at the close of 31 August 2026, not a line valid for the entire history. OLS is re-estimated on a rolling window and Kalman updates its coefficients bar by bar, so all four lines move over time.

Core idea: β does not try to “predict” the exact price. It builds a relative comparison. The residual is the unsettled bill; the Z-score tells us whether that bill is small or extraordinary relative to its recent history.

Four ways to estimate the relationship

4 The same couple, four quantitative therapists

OLS re-estimates a line using a 14-day rolling window. Kalman updates the relationship bar by bar and allows it to change gradually. Without an intercept, qβ = 3·10−8; with an intercept, qβ = 3·10−6 and qα = 3·10−8. In all four cases, the residual is normalised using a 14-day Z-score. These values are illustrative, not optimised.

OLS without intercept

It forces the relationship through the origin: Y = βX. It is simple, stable, and easy to interpret. It may be too rigid when a persistent baseline exists.

OLS with intercept

It estimates Y = α + βX. It adapts better to level shifts, but α and β may divide the explanation between them in unstable ways.

Kalman without intercept

It retains Y = βtX, but allows β to evolve smoothly. It reacts to regime changes; it can also chase noise.

Kalman with intercept

It allows both αt and βt. It is the most flexible—and the easiest to overexcite. Flexibility does not automatically mean truth.

Exact configuration and meaning of each parameter

Model or layerParameter usedWhat it representsWhat happens when it increases
OLS · without interceptβ window = 14 days
1,344 bars
Recent history used to calculate a single slope β, forcing the line through the origin.The slope becomes smoother and more stable, but takes longer to recognise a change in the relationship.
OLS · with interceptα and β window = 14 days
1,344 bars
The same sample simultaneously estimates the level α and slope β.α and β vary less; in exchange, the model may retain an outdated relationship for longer.
Kalman · without interceptqβ = 3·10−8Process variance of β: the amount of freedom the slope receives to change between two bars.β reacts faster, but may also chase temporary moves. Such a small q deliberately imposes slow adaptation.
Kalman · with interceptqβ = 3·10−6
qα = 3·10−8
β can adapt more freely; α remains more rigid so the baseline does not absorb every surprise.Increasing qβ makes the hedge more mobile; increasing qα allows the baseline to move more. Too much of both can erase the residual.
Kalman noiseEMA = 5 bars
75 minutes
Memory used to update the variance of the surprises observed by the filter.Longer memory smooths the noise estimate; shorter memory reacts sooner to turbulent episodes.
NormalisationZ window = 14 days
1,344 bars
Period that defines what counts as a normal or extraordinary residual.The Z-score becomes slower and compares the present with a longer history.
Entry|Z| = 4A position opens only when the residual reaches four standard deviations from its rolling reference.The threshold still requires large deviations, although there is also a risk of mistaking a structural break for an opportunity.
Opposite-side exit|Z| = 3 on the other sideA long opened at −4 closes at +3; a short opened at +4 closes at −3. It does not close on touching zero.Requiring a rotation to the opposite side seeks to capture a wide move, but extends both the duration and risk of the position.

A window and q are not the same unit. OLS explicitly remembers 14 days and abruptly forgets what came before. Kalman has no rectangular window: it retains the previous state, while q determines how much it may correct it. That is why “14 days” and “3·10−8” must not be placed on a common scale as though they were equivalent quantities.

To avoid numerical problems, the filters work with both prices divided by their first common observation. The q values refer to that normalised space. α and β are then transformed back into real prices and units to construct the residual and both legs.

These are not four independent alphas. They are four formulations of the same hypothesis. Comparing them reveals how much the deviation depends on the chosen way of estimating the relationship.

4.1 OLS without intercept · the proportional agreement

OLS without intercept
The slope is recalculated over 14 days. With no α, every level shift must be absorbed by β or appear in the residual.

4.2 OLS with intercept · one additional clause

OLS with intercept
The intercept may capture a persistent level shift, but it may also compete with β. The choice therefore rests on stability and subsequent evidence, not algebraic elegance.

4.3 Kalman without intercept · the slope learns live

Kalman without intercept
Kalman does not use a rectangular window: it carries the previous state forward and corrects it with each new surprise. q controls how much the relationship may move.

4.4 Kalman with intercept · everything moves

Kalman with intercept
Allowing α and β to move can follow rapid changes, but increases the model's freedom. If it explains every argument too well, it may erase the very residual we wanted to trade.

From residual to trade

5 How a statistical distance becomes two orders

Zt = (residualt − rolling mean) / rolling standard deviation
Z ≥ +4. MELANIA is expensive relative to TRUMP according to the model: short MELANIA and long β units of TRUMP.
Z ≤ −4. MELANIA is cheap: long MELANIA and short β units of TRUMP.
We do not exit on touching zero. In this family we wait for a wide rotation: a long closes at +3 and a short at −3.
Both legs count. The portfolio is normalised by MELANIA notional and β·TRUMP notional; returns are not added as though both legs carried equal weight.
Example of a complete trade
Example taken from OLS without an intercept. The entry opens the discrepancy; the exit requires a crossing to the other side. Holding longer may capture a wider move, but also extends risk and exposure to structural break.

Zero-lag / same-open convention

In this exercise, the signal observed at the open of bar t is considered executable at that same open and gains or loses with the move t → t+1. This research convention is consistent with the assumption that real execution would use market-microstructure information to act within the bar.

What it does not model: latency, queue position, market impact, partial fills, or the intrabar path—unless a specific stop is introduced. A bar-based backtest decides whether a hypothesis deserves an execution phase; it does not promise the PnL that will reach the account.

Cointegration and reversion

6 Is there an anchor—or merely two charts that look alike?

Correlation means that two series often move together. Cointegration requires something stronger: a combination of the two whose deviation remains bounded or returns to equilibrium. For pairs trading, that is the interesting property.

Engle–Granger

It estimates a relationship and applies a unit-root test to the residual. It is intuitive and natural for two assets, but depends on which one is assigned to Y and on the relationship being sufficiently stable.

Johansen

It treats the variables jointly and can detect the cointegration rank. It is more general, but sensitive to lags, trend, and sample size.

ADF + KPSS

ADF attempts to reject a unit root; KPSS attempts to reject stationarity. Using both avoids pretending that one test holds the absolute truth.

Half-life, ACF, and crossings

They measure the speed and practical behaviour of reversion. They are useful diagnostics, not notarised certificates of cointegration.

What TRUMP and MELANIA say

MethodNull hypothesisp-valueReading
Engle–GrangerThere is no cointegration0.101Does not reject at 5%
Residual ADFThe residual has a unit root0.031Rejects at 5%
Residual KPSSThe residual is stationary0.010Rejects stationarity
Johansen · rank 0No cointegrating vector existsRejects at 5%
Rolling cointegration diagnostics
The tests use four-hour opens so that thousands of correlated intraday observations are not mistaken for thousands of independent pieces of evidence. The result changes with the method and period.

Didactic conclusion: the evidence is mixed. Engle–Granger does not reject the absence of cointegration at 5%, ADF does detect reversion in its residual, KPSS rejects stationarity, and Johansen finds one vector. This is not an error; it is a warning about instability. Cointegration is not a marriage certificate—at best, it is an interview with references.

Economic exercise

7 What if we trade all four versions under exactly the same rules?

To complete the intuition, we run a simple exercise: fixed parameters, no optimisation, 3.5 basis points per unit of turnover, and the Martin ratio as the primary metric. It is neither a strategy selection nor a promise of returns.

An entry threshold of 4 expands the sample, but does not turn the example into validation. The four formulations may still generate very different trade counts because they do not construct the same residual. Entry counts must be read alongside CAGR and Martin: a few fortunate trades are not sufficient evidence.

Didactic equity curves by model
The differences show that the method used to estimate α and β changes the object being traded. An attractive result here does not validate the pair: development, locked validation, out-of-sample testing, and parameter auditing are still missing.

Results ranked by Martin

The first column identifies the model. Total turnover is expressed in multiples of capital: 23× means that cumulative notional equal to 23 times capital was traded over the full sample. Average daily turnover is a percentage: it divides that turnover across all observed days. A complete entry consumes approximately 1× and its exit another 1×; a direct reversal from long to short consumes 2×. Trades counts entries initiated by the state machine.

ModelMartin · CAGR/UINet CAGRDaily SharpeMax drawdownTradesTotal turnoverAverage daily turnover
Kalman · with intercept5.8858.0%1.24−27.3%250499×84.7%
OLS · with intercept2.0542.9%1.14−36.2%1530×5.1%
Kalman · without intercept0.8723.8%0.75−50.7%4997×16.5%
OLS · without intercept0.5110.3%0.47−35.6%1223×3.9%

Why Martin: it divides annualised return by the Ulcer Index, which measures the depth and persistence of drawdowns. Sharpe remains as context, but Martin better describes whether the path to profit was bearable—or a collection of ulcers with a chart.

What this shows—and what it does not

8 The difference between a useful explanation and selling smoke with two lines

What this document does show

How the residual is constructed; what changes when an intercept is added; how Kalman adapts β; how the Z-score triggers orders; and why statistical tests may disagree.

What this document does not show

That TRUMP/MELANIA is tradable, that the parameters are robust, that the result survives other periods, or that real execution reproduces the simulation.

What the next level would require

Multidimensional grid. β window or speed, Z window, entry, and exit tested jointly.
Robust region. Choose a stable plateau, not the lucky maximum of one cell.
Causal blocks. Develop, freeze, validate, and test without going back to retune.
Costs and representativeness. Penalise turnover and prevent two fortunate trades from winning the competition.
Execution. Test against the order book, liquidity, impact, and fills before production.

The right idea is not “I found a pair.” It is: “I defined a convergent object, measured when it deviates, and designed an honest way to try to refute it.”

Pocket glossary

9 So we can return in a year without rereading the chat

Pairs trading. A simultaneous long and short position designed to monetise a relative move.

Hedge ratio β. Proportion of leg X used to hedge one unit of leg Y.

Intercept α. Constant or dynamic level that shifts the line away from the origin.

Residual. Observed price minus the price explained by the relationship.

Z-score. Residual expressed in standard deviations relative to its rolling history.

Cointegration. Existence of a combination of non-stationary series that is itself stationary.

Half-life. Estimated time for a deviation to reduce its distance from equilibrium by roughly half.

Kalman q. Freedom granted to the state to change; more q means faster adaptation and a greater risk of chasing noise.

Turnover. Notional traded when positions change. It is expressed as a multiple of capital in total and as a percentage of capital in the daily average. This is where commissions live.

Martin ratio. CAGR divided by the Ulcer Index: return relative to the accumulated pain of drawdowns.

Sources and references

GitHub

Code, notebook and reproducible materials.

The public repository preserves the notebook, implementation and reproducible materials. This web publication retains the complete methodology, formulas, figures, results, limitations and conclusion.

GitHub Code and reproduction