đ Position sizing kills more traders than bad picks
Use scipy to compute Kelly criterion fractions on S&P 500 returns
Each week, I send out one Python tutorial to help you get started with algorithmic trading, market data analysis, and quant finance. Upgrade to a paid plan to access the Python code notebooks, Discord community, and code support.
Most traders donât blow up because they picked the wrong stock.
They blow up because they bet too much on the right one. Position sizing, which means deciding how much of your account to put into a single trade, is the part of trading that separates people who last from people who donât. Beginners almost always skip it. They spend weeks finding a strategy, then risk half their account on the first trade without thinking twice.
That habit is how accounts go to zero, usually faster than anyone expects.
The lesson nobody wants to learn first
In 2006, on my first day trading professionally, someone was walking out for their last. A week later, two more people left their screens for good. The managing director eventually told us the one thing that ruins tradersâ careers faster than anything else. Trading too big.
Most beginners I talk to treat risk management as something theyâll figure out later, after theyâve found a âwinning strategy.â
Professionals think about it the other way around. They figure out how much to risk first, then look for trades that fit inside those limits.
What youâll build today
In todayâs post, youâll use Python to calculate the optimal position size for the S&P 500 using a formula called the Kelly criterion, which tells you exactly how much of your account to bet to grow it as fast as possible without taking on unnecessary risk.
Letâs go.
A formula for how much to bet
The Kelly criterion is a formula that tells you the best size for a bet, meaning the amount that grows your account as fast as possible over many repeated bets. John Kelly, a researcher at Bell Labs, invented it in the 1950s to solve problems in information theory and gambling. In the 1960s, a mathematician named Edward Thorp made it famous by using it to beat casinos at blackjack and then applying it to the stock market. He wrote about it in two well-known books, Beat the Dealer and Beat the Market.
Warren Buffett and the legendary bond investor Bill Gross have both reportedly used versions of the Kelly criterion to size their positions. The idea has been around for decades because it works, at least when you can estimate your odds with reasonable accuracy.
How professionals use it
Trading teams at hedge funds and proprietary firms use the Kelly criterion as a starting point for deciding how much capital to put into each trade or strategy.
The formula works best when you have a good estimate of your expected returns, which means you need to know roughly how often your strategy wins and how much it wins or loses on average. Professional firms get these estimates by running their strategies on thousands of historical trades, then adjusting the Kelly number downward (often using half the suggested size) because real markets are messier than any model assumes. The formula also assumes you can make an unlimited number of bets, which nobody actually can, so professionals treat it as an upper bound rather than a target.
Why this matters when youâre starting out
If youâre learning Python for trading, the Kelly criterion is one of the first practical tools worth understanding because it forces you to think about risk before you think about returns.
Most beginners focus entirely on finding trades and ignore how much to risk on each one. Thatâs the fastest way to wipe out an account. The Kelly criterion gives you a concrete, mathematical answer to âhow much should I bet?â Building it in Python teaches you how to work with return data, probability distributions (the range of possible outcomes and how likely each one is), and optimization. Youâll use all of these skills constantly. Even if you never use the exact Kelly number in live trading, the process of calculating it will change how you think about sizing every position you take.
Letâs see how it works with Python.


