Quant research & trading·Python·Published
Kelly Sizer
I built this because I kept sizing positions by feel and wanted the actual formula in front of me with the caveats attached. It implements binary Kelly f* = (p*b - q) / b, fractional Kelly for the obvious reason that full Kelly assumes you know p exactly, continuous Kelly as edge / variance, vol-targeted Kelly that scales the fraction to a target annualized portfolio vol with a leverage cap, and a correlation-adjusted matrix that shrinks each position by 1 / sqrt(1 + (n-1) * avg_corr). The CLI takes an edge, odds, capital and fraction and prints the size in both fraction and dollars, and generate_report emits a Markdown sizing report with the methodology and the caveats written out rather than buried. The multi-asset path takes per-asset edges and vols, applies vol targeting at 15% by default, and clips the final weights. Tests cover the basic formula, zero edge, fractional scaling, the edge/vol case and matrix clipping, all on synthetic inputs, so the arithmetic is checked against known values rather than eyeballed.



- Full Kelly maximizes long-run geometric growth only if the edge estimate is exact, and since it never is, half Kelly costs about a quarter of the growth rate to remove most of the drawdown, which is a trade I will take every time.
- Continuous Kelly as edge / variance blows up fast: a 5% edge at 20% vol implies 1.25x leverage, so a leverage cap is not a nicety, it is the difference between a sizing tool and a liquidation.
- Correlated positions each sized at full Kelly multiply the real risk by roughly the square root of the position count, which is why the 1 / sqrt(1 + (n-1) * avg_corr) shrink has to be applied before the dollar amounts are computed, not after.
Scale 0–100: how much this project relied on each skill.