FeaturesLearnNISMGalleryFaqPricingAboutWeb Terminal (Desktop & iOS)Get Mobile App
Algorithmic Trading 101: Strategies, Backtesting & Risk Management
πŸ“š Course Β· 10 chaptersIntermediate 3.5 hours

Algorithmic Trading 101: Strategies, Backtesting & Risk Management

A practitioner-oriented course covering the core building blocks of systematic trading: how to backtest without fooling yourself, the statistics behind mean-reversion and momentum strategies, and how to size positions and manage risk so a good strategy doesn't blow up your account.

Algorithmic Trading

Course Syllabus

8 / 10
Chapter 8 of 10

Chapter 8: Position Sizing and the Kelly Formula

8/10

Chapter 8: Position Sizing and the Kelly Formula

Every chapter so far has focused on one question: does this strategy have a genuine edge? We've learned to detect mean reversion and momentum (Chapters 4 and 6), backtest honestly (Chapter 1), validate statistical significance (Chapter 2), and understand the market mechanics that drive returns (Chapter 7). But even a strategy with a real, statistically validated edge can still destroy an account β€” if it's traded with the wrong amount of capital.

This is the paradox every systematic trader eventually confronts: too little leverage wastes a good edge, and too much leverage turns a good edge into ruin. A strategy that would have compounded beautifully at the right size can wipe out an account entirely if oversized β€” even though, on paper, the edge was completely real.

This chapter introduces the Kelly formula, the mathematical foundation for answering the question 'how much should I actually bet?' β€” along with the practical wisdom needed to use it safely, since the raw formula, applied naively, is a genuinely dangerous tool.

Why this chapter matters: A validated edge (Chapters 1-2) tells you whether to trade a strategy. Position sizing tells you how much β€” and getting this wrong is one of the most common ways traders turn a genuinely profitable strategy into a blown account.


1. The Real Goal: Long-Term Compounded Growth

Reframing Risk Management

Many traders think of risk management purely through the lens of loss aversion β€” the simple, instinctive discomfort of watching an account balance go down. But this instinct, while understandable, isn't actually a rational foundation for position sizing. The right way to think about risk is this: our real objective is to maximize long-term compounded equity growth, and we manage risk only to the extent that risk interferes with that goal.

This reframing matters because it changes the entire question. It's not 'how do I avoid losses' β€” some losses are an unavoidable, even necessary, part of any real trading strategy. The real question is: 'what level of leverage grows my capital the fastest over the long run, given the statistical properties of my strategy's returns?'

Note: Research in behavioral finance suggests that most people need the potential to gain roughly β‚Ή2 to psychologically justify risking β‚Ή1 β€” which may explain why a Sharpe ratio of 2 feels so intuitively appealing to traders, even though the 'right' amount of leverage to use is a distinct question from how a strategy's risk-adjusted returns simply feel.

Why Leverage Must Stay Constant

A central, somewhat counterintuitive requirement running through everything in this chapter: optimal position sizing requires holding leverage constant over time β€” meaning your total exposure should always remain a fixed multiple of your current equity, not your starting equity.

Classic Example: Suppose you begin trading a Bank Nifty futures strategy with β‚Ή10,00,000 in capital, and your calculated optimal leverage is 3x β€” meaning you should hold a position with a market value of β‚Ή30,00,000. If the strategy loses β‚Ή1,00,000 on a bad day, your equity falls to β‚Ή9,00,000. To maintain the same 3x leverage, your position's market value must now shrink to β‚Ή27,00,000 β€” meaning you need to actively sell down your position, reducing exposure precisely when you've just taken a loss. Conversely, if the strategy gains β‚Ή1,00,000, your equity rises to β‚Ή11,00,000, and maintaining 3x leverage means adding to your position, increasing exposure precisely when things have been going well.

