edgekit

The math of edge

“Edge” is not a vibe — it is a number. It is the expected value of one trade, measured in units of risk. This chapter defines it precisely, shows why it is invisible until you have taken many trades, and then confronts the harder question the beginner never asks: given a real edge, how much should you bet? The answers are less aggressive than intuition suggests.

R-multiples — the unit of edge#

Dollars are a bad unit for comparing trades, because a $500 win on a $5,000 risk is nothing like a $500 win on a $50 risk. The fix is the R-multiple: express every outcome as a multiple of the amount you risked on that trade ( = your initial stop distance in dollars).

A trade stopped out for its full risk is ; one that makes three times its risk is . R-multiples make trades of different sizes and different instruments directly comparable, and they are the native language of edgekit.metricstrade_stats takes an array of per-trade R and gives you everything else.

Why the R-multiple is the right unit
Dividing by dollars-risked normalises every trade to the same scale, so the per-trade outcomes become draws from one common distribution rather than apples-and-oranges dollar figures. That single move is what makes the expectation , the variance, and every probability statement in this chapter well-defined: you cannot average a distribution that changes units every trade. R-multiples turn a messy trade log into a clean sample from a random variable.

Expectancy#

Suppose a strategy wins with probability , and on a win it makes (in R) while on a loss it gives back (in R, positive). Its expectancy is the expected R per trade:

Derivation — expectancy is just E[·] of a two-outcome variable

Model one trade as a random variable that takes the value with probability and with probability . By the definition of expected value — the probability-weighted sum of the outcomes —

Short proof via linearity. Write the outcome with two indicator variables, , where on a win and otherwise. The expectation of an indicator is just the probability of its event, . Linearity of expectation — , which holds with no independence assumption — then gives .

Why it matters for trading. The formula is exact for a single trade and assumes nothing about independence or identical distribution — those enter only when you average many trades (below). So expectancy is well-defined even for a strategy whose trades are correlated or whose payoff shape drifts; it is the one number that tells you whether the game is worth playing at all.

This is the single most important formula in trading. It is just the expected value from Probability & distributions applied to a trade. If you have an edge; if no amount of clever money management can save you. edgekit reports this as ev_r.

Win rate pAvg win WAvg loss LExpectancy E[R]Edge?
0.402.0R1.0R+0.20RYes — low win rate, big winners
0.601.0R1.0R+0.20RYes — same edge, different shape
0.700.5R1.5R−0.10RNo — high win rate, still loses
0.501.0R1.0R0.00RCoin flip — no edge
Scenario: the first row, in dollars, over 100 trades
Take the top row — , , , so . Trade it on a $100,000 account risking per trade, so each trade is worth on a win and on a loss, and the average trade earns . Over 100 trades your expected profit is . But you win only 40% of them, so you will string together losing runs — six losses in a row () is unremarkable for a 40%-win system. The edge is real and the drawdowns are real at the same time; the /trade only shows up once the losers and the fat winners have both had their turn.
Win rate alone tells you nothing
A 70%-win strategy can be a money-loser and a 40%-win strategy a winner. Only the combination of win rate and payoff — i.e. expectancy — decides. Beginners chase high win rates; the math cares about .

Payoff ratio#

The payoff ratio is the average win divided by the average loss. It lets you find the breakeven win rate for any payoff — the win rate at which :

Derivation — set the expectancy to zero and solve

Breakeven is the win rate at which the edge vanishes, so set and solve for :

Why it matters for trading. This is the bar the real hit rate must clear after costs. Costs act by shrinking every and enlarging every , which lowers and raises — the reason a gross edge so often turns into a net loss. Choosing a target R is therefore not a preference; it is a commitment to beat a specific, computable win rate.

With a 2:1 payoff you only need to win a third of the time to break even; with a 1:2 payoff you need to win two-thirds. This is the trade-off every strategy design negotiates: wider targets buy you a lower required win rate but a lower hit rate to go with it. In edgekit, an ORB(or_bars=30, target_r=2.0) is picking a 2R payoff and therefore a ~33% breakeven — everything hinges on whether the real hit rate clears it once costs are paid.

The law of large numbers#

Expectancy is a statement about the average of many trades — and here is the catch that ruins undercapitalised traders: over a small number of trades, expectancy is invisible. The law of large numbers says the sample average converges to the true expectancy only as the number of trades grows:

Proof sketch — why it converges, and how slowly

