Register
Learn guide

Stress Testing Algo Strategies Under Randomness

A Monte Carlo simulation tests a trading strategy against randomness. Instead of relying on the single sequence of trades in your backtest, it creates thousands of alternative sequences and shows the range of outcomes the same strategy could have produced. It answers a question a backtest cannot: how bad could it plausibly get?

QuantPower Research · Updated 14 Nov 2026 · 17 min read

A backtest gives you one path through the past. The trades came in a particular order, partly by luck, and that order decided how deep the worst drawdown was and how long the worst losing run lasted. Change the order and the same strategy can look much more dangerous. Monte Carlo simulation shows those other orders, so you can size a strategy for the drawdown you are likely to meet rather than the one you happened to see. This guide explains why one backtest understates risk, the main Monte Carlo methods for trading, how to read the results, two worked examples, how to use the results for position size and loss limits, and the limits of the technique.

Monte Carlo simulation at a glance

PartWhat it means
InputThe list of trade results from a backtest or a live record, after costs
MethodReorder or resample those trades thousands of times
OutputA spread of drawdowns, losing runs and final results
What to readPercentiles, such as the 95th percentile drawdown
Main usePosition size, loss limits and deciding whether a strategy's risk is acceptable
What it cannot doPredict returns, invent market events or fix a bad backtest

A short history of Monte Carlo methods

The method was named after the casino. In the late 1940s, at the Los Alamos laboratory in the United States, the mathematician Stanislaw Ulam was recovering from an illness and playing solitaire. He wondered whether the chance of winning could be worked out by playing many random games and counting, rather than by solving the problem exactly. With John von Neumann he turned the idea into a way of solving physics problems with random numbers on early computers. Nicholas Metropolis suggested the name Monte Carlo, and in 1949 Metropolis and Ulam published "The Monte Carlo Method".1

Finance took up the idea in the 1970s. In 1977 Phelim Boyle showed how to price options by simulating many random paths of the underlying price and averaging the payoffs.2 Banks later used the same idea to estimate how much a portfolio could lose on a bad day, a measure called value at risk.

The method most used for testing trading strategies came from statistics. In 1979 Bradley Efron published the bootstrap: estimate how uncertain a result is by resampling the data you have, with replacement, many times over.3 Resampling a strategy's trades is a bootstrap. Later work added block methods, which resample runs of consecutive data together so that patterns such as clusters of losses are kept.4 Trading-system authors such as Robert Pardo brought these tools to strategy testing, alongside walk-forward analysis.5

Why one backtest is not enough

A backtest shows one path: the trades in the order they happened. But the order was partly luck. The same set of trades in a different order can produce a very different maximum drawdown, longest losing streak and final result.

If your strategy's ten worst trades happened to be spread out in history, the backtest shows a mild drawdown. If they had come together, which is entirely possible, the drawdown would have been much deeper. A trader who sizes a strategy on the backtest's drawdown is sizing on a lucky draw.

The same is true of the mix of trades. A backtest of 200 trades might include two unusually large winners. With slightly different market conditions, those two trades might not have happened, and the total result would be lower. Monte Carlo methods show how much the result depends on such trades.

The length of the history matters as well. A strategy tested on two years of data has met only the markets of those two years. If both years were calm, the trade list holds few of the large losses that a volatile year brings, and no amount of reshuffling will create them. Monte Carlo widens the view within the sample; it cannot reach beyond it. That is why it works best on a long test that covers different kinds of market: a sharp fall, a long range, a strong trend, a period of high volatility. When the history is short, treat the simulated drawdowns as a lower bound and size more cautiously still.

There is also a human reason. A drawdown that is twice as deep as anything in the backtest feels like proof that the strategy is broken. Often it is not: it is a normal bad sequence that the backtest simply did not happen to contain. A trader who has seen the Monte Carlo range knows in advance that such a drawdown is possible, and is less likely to abandon a sound strategy at the worst moment.

Monte Carlo methods for trading

Reshuffling trades

Take the list of trade results from your backtest and randomly reorder them thousands of times. Each order gives a new equity curve. Total profit stays the same, because the same trades are in every sequence, but drawdowns and losing streaks change. This is the simplest method and a good starting point. It answers one question: given these trades, how bad could the order have been?