This 'sell into losses, buy into gains' behavior can feel deeply uncomfortable β€” it's the opposite of what loss-averse instinct tells you to do. But it is mathematically necessary to achieve the optimal long-term compounded growth rate. We'll return to a serious downside of this requirement in Section 5.

A simple two-column bar chart titled 'Constant Leverage in Action β€” 3x Leverage on a β‚Ή10,00,000 Account', showing three scenarios side by side: 'Starting Position' with Equity β‚Ή10,00,000 and Market Value β‚Ή30,00,000, 'After a β‚Ή1,00,000 Loss' with Equity β‚Ή9,00,000 and Market Value reduced to β‚Ή27,00,000 with a downward arrow labeled 'Must Sell to Reduce Exposure', and 'After a β‚Ή1,00,000 Gain' with Equity β‚Ή11,00,000 and Market Value increased to β‚Ή33,00,000 with an upward arrow labeled 'Must Buy to Increase Exposure'
πŸ“· A simple two-column bar chart titled 'Constant Leverage in Action β€” 3x Leverage on a β‚Ή10,00,000 Account', showing three scenarios side by side: 'Starting Position' with Equity β‚Ή10,00,000 and Market Value β‚Ή30,00,000, 'After a β‚Ή1,00,000 Loss' with Equity β‚Ή9,00,000 and Market Value reduced to β‚Ή27,00,000 with a downward arrow labeled 'Must Sell to Reduce Exposure', and 'After a β‚Ή1,00,000 Gain' with Equity β‚Ή11,00,000 and Market Value increased to β‚Ή33,00,000 with an upward arrow labeled 'Must Buy to Increase Exposure'

2. The Kelly Formula: Optimal Leverage Under a Gaussian Assumption

The Formula

Under the simplifying assumption that a strategy's excess returns follow a Gaussian (normal) distribution, the Kelly formula gives a remarkably simple, closed-form answer for the leverage that maximizes long-term compounded growth:

Optimal Leverage (f) = Mean Excess Return Γ· Variance of Excess Returns

In plain terms: the higher your strategy's average return relative to its volatility, the higher the leverage the Kelly formula recommends. A strategy with a strong, consistent edge (high return, low variance) justifies more leverage; a strategy with a weak or erratic edge (low return, high variance) justifies little to none.

It can be mathematically proven that, if the Gaussian assumption holds and all profits are continuously reinvested, this specific leverage level produces the highest possible compounded growth rate of any constant-leverage strategy β€” using more leverage than this actually produces a lower long-term growth rate, not a higher one, because the extra volatility drag outweighs the extra expected return.

Classic Example: Suppose a systematic Nifty options-selling strategy has, based on a rigorously validated backtest (using the full toolkit from Chapters 1 and 2), an estimated mean excess daily return and a corresponding daily variance that, when plugged into the Kelly formula, suggests an optimal leverage of 4x. This tells you that β€” assuming your estimates of mean and variance are accurate β€” running this strategy at 4x leverage would grow your capital faster over the long run than running it at either 2x (too conservative, leaving growth on the table) or 8x (too aggressive, where the added volatility drag actually reduces long-term compounded growth despite the higher average return).

The Danger of Estimation Error

Here's the critical catch: the Kelly formula requires knowing the true mean and variance of your strategy's future returns β€” but you can never actually know these values with certainty. You only have historical estimates, and those estimates carry real uncertainty (recall the sample-size lessons from Chapter 2).

This creates a deeply asymmetric risk:

  • If you underestimate leverage (using a leverage lower than the 'true' optimal), the consequence is merely a suboptimal, slower growth rate β€” a mild cost.
  • If you overestimate leverage (using a leverage higher than the 'true' optimal β€” for example, because your backtested mean return was inflated by good luck, or your estimated variance understated real future volatility), the consequence can be catastrophic: an overestimated Kelly leverage, applied at a high enough magnitude, can lead all the way to ruin β€” equity going to zero.

