backtrader
Event-driven backtesting with bar-by-bar execution, complex order types, multiple analyzers,…
Kelly criterion optimal sizing with fractional variants, edge estimation, and practical application for crypto trading
$ npx -y skills add agiprolabs/claude-trading-skills --skill kelly-criterion --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/kelly-criterionContext preview
The summary Claude sees to decide when to auto-load this skill.
Kelly criterion optimal sizing with fractional variants, edge estimation, and practical application for crypto trading
name: kelly-criterion description: Kelly criterion optimal sizing with fractional variants, edge estimation, and practical application for crypto trading
The Kelly criterion is the mathematically optimal bet size that maximizes long-term geometric growth of capital. Developed by John Kelly at Bell Labs in 1956, it answers a precise question: given a known edge, what fraction of your bankroll should you risk to maximize the compounding rate?
**Core insight**: Betting too small leaves growth on the table. Betting too large increases ruin risk and actually *reduces* long-term growth. Kelly finds the exact optimum between these extremes.
**Practical insight**: You should almost never use full Kelly. Estimation error in your edge means full Kelly will overbets in practice. Use fractional Kelly (0.25x to 0.5x) for real trading.
---
For a binary outcome (win or lose):
f* = (p * b - q) / b
Where:
**Equivalent forms**:
f* = p - q / b f* = p - (1 - p) / b f* = (p * b - (1 - p)) / b
**Edge** = `p * b - q` = expected value per unit risked. Kelly only makes sense when edge > 0. If edge is zero or negative, the optimal bet is zero — do not trade.
| Win Rate | Payoff 1:1 | Payoff 1.5:1 | Payoff 2:1 | Payoff 3:1 | |----------|-----------|-------------|-----------|-----------| | 40% | -20% | -6.7% | 10% | 20% | | 45% | -10% | 3.3% | 15% | 25% | | 50% | 0% | 16.7% | 25% | 33.3% | | 55% | 10% | 18.3% | 27.5% | 35% | | 60% | 20% | 26.7% | 35% | 40% |
*Values are full Kelly fraction. In practice, use 0.25x to 0.5x of these numbers.*
---
Full Kelly assumes you know `p` and `b` exactly. You never do. Here is why fractional Kelly is essential:
Your win rate estimate from 100 trades has a standard error of roughly ±5%. If your true win rate is 55% but you estimate 60%, full Kelly will overbets by ~50%, which *reduces* long-term growth below what half Kelly would achieve.
Full Kelly has extremely high variance. Expected maximum drawdown for full Kelly is roughly 50-80% of account. This is psychologically devastating and practically dangerous (margin calls, inability to continue trading).
| Kelly Fraction | Relative Growth Rate | Approximate Max Drawdown | |---------------|---------------------|-------------------------| | 1.0x (full) | 100% | 50-80% | | 0.5x (half) | ~75% | 25-40% | | 0.25x (quarter)| ~50% | 12-20% | | 0.1x (tenth) | ~25% | 5-10% |
Overbetting by 2x (betting at 2*f*) produces **zero** long-term growth — the same as not trading at all. Underbetting by 2x (betting at 0.5*f*) still captures ~75% of the optimal growth rate. The penalty for overbetting is catastrophically worse than for underbetting.
| Fraction | When to Use | |----------|------------| | 0.10x Kelly | Very uncertain edge, new strategy, < 30 trades in sample | | 0.25x Kelly | Moderate confidence, 30-100 trades, reasonable Sharpe | | 0.50x Kelly | High confidence, 100+ trades, consistent performance | | 1.00x Kelly | Never recommended in practice |
---
Kelly requires two inputs: win rate (`p`) and payoff ratio (`b`). Both must be estimated from data.
wins = [t for t in trades if t > 0] losses = [t for t in trades if t < 0] win_rate = len(wins) / len(trades) # p payoff_ratio = mean(wins) / abs(mean(losses)) # b edge = win_rate * payoff_ratio - (1 - win_rate) # should be > 0 kelly_full = (win_rate * payoff_ratio - (1 - win_rate)) / payoff_ratio
Use the **lower bound of a Wilson confidence interval** for win rate rather than the point estimate:
import math
def wilson_lower(wins: int, total: int, z: float = 1.96) -> float:
"""Lower bound of Wilson score interval (95% confidence)."""
p = wins / total
denominator = 1 + z**2 / total
centre = p + z**2 / (2 * total)
spread = z * math.sqrt((p * (1 - p) + z**2 / (4 * total)) / total)
return (centre - spread) / denominatorUsing the lower bound of the confidence interval for win rate automatically builds in conservatism, reducing the risk of overbetting due to sampling luck.
| Edge Value | Classification | Notes | |-----------|---------------|-------| | < 0 | Negative edge | Do not trade this strategy | | 0 - 0.02 | No meaningful edge | Transaction costs likely exceed edge | | 0.02 - 0.10 | Marginal edge | Conservative fractions only | | 0.10 - 0.20 | Good edge | Standard fractions appropriate | | > 0.20 | Excellent edge | Rare; verify not overfitting or temporary |
---
When holding multiple positions simultaneously:
If bets are uncorrelated, each can be sized at its individual Kelly fraction. However, the **sum of all Kelly fractions** should not exceed 1.0 (total portfolio). If it does, scale each proportionally:
kelly_fractions = [0.15, 0.10, 0.12, 0.08] # individual Kelly fractions
total = sum(kelly_fractions) # 0.45
if total > 1.0:
scale = 1.0 / total
kelly_A comprehensive collection of 68 ready-to-use trading, DeFi, and quantitative finance Agent Skills. Works with Claude Code, Cursor, Codex, Gemini CLI, and 30+ other tools.
Repo: agiprolabs/claude-trading-skills
Event-driven backtesting with bar-by-bar execution, complex order types, multiple analyzers,…
Solana token market data via Birdeye — prices, OHLCV, trades, token metadata, security…
Broad crypto market data from CoinGecko covering 13,000+ tokens. Global market stats,…
Cointegration testing for pairs trading using Engle-Granger, Johansen, and rolling stability…
Wallet evaluation, monitoring, and copy-trade strategy design for Solana DEX trading
Cross-asset correlation analysis including rolling correlation, hierarchical clustering, tail…