Resampling with replacement

Draw trades at random from your results, allowing the same trade to be picked more than once, until you have a sequence of the same length. Repeat thousands of times. This varies both the order and the mix of trades, so total profit changes too. Some sequences will include the best trade twice; others will leave it out. It shows how sensitive the results are to which trades happened.

Block resampling

Draw runs of consecutive trades, such as blocks of 5 or 10, instead of single trades. This keeps clusters of losses together, as they often are in real markets, where bad trades tend to come in volatile weeks. It usually gives deeper drawdowns than single-trade methods, and is the more honest choice for strategies whose results depend on market conditions.

Varying execution

Add random slippage or extra costs to each trade, or randomly skip a share of trades to simulate missed fills and refused orders. This tests how much the strategy depends on perfect execution. A strategy whose result disappears when 5% of trades are skipped or when slippage doubles is fragile.

Varying parameters

Run the strategy with settings drawn at random from a range around the chosen values, such as stops from 25% to 35% instead of exactly 30%. This overlaps with parameter stability testing and helps detect overfitting: a sound strategy gives similar results across nearby settings, an overfitted one does not.

Which method to use

MethodChangesBest for
ReshufflingOrder onlyDrawdown and losing-run planning
ResamplingOrder and mixHow much the result depends on a few trades
Block resamplingOrder and mix, keeping clustersStrategies whose losses come in groups
Varying executionCosts, slippage, missed tradesFast or high-frequency strategies
Varying parametersThe rules' settingsChecking for overfitting

Most traders start with reshuffling and resampling, and add block resampling for strategies that trade often in volatile periods, such as option selling.

How to read the results

Monte Carlo produces a distribution, so look at percentiles rather than averages. The average drawdown is the drawdown you will usually beat; the 95th percentile is the one you must be able to survive.

MeasureWhat to look at
Maximum drawdownThe 95th percentile: a drawdown that only 1 sequence in 20 exceeded
Longest losing streakThe 95th percentile: how many losses in a row to plan for
Final profitThe 5th percentile: a poor but plausible outcome
Time under waterHow long the equity stayed below a previous peak
Risk of ruinThe share of sequences that fall below a level you cannot accept

Two further checks help. Compare the backtest's own drawdown with the distribution: if it sits near the best end, the backtest was lucky and you should plan for worse. And look at the 5th percentile final result: if it is a loss, a fair share of plausible histories end in a loss, and the strategy's edge is thin.

A worked example: reshuffling a backtest

Histogram of maximum drawdowns from 10,000 reshuffles of the same 200 trades, with the backtest, median and 95th percentile marked (illustration)

This is a hypothetical example.

A strategy's backtest has 200 trades with a total profit of ₹1,50,000 and a maximum drawdown of ₹40,000. After reshuffling the trades 10,000 times:

  • The median maximum drawdown is ₹46,000.
  • The 95th percentile maximum drawdown is ₹68,000.
  • The 95th percentile longest losing streak is 11 trades.

The backtest's ₹40,000 drawdown was better than most possible orders. Planning around ₹68,000 is more realistic. If ₹68,000 is more than you could tolerate, reduce the position size before going live.

The losing streak matters too. Eleven losses in a row will happen in about one sequence in twenty. If you would stop trading the strategy after seven losses, you will probably stop it at some point during a normal run of bad luck. Either accept that eleven is possible, or choose a strategy you can stay with.

A worked example: risk of ruin on a small account

This is a hypothetical example.

A trader has ₹3,00,000 and decides that a fall to ₹2,00,000 would end the strategy, because they would stop trading it. Their option strategy's backtest has 150 trades at one lot, with an average result of ₹900 a trade after costs and a maximum drawdown of ₹55,000.

They resample the trades with replacement 10,000 times, each run of 150 trades:

  • At one lot, 3% of runs fall by ₹1,00,000 or more at some point.
  • At two lots, every result doubles, so a fall of ₹1,00,000 at two lots is the same as a fall of ₹50,000 at one lot; 21% of runs reach it.
  • The 5th percentile final result at one lot is a profit of ₹38,000; at two lots, ₹76,000.