Warning: This asymmetry is the single most important practical lesson of this chapter. Because overestimating leverage is so much more dangerous than underestimating it, and because your mean/variance estimates are never perfectly certain, treating the raw Kelly formula's output as a leverage target is a genuinely risky practice. It should be treated as an upper bound β€” a ceiling you deliberately stay well below, not a number you aim for directly.


3. Half-Kelly: The Practical Compromise

Why Traders Discount the Formula

Given the asymmetric danger described above, a widely adopted practical convention among professional traders is to use half of the Kelly-recommended leverage β€” commonly called half-Kelly.

The logic is straightforward: because Kelly's growth-rate curve is relatively flat near its peak (meaning leverage somewhat below the true optimal sacrifices only a modest amount of growth rate), but the downside of overshooting the true optimal accelerates sharply toward ruin, deliberately under-leveraging relative to your best estimate provides a substantial safety margin at a relatively small cost in expected growth rate.

Classic Example: If your validated backtest of a Reliance Industries mean-reversion strategy (built using Chapter 5's Bollinger band framework) suggests a full-Kelly optimal leverage of 5x, adopting half-Kelly means running the strategy at 2.5x instead. If your original mean/variance estimates turn out to have been accurate, you'll compound your capital somewhat slower than the theoretical maximum β€” a real but modest cost. But if your estimates were optimistic (a very common scenario, since backtests tend to look better than live performance, as we discussed all the way back in Chapter 1), the half-Kelly position gives you meaningful protection against the sharply accelerating downside of having overestimated your true edge.

Kelly as a Sanity Check, Not Just a Target

Beyond directly setting leverage, the Kelly formula is also genuinely useful as a sanity check against products or strategies that appear to be using dangerously excessive leverage.

Classic Example: Suppose Kelly-formula analysis on a broad market index (comparable in spirit to indices like the Nifty 50 or similar diversified benchmarks) suggests an optimal leverage of roughly 1.8x, based on its long-run historical return and volatility characteristics. Now consider a leveraged ETF product explicitly designed to deliver 3x the daily return of that same index. Since 3x already exceeds the Kelly-optimal leverage of 1.8x for the underlying index, there is a genuine, quantifiable risk that sustained use of such a product β€” especially held for periods longer than a single trading day, where compounding effects on leveraged products can diverge meaningfully from a simple 3x multiple β€” carries a real risk of the product's value eroding toward zero over time, even if the underlying index itself performs reasonably well. This is exactly why fund providers of such leveraged products typically include prominent warnings against buying and holding them for extended periods.


4. Beyond Gaussian: Simulation and Empirical Approaches

Why the Gaussian Assumption Often Fails

The closed-form Kelly formula's elegance comes at a cost: it assumes returns are Gaussian (normally distributed). Real trading strategy returns are frequently not Gaussian β€” they often exhibit fat tails (extreme moves happening more often than a normal distribution predicts) and skewness (asymmetric likelihood of large gains versus large losses).

Classic Example: A Bank Nifty options-selling strategy β€” collecting small, frequent premiums in exchange for occasionally being exposed to large, sharp losses during unexpected volatility spikes (such as a surprise RBI announcement or a geopolitical shock) β€” typically has a return profile that looks nothing like a Gaussian distribution. Most days show small, steady gains, but the occasional tail event produces a loss far larger than a Gaussian model would predict. Applying the standard Kelly formula's variance-based calculation to this kind of strategy, without adjustment, risks significantly overestimating the safe leverage level, because it doesn't properly account for the fat-tailed nature of the loss distribution.

Simulation-Based Optimization

When the Gaussian assumption is a poor fit, a more robust alternative is to numerically optimize leverage using simulated returns drawn from a distribution that better matches the strategy's actual historical shape β€” capturing the real skewness and kurtosis (fat-tailedness) observed in the backtest, rather than assuming a symmetric bell curve.

The general process:

  1. Characterize your strategy's historical returns β€” not just the mean and variance, but also skewness and kurtosis.
  2. Generate a large number of simulated return sequences that share these same statistical properties (this should feel familiar β€” it's the same Monte Carlo philosophy from Chapter 2's statistical significance testing, now applied to sizing rather than significance).
  3. For each candidate leverage level, calculate the resulting compounded growth rate across all simulated sequences.
  4. Select the leverage level that maximizes the average simulated compounded growth rate, subject to an acceptable risk of severe drawdown across the simulations.

Empirical Optimization on Historical Returns

An even more direct, if data-hungry, alternative is to optimize leverage directly against your actual historical backtest returns, without assuming any particular theoretical distribution at all β€” simply testing which leverage level would have produced the best compounded growth rate on the exact historical return sequence you observed.

Warning: This empirical approach is elegant but comes with an obvious echo of Chapter 1's central warning: optimizing leverage directly against a single historical return sequence is itself a form of fitting to that specific sample. Just as with strategy parameters, be cautious of finding a suspiciously 'perfect' leverage level that happens to maximize returns on your specific backtest window β€” validate any empirically-derived leverage level against out-of-sample data, exactly as you would validate the underlying strategy itself.

A comparison chart titled 'Gaussian vs. Fat-Tailed Return Distributions for Position Sizing', showing two overlaid probability distribution curves β€” a smooth, symmetric bell curve labeled 'Gaussian Assumption (standard Kelly formula)' and a taller, narrower peaked curve with visibly thicker tails on both sides labeled 'Actual Strategy Returns (e.g., options-selling with occasional volatility shocks)', with shaded regions in the tails of the second curve highlighted and annotated 'Fat tails mean standard Kelly formula can overestimate safe leverage'
πŸ“· A comparison chart titled 'Gaussian vs. Fat-Tailed Return Distributions for Position Sizing', showing two overlaid probability distribution curves β€” a smooth, symmetric bell curve labeled 'Gaussian Assumption (standard Kelly formula)' and a taller, narrower peaked curve with visibly thicker tails on both sides labeled 'Actual Strategy Returns (e.g., options-selling with occasional volatility shocks)', with shaded regions in the tails of the second curve highlighted and annotated 'Fat tails mean standard Kelly formula can overestimate safe leverage'

5. Allocating Across Multiple Strategies

The Multi-Strategy Kelly Formula

Most serious systematic traders don't run just one strategy β€” they run a portfolio of several, perhaps combining a mean-reversion strategy on a stock pair, a cross-sectional momentum strategy on a stock universe, and a futures-based roll-return strategy (drawing on Chapters 5, 6, and 7 respectively). The Kelly framework extends naturally to this multi-strategy setting: the optimal leverage for each individual strategy depends not just on its own mean and variance, but also on how correlated its returns are with the other strategies in the portfolio.

Intuitively, this makes sense: two strategies that tend to lose money at the same time (highly correlated) don't diversify each other, so combining them doesn't justify as much combined leverage as two strategies that tend to lose money at genuinely different times (uncorrelated or negatively correlated) β€” which is precisely why, as we discussed in Chapter 6, combining a mean-reversion strategy with a momentum strategy can be attractive: their tendency to perform well in different market regimes means they're not highly correlated, and can support more total leverage together than either could safely support alone.

What Happens When Your Broker Limits Total Leverage?

In practice, brokers impose maximum leverage limits that are often well below what an unconstrained Kelly calculation might suggest for a full multi-strategy portfolio. A common but suboptimal instinct is to simply scale every strategy down proportionally until the total fits within the limit.

Note: A more sophisticated (and often better-performing) approach, when facing a binding leverage constraint, is to concentrate available capital disproportionately in the strategy or strategies with the highest risk-adjusted expected return, rather than spreading the constrained capital thinly and equally across every strategy. This doesn't mean abandoning diversification entirely β€” but it does mean that when leverage is genuinely scarce, capital should flow preferentially toward your highest-conviction, best-validated edges rather than being mechanically spread proportional to your unconstrained ideal allocation.


6. Putting It Into Practice: A Worked Sizing Walkthrough

Let's tie the chapter together with a concrete, step-by-step example.

The Setup: You've built and rigorously validated (using Chapters 1, 2, 4, and 5) a mean-reversion strategy on a cointegrated spread between two large private banks, with a solid track record across multiple market regimes.

  1. Calculate the raw Kelly leverage using the strategy's historical mean excess return and variance. Suppose this comes out to 4.5x.
  2. Check the shape of the return distribution. If backtested returns show meaningful skewness or fat tails (common for strategies with occasional large drawdowns), don't trust the raw Gaussian-based Kelly number directly β€” run a simulation-based or empirical optimization instead, as described in Section 4.
  3. Apply a safety discount. Even after adjusting for non-Gaussian returns, apply a conservative discount β€” half-Kelly (2.25x, in this example) is a reasonable, widely used starting point, reflecting genuine uncertainty in your mean/variance estimates.
  4. Consider correlation with your other strategies. If you're also running a momentum strategy from Chapter 6 that tends to perform well in different market conditions, the low correlation between the two may justify holding your final leverage closer to (but still below) the single-strategy half-Kelly figure, rather than discounting further purely out of excess caution.
  5. Respect any broker-imposed leverage ceiling. If your total desired leverage across all strategies exceeds what your broker allows, concentrate the constrained capital toward your highest-conviction strategy rather than diluting everything proportionally.
  6. Re-validate periodically. Your mean and variance estimates are not static β€” as market regimes shift (recall the regime-shift warnings from Chapter 1), periodically re-run this entire sizing process rather than locking in a leverage figure indefinitely.

Golden Rule: Position sizing is not a one-time calculation you perform once and forget. It's an ongoing discipline that should be revisited every time your strategy's live performance, or the broader market regime, gives you meaningful new information about your true mean and variance.


7. Key Takeaways

  • The true goal of position sizing is maximizing long-term compounded equity growth, not minimizing discomfort from short-term losses β€” risk should be managed only to the extent it interferes with that growth objective.
  • Optimal position sizing requires holding leverage constant relative to current equity β€” which mechanically means adding to positions after gains and reducing positions after losses, an uncomfortable but mathematically necessary consequence.
  • The Kelly formula (mean excess return Γ· variance of excess returns) gives the theoretically optimal leverage under a Gaussian assumption β€” but overestimating this leverage carries a far more dangerous downside (potential ruin) than underestimating it (merely a slower growth rate).
  • Because of this asymmetry and inherent estimation uncertainty, treat full Kelly as an upper bound, not a target β€” half-Kelly is a widely used, practical compromise that sacrifices some theoretical growth rate for meaningful downside protection.
  • Real strategy returns are often fat-tailed and skewed, not Gaussian β€” for these cases, simulation-based or empirical, historical-return-based leverage optimization is more robust than the raw closed-form Kelly formula, though empirical optimization should itself be validated out-of-sample to avoid overfitting.
  • When running multiple strategies, optimal leverage for each depends on its correlation with the others β€” low-correlation strategies (like combining mean reversion and momentum, per Chapter 6) can support more combined leverage than highly correlated ones; when facing a broker-imposed leverage ceiling, concentrating capital toward your highest-conviction strategy is often better than proportionally diluting every strategy equally.

Coming up in Chapter 9: Having established how much leverage to use under normal conditions, we turn to a complementary set of tools for capping worst-case outcomes β€” stop losses and Constant Proportion Portfolio Insurance (CPPI) β€” exploring why stop losses can help momentum strategies but often hurt backtested mean-reversion performance, and how CPPI offers a way to cap maximum drawdown while still preserving long-term growth potential.

Chapter 8: Position Sizing and the Kelly Formula | Algorithmic Trading 101: Strategies, Backtesting & Risk Management - TradeKaizen