Assume the trades are independent with common mean and variance . Linearity gives (the sample average is unbiased), and because variance of independent sums adds,

A random variable with a fixed mean and a variance collapsing to zero concentrates on that mean (Chebyshev: ). That is the weak law. Why it matters for trading: the standard error of your measured edge shrinks only as — the square-root-of-n law. Halving your uncertainty needs four times the trades; a edge with per-trade noise needs on the order of a hundred trades before the signal clears the noise. This is precisely why a losing month tells you almost nothing.

The word converges hides a slow, noisy reality. A genuine edge can sit underwater for dozens of trades in a row; a losing streak of 8–10 is routine even for a good system. Early on, luck dominates skill — the running average staggers around before it settles. This is the mathematical reason a losing month tells you almost nothing.

A running average of trade R-multiples slowly converging toward the true expectancy
Law of large numbers: the running average edge (noisy line) only settles onto its true expectancy (dashed) after many trades. Early swings are pure sampling noise, not signal.
!Edge and survival are different problems
A positive expectancy guarantees you win eventually. It says nothing about surviving the drawdowns along the way — and if a losing streak wipes you out first, the eventual edge never arrives. That is why edge (this section) and sizing (the next) are two separate questions, and both must be answered.

Random walks and the martingale baseline#

What does no edge look like in the language of probability? It is a martingale: a process whose best forecast of its next value, given everything you know, is simply its current value.

A price that is a pure random walk is a martingale, and it is a theorem (the optional-stopping theorem) that no trading rule — no stop, target, or clever entry timing — can manufacture positive expectancy from a martingale: every strategy inherits before costs, and a loss after them. An edge is precisely a departure from the martingale property: means the game, in your direction, is a submartingale — the conditional expectation drifts up, not flat. Everything in this course is an attempt to establish, honestly, that a given series is not a martingale.

Why it matters for trading
The martingale is the null hypothesis you are always testing against. The permutation test in the next chapterworks by literally shuffling your data into a martingale and asking whether your edge could have come from that. If a strategy’s returns are indistinguishable from a driftless random walk, its beautiful backtest is measuring luck, not signal.

The Kelly criterion#

Given a real edge, how much of your capital should you risk per trade? Bet too little and you leave growth on the table; bet too much and volatility drag (from Returns & compounding) — or ruin — eats you alive. The Kelly criterion is the bet fraction that maximises the long-run geometric growth rate. For a payoff ratio and win probability :

Derivation — maximise expected log-growth

Why log growth? Because wealth compounds multiplicatively: after bets your capital is a product of per-bet multipliers, and the log turns that product into a sum whose long-run average is governed by the law of large numbers. Maximising the expected log return per bet, , therefore maximises the long-rungeometric growth rate. Let the per-unit outcome be on a win (probability ) and on a loss (probability ), and stake fraction :

Differentiate and set to zero (the game is concave in , so this is the max):

Collect the terms — the right-side factors combine:

The second derivative everywhere, confirming is a maximum, not a saddle. Notice the numerator is exactly the expectancy per unit staked: no edge, no bet.

!Why fractional Kelly — the variance of log-growth is huge

Full Kelly maximises the expected log-growth, but it says nothing about its variance, which at is punishingly large — full-Kelly equity swings routinely halve the account. Because is concave, a second-order expansion around the optimum,

shows growth falls off only quadratically as you back away from while volatility falls linearly. That asymmetry is the whole case for fractional Kelly: betting keeps roughly three-quarters of the growth for about half the volatility. Since and are themselvesestimated with the sampling error above, betting a fraction also hedges the very real chance you have over-estimated your edge.

The numerator is just the expectancy per unit staked, so Kelly scales your bet with your edge and shrinks it with the payoff’s riskiness. A strategy with and gives — risk 10% of capital per bet to grow fastest. The growth-rate curve peaks at and falls off on both sides; push past it and growth actually turns negative despite the positive edge.

Long-run growth rate as a function of bet fraction, peaking at the Kelly fraction and going negative when over-betting
Growth rate vs bet fraction. It peaks at f*, and crucially the curve is asymmetric — over-betting past ~2f* drives long-run growth below zero even though every individual bet has positive expectancy.
Scenario: a coin-flip edge, sized three ways
You have an even-money strategy () that wins of the time. Full Kelly says — risk 10% of the account per bet to grow fastest. On $100,000 that is a $10,000 stake per trade, and the theory promises the maximum long-run growth rate. It also promises equity swings that routinely halve the account, and if your true is really 0.53 (you over-estimated), 10% is now over-betting the real edge. Half-Kelly — , a $5,000 stake — keeps roughly three-quarters of the growth for about half the volatility. That is the trade nearly every professional takes, and it is why edgekit sizes to a drawdown budget rather than betting a full, fragile point-estimate of .

Why full-Kelly is too aggressive#

Nobody serious bets full Kelly. Three reasons, all fatal in practice:

  • The curve is flat on top but a cliff on the right. Half-Kelly captures about 75% of the growth for roughly half the volatility — a wonderful trade. Over-betting is punished far more harshly than under-betting.
  • Your edge is estimated, not known. and come from a finite sample with the standard error of the last chapter. If you have over-estimated your edge, full-Kelly on the true (smaller) edge is already over-betting.
  • Full-Kelly drawdowns are brutal. The expected worst drawdown at full Kelly routinely exceeds 50% — deeper than almost any real account (or prop-firm rule) can tolerate.

The standard practice is fractional Kelly — a quarter to a half of . edgekit sidesteps the fragile point-estimate of Kelly entirely for deployment: rather than bet a fraction of a guessed edge, edgekit.sizing sizes against a hard drawdown budget, which is the constraint that actually binds a real account.

edge_to_size.py
from edgekit import trade_stats, sizing

# 1) measure the edge, in R
st = trade_stats(trades.r, dates=trades.date)
print(st["ev_r"], st["win_rate"], st["pf"])   # is E[R] > 0 with enough trades?

# 2) size to a drawdown budget rather than a full-Kelly guess
res = sizing.size_to_dd(daily_r, dd_budget=0.095, account=100_000)
res["dollar_per_r"]   # dollars to risk per 1R so historical max DD == 9.5%
res["binding"]        # which constraint set the size

Risk of ruin#

The flip side of Kelly. Risk of ruin is the probability that a string of losses drags your account below a threshold you cannot come back from — before the edge has time to pay out. For a simplified even-money game with win probability and units of capital, the classic gambler’s-ruin result is:

Derivation — first-step analysis of the gambler's ruin

Track capital in whole units and let be the probability of eventual ruin (hitting ) starting from units, with win probability and loss probability per bet. Condition on the first bet — this is first-step analysis, an application of the law of total probability:

This linear recurrence has characteristic equation , whose roots are and . The general solution is therefore . With a positive edge the ruin probability must stay bounded and tend to as capital grows, forcing ; the boundary forces . Hence , and starting from units,

Why it matters for trading. A drawdown limit — a prop-firm rule, or the level below which you quit — is exactly a lower absorbing barrier on this walk. The exponent is how many units of risk your capital represents, and you set it with bet size: risk 1% per trade and ; risk 10% and . Because ruin decays geometrically in , over-betting shrinks the exponent and drives — a positive edge with too large a bet is almost sure to be ruined before the law of large numbers can pay it out. Edge sets the base ; sizing sets the exponent — and the exponent wins.

Two levers control it: the size of your edge ( above 0.5) and how many units of risk your capital represents (, which you set by bet size). Even a solid edge combined with an over-sized bet gives a frightening probability of ruin — and once ruined, the positive expectancy is worthless because you are no longer in the game.

Scenario: same edge, bet size decides survival
Keep the winning edge (so ) and treat “ruin” as losing the whole account. If you risk 1% per trade, your capital is units and the ruin probability is — around , effectively zero. Crank the bet to 10% per trade and now : — a 13% chance of blowing up despite the identical, genuinely positive edge. Push to 20% () and it climbs to . The signal never changed; the exponent did. Sizing, not edge, is what keeps you in the game long enough for the edge to pay.
Risk of ruin rising sharply as bet size per trade increases, for a fixed positive edge
Risk of ruin against risk-per-trade for a fixed positive edge. Small bets keep ruin near zero; past a point the same edge is almost certain to blow up. Sizing, not signal, decides survival.
The whole message in one line
Edge decides whether you win in the long run; sizing decides whether you live long enough to see it. A positive expectancy and a bet size that keeps risk-of-ruin near zero are both required — neither substitutes for the other. This is the bridge into Position sizing.

Next: we have the math to define and size an edge — so why do so many backtests show edges that evaporate live? Why most backtests lie.