Two lots double the expected profit, and multiply the chance of reaching the stop level about seven times. For this trader, one lot is the size that fits the account and the limit. The final result looks better at two lots only if nothing goes wrong on the way.

A worked example: two strategies with the same average

This is a hypothetical example.

Two strategies each made ₹1,20,000 over 120 trades in their backtests, an average of ₹1,000 a trade after costs.

  • Strategy A is an option-buying breakout. It loses small amounts often and wins large amounts now and then: 35% of trades win, with an average win of ₹5,000 and an average loss of about ₹1,150.
  • Strategy B is an option-selling strategy. It wins small amounts often and loses large amounts now and then: 80% of trades win, with an average win of ₹2,250 and an average loss of ₹4,000, but with three losses of over ₹20,000 each.

On the backtest, A's worst drawdown was ₹31,000 and B's was ₹38,000: not very different. The resampling results tell a different story:

Measure (10,000 resampled runs)Strategy AStrategy B
95th percentile maximum drawdown₹44,000₹71,000
95th percentile losing streak14 trades4 trades
Share of runs that end in a loss9%12%
Effect of leaving out the three largest single tradesProfit falls by halfProfit rises by more than half

The two strategies have the same average and similar backtest drawdowns, but different risks. A's danger is a long run of small losses, which tests the trader's patience. B's danger is a few large losses, which test the account. Neither result says which is better; it says how to size each and what to expect. A trader who knows that B can lose ₹71,000 in a bad sequence will size it smaller than A, even though its backtest looked calmer.

Monte Carlo for option strategies

Option strategies need extra care in a simulation, because their results depend on events that a simple reshuffle can blur.

  • Losses cluster around events. Sold options lose most on days with large moves: results days, policy announcements, budget days, sharp global moves. Those days are not spread evenly; they come in groups. Block resampling keeps them together.
  • Gaps are not in the trade list. A backtest that exits on a stop at the next minute's price assumes the price passed through the stop. On a gap opening, the price jumps past it. Add a few gap losses to the simulation, larger than the stop, to see what they do to the drawdown.
  • Expiry days behave differently. Strategies that trade on expiry day often have their largest wins and losses then. Simulate expiry-day trades separately, or check that the mix of expiry and non-expiry trades in each run is realistic.
  • Rule changes split the history. Expiry days moved to Tuesday on the NSE from 1 September 2025, and contract sizes were raised from 20 November 2024. Trades from before and after these changes may not belong in the same pool.
  • Margin can bind before the loss limit. A large loss on a sold option also raises the margin needed to keep the position. A simulation in rupees of profit and loss does not show a margin call; check separately that the account can carry the worst positions.

For option selling in particular, the 99th percentile drawdown is often a better planning number than the 95th, because the losses that matter are rare and large.

What a good result looks like

There is no single passing score, but strategies worth trading usually show:

  • A 95th percentile drawdown that fits comfortably inside the trader's limit at the chosen size.
  • A 5th percentile final result that is still a profit, or a small loss the trader can accept.
  • A losing streak at the 95th percentile that the trader is confident they would sit through.
  • Results that do not depend on two or three trades: leaving out the best few should reduce the profit, not erase it.
  • Similar results when slippage is raised or a share of trades is skipped.

A strategy that fails several of these is not necessarily wrong, but it is riskier than its backtest suggested, and the size should reflect that.

Using Monte Carlo to judge live results

Once a strategy is live, the simulation becomes a yardstick.

  • A drawdown inside the simulated range is normal. A drawdown at the 70th percentile of the simulation is bad luck, not evidence that the strategy has stopped working. Stopping a sound strategy there is one of the most common and costly mistakes.
  • A drawdown beyond the 99th percentile is a signal. It suggests the market, the execution or the strategy itself has changed. Pause and review before trading on.
  • A losing streak longer than any simulated is a similar signal.
  • Results consistently below the 5th percentile path after several months mean the live strategy is not the one that was tested; check fills, costs and rule differences.

