Without a mathematical framework for position sizing, autonomous agents over-bet on winning streaks and blow up on losing ones. Kelly Criterion solves this by maximizing the long-run growth rate of your agent's bankroll — not just the expected value of each individual trade.
The Kelly Criterion, developed by John L. Kelly Jr. at Bell Labs in 1956, answers a fundamental question: given a bet with known odds and probabilities, what fraction of your bankroll should you wager to maximize the long-run rate of wealth accumulation?
The answer is the fraction that maximizes the expected logarithm of wealth — not the expected value itself. This distinction is critical. Maximizing expected value can lead to betting your entire bankroll on a positive-EV bet, which risks ruin. Maximizing expected log wealth naturally accounts for the catastrophic effect of going broke.
For trading applications, where wins and losses are not symmetric coin flips, the formula is expressed in terms of average win size (W) and average loss size (L):
An AI trading agent without position sizing is dangerous. Large language models and reinforcement learning agents will naturally gravitate toward action — placing trades — without any internal model of how bet size affects long-run survival. The result is agents that over-bet on high-confidence signals and rapidly deplete their capital.
The Kelly Criterion provides agents with a mathematically grounded upper bound on position size. It converts the agent's internal confidence estimate (win probability) and historical edge (win/loss ratio) into a specific, defensible fraction of bankroll. This makes the agent's behavior auditable: every position size has a provable mathematical justification.
Without Kelly sizing, a string of winning trades can lead an agent to bet 80% of its bankroll on a single position — and one loss wipes out years of gains. With Kelly, the bet size automatically shrinks as your edge diminishes and grows as it strengthens.
A production-ready KellySizer class with fractional Kelly support, bankroll tracking, and integration with the Purple Flea Trading API.
Full Kelly betting is theoretically optimal only when your estimates of win rate and win/loss ratio are perfectly accurate. In practice, these estimates always contain estimation error — and Kelly's growth rate is highly sensitive to overestimating your edge.
If you think your win rate is 60% but it is actually 52%, full Kelly will cause you to significantly over-bet, leading to drawdowns far larger than the math predicts. For AI agents where parameters are estimated from finite data, this is always the case.
Use 25% Kelly as a default. At a quarter of full Kelly, you capture approximately 75% of the maximum growth rate while reducing variance by a factor of 16. This is the sweet spot for production agents where parameter uncertainty is unavoidable.
Full Kelly warning: At full Kelly, the probability of your bankroll halving at some point during a long series of bets approaches 50% — even with a genuine positive edge. At half Kelly, that probability drops to 25%. At quarter Kelly, to about 11%. Always use fractional Kelly in production.
As your agent places trades, its estimates of win rate and W/L ratio should update. Use an exponential moving average to give more weight to recent trades.
Casino games have fixed, known probabilities — making them the ideal test case for Kelly Criterion. Your agent can calculate the exact optimal bet size before every wager on the Purple Flea Casino API.
f* = (1 × 0.49 − 0.51) / 1 = -0.02. A negative Kelly fraction means do not bet. The house edge makes this a losing proposition in the long run, regardless of short-term variance. Your agent should refuse to play when Kelly is negative.
p = 49/100 = 0.49, b = 2. f* = (2 × 0.49 − 0.51) / 2 = 0.235. A 23.5% Kelly bet — but use 25% Kelly so bet 5.9% of bankroll. This is only marginally positive; even small estimation errors flip it negative.
With a fair crash game, the probability of reaching 2x is approximately 50%. f* = (1 × 0.50 − 0.50) / 1 = 0. Exactly break-even — the Kelly fraction is zero, meaning you have no mathematical edge. A house edge of even 1% makes Kelly negative. Only play crash games where you have an informational edge on the cashout timing.
Trading does not have fixed odds like casino games. Your win rate and W/L ratio must be estimated from a backtest or from live trade history. The quality of your Kelly estimate is only as good as your sample size and the stability of your edge.
A robust approach: backtest your strategy on 2 years of historical data, compute win rate and W/L in-sample, then validate on an out-of-sample holdout period. If the out-of-sample metrics are within 10% of in-sample, your Kelly estimate is reasonably reliable. Use a further 50% haircut on estimated edge for live trading.
Wrap KellySizer as a LangChain tool so your agent automatically sizes every position before placing the order through the Purple Flea Trading API.
Kelly assumes each bet is independent. If you open ETH-PERP and BTC-PERP simultaneously, they are highly correlated — effectively one bet. Apply Kelly to your total correlated exposure, not to each position individually. Diversified, uncorrelated positions each get a separate Kelly allocation.
Transaction costs reduce your effective edge. A strategy with a 55% win rate and 1.4 W/L may have a Kelly fraction of 5% before fees — but if you pay 0.1% per trade and trade frequently, fees can consume half your edge. Always compute win_rate and W/L after deducting all fees.
Full Kelly is theoretically optimal only with perfect knowledge of your edge. In practice, estimation error combined with full Kelly produces drawdowns much larger than expected. Always use fractional Kelly (25%–50%) for any real-money agent. The growth-rate sacrifice is modest; the variance reduction is large.
Free to start. 20% referral on trading fees. No KYC required.