Writing these thresholds down before the strategy goes live turns a stressful decision into a rule. It also guards against the opposite mistake: keeping a broken strategy running because "drawdowns happen".

Using Monte Carlo for position size

Monte Carlo results feed directly into sizing. If you are willing to accept a maximum drawdown of ₹50,000 and the 95th percentile drawdown at one lot is ₹68,000, one lot is too large for your limit, and you need a smaller strategy or a larger account.

A simple method:

  1. Decide the largest drawdown you would accept, in rupees, before you look at the results.
  2. Run the simulation at one lot and read the 95th percentile drawdown.
  3. Divide your limit by that drawdown and round down. That is the number of lots that fits.
  4. If the answer is less than one, the strategy is too risky for the account as it stands.

The position size calculator and the Kelly criterion guide cover other ways to size a trade; Monte Carlo is the check that the chosen size survives bad sequences.

Using Monte Carlo for loss limits

The same results can set loss limits. A daily or monthly loss limit should be wide enough that normal bad luck rarely hits it, and narrow enough that hitting it means something has changed.

  • From the simulation, read the 95th or 99th percentile of the worst single day or the worst month.
  • Set the limit a little beyond it.
  • If the limit is hit in live trading, treat it as a signal: the market or the strategy may have changed, and the strategy should be paused and reviewed rather than restarted the next morning.

In QuantPower these limits can be set on the account: a daily loss limit refuses new orders once the day's loss reaches it, and Smart Exit squares off every position and stops the algos when the account's profit or loss for the day reaches the level you set. Both cover every connected broker together.

Running a simple simulation yourself

A reshuffle needs only a list of trade results. In Python, with each trade's net result in rupees in a list:

Python
import random

trades = [1200, -800, 450, -1500, 900]  # your full list of net trade results
runs, worst = 10000, []
for _ in range(runs):
    seq = random.sample(trades, len(trades))   # reshuffle; use random.choices(trades, k=len(trades)) to resample
    equity, peak, max_dd = 0, 0, 0
    for t in seq:
        equity += t
        peak = max(peak, equity)
        max_dd = max(max_dd, peak - equity)
    worst.append(max_dd)
worst.sort()
print("median drawdown", worst[runs // 2], "95th percentile", worst[int(runs * 0.95)])

A spreadsheet can do the same with a random-number column and a sort, repeated with a macro. The method matters less than the input: use trades after costs, from a test on data the strategy was not designed on.

Monte Carlo and value at risk

Value at risk (VaR) and Monte Carlo simulation are often mentioned together, and they answer related but different questions.

  • Value at risk asks how much a position or portfolio could lose over a short period, such as one day, at a given confidence level. "A one-day 95% VaR of ₹20,000" means that on about 19 days out of 20 the loss should be smaller than ₹20,000. It is usually calculated from the volatility of prices, or from past daily changes.
  • A Monte Carlo test of a strategy asks how bad a whole sequence of trades could get: the deepest drawdown, the longest losing run, the chance of falling below a level over months.

VaR can itself be calculated by Monte Carlo, by simulating many random price paths for the next day. But a one-day VaR says nothing about a slow run of twenty losing trades, and a drawdown simulation says little about tomorrow's single worst day. A trader running several strategies needs both: VaR for the size of open positions today, and a drawdown simulation for the strategy's long-run risk.

Limits of Monte Carlo simulation

  • It can only reshuffle what you give it. If the backtest's trades are unrealistic, such as fills at prices that were not available, the simulations will be unrealistic too.
  • It assumes trades are independent, unless you use blocks. In real markets losses often cluster, and single-trade reshuffling breaks those clusters, which can understate risk.
  • It does not create new market events. A crash or a gap larger than anything in your history will not appear in the simulation.
  • It does not fix overfitting. An overfitted strategy's trades are the wrong input, and reshuffling them produces confident numbers about a strategy that does not exist.
  • It does not see rule changes. Lot sizes, expiry days and taxes in India have changed several times since 2024; trades from before the changes may not represent the strategy today.

Treat Monte Carlo as a stress test that widens your view of risk, not as a forecast.

Where Monte Carlo fits in strategy testing

  1. Write the rules and backtest them with realistic costs.
  2. Check robustness with out-of-sample and walk-forward testing.
  3. Run Monte Carlo on the out-of-sample trades to estimate drawdowns and streaks.
  4. Size the strategy so the 95th percentile drawdown fits your limit.
  5. Forward test on live prices with test money, then go live small.
  6. Compare live results with the simulated range. A live drawdown beyond the 99th percentile is a strong sign that something has changed.

QuantPower's backtests list every trade with its result after costs, and the option strategy backtest also holds back the last 30% of the period as unseen days. That trade list is the input for a Monte Carlo analysis. Measure the historical drawdown with the max drawdown calculator.

Common mistakes

  • Reading the average instead of the tail. The median drawdown is not the one that ends trading careers.
  • Too few runs. A hundred runs gives unstable percentiles. Use thousands.
  • Using in-sample trades. The trades of a strategy fitted to the same data overstate the edge, and so understate the risk.
  • Forgetting costs. Simulate trades after brokerage, taxes and slippage.
  • Ignoring clusters. For strategies that lose in groups, single-trade reshuffling is too kind; use blocks.
  • Treating the 95th percentile as the worst case. One sequence in twenty is worse, and real markets can produce events beyond any history.
  • Running the simulation once and forgetting it. As live trades are added to the record, run it again; the range should narrow as the sample grows, and a range that keeps widening is a warning.

Where risk testing is going

Three changes are visible. Simulation is cheap: what once needed a research desk now runs in seconds on a laptop or in a browser, so there is little reason to size a strategy on one backtest. Methods that keep the structure of markets, such as block resampling and simulations that change volatility over time, are becoming standard for strategies that trade options. And AI tools now write strategies quickly, which raises the number of strategies a trader can test; with more strategies, the chance of one looking good by luck rises, and stress tests such as Monte Carlo and walk-forward testing become more important, not less.

Start with 500 free tokens

Connect your broker, build a strategy and test it on paper before a single live order goes out.

Frequently asked questions

What is Monte Carlo simulation in trading?

A way to test a strategy by creating thousands of alternative trade sequences from its results, to see the range of possible drawdowns, losing runs and outcomes.

How many simulations should I run?

Thousands. 1,000 to 10,000 runs are common, enough for the percentiles to settle.

Does Monte Carlo predict future returns?

No. It shows how much the results of the same trades could vary, which helps with risk planning and position size.

Should I use reshuffling or resampling?

Reshuffling shows how order affects drawdowns. Resampling also varies the mix of trades. Using both, and blocks for strategies whose losses cluster, gives a fuller picture.

Can Monte Carlo show the chance of losing money over a year?

Roughly, yes. Resample a year's worth of trades many times and count the share of runs that end below zero. The answer is only as good as the trades you feed in, and it assumes the coming year resembles the tested period, which it may not.

What should I do if a live drawdown is deeper than the simulation?

Treat it as a sign that something has changed. Pause the strategy, compare the live trades with the backtest for the same days, check fills, costs and any rule changes in the market, and test any fix before switching it back on.

How many trades do I need for a useful simulation?

At least 100, and more is better. With fewer trades, the simulation can only reshuffle a small sample, and the results say more about that sample than about the strategy.

References

  1. N. Metropolis and S. Ulam, "The Monte Carlo Method", *Journal of the American Statistical Association* 44(247), 335–341 (1949)
  2. P. P. Boyle, "Options: A Monte Carlo Approach", *Journal of Financial Economics* 4(3), 323–338 (1977)
  3. B. Efron, "Bootstrap Methods: Another Look at the Jackknife", *Annals of Statistics* 7(1), 1–26 (1979)
  4. H. R. Künsch, "The Jackknife and the Bootstrap for General Stationary Observations", *Annals of Statistics* 17(3), 1217–1241 (1989)
  5. R. Pardo, *The Evaluation and Optimization of Trading Strategies*, 2nd edition, Wiley (2008)
The examples on this page are hypothetical. Simulated results have inherent limits and do not guarantee future performance. This guide is for education and is not investment advice.