Select Page

# Monte Carlo Simulation

After out-of-sample testing and walk-forward optimization, we can be reasonably confident that our GBPJPY trend following strategy is robust.

For this final article on robustness testing, we will learn more about this strategyâ€™s risk profile using StrategyQuantâ€™s Monte Carlo simulator. In this instance, Monte Carlo simulation will be used for informational purposes only; there will be no filtering/shortlisting of strategies, although you have the option to do so in StrategyQuant.Â

# Monte Carlo Simulation

With random noise being a perpetual contaminant in every price dataset, your backtest statistics will never be exactly replicated in live trading. Monte Carlo simulations use repeated random sampling to determine the probabilities of obtaining different backtest outcomes, giving you an estimate of how your strategy performance might deteriorate in real-time.

There are two common trading applications of Monte Carlo simulations:

2. Running a fresh backtest with randomized changes in prices/strategy parameters

Both these options are available in StrategyQuant. Here I’ll use the GBPJPY trend strategy to demonstrate the use of the trade sequence randomizer.

Randomizing your backtestâ€™s trade sequence can provide a more reliable estimate of the drawdowns you will encounter in live trading.

Every backtest, no matter how reliable, only represents a single run of your strategy over a certain historical period. Suppose you flip a fair coin 100 times and get 53 heads. If you flip it another 100 times, you are not likely to get exactly 53 heads again.

By randomizing the sequence of trades, the Monte Carlo method simulates multiple equity curves from your single backtest. Since drawdown is affected by the sequence of losing trades, these multiple equity curves can be used to produce a drawdown distribution that is more reliable than a single drawdown value.

Before we go into more detail about these distributions, a brief explanation of confidence levels is required.

# Confidence Intervals for Monte Carlo Simulation

The GBPJPY trend following strategy above produced a 372-trade backtest over the 2003-2020 period. By rearranging the sequence of trades, we can arrive at 372! (372*371*370â€¦*3*2*1) different equity curves. This is an astronomical number which no computer can process in a reasonable time!

We can achieve a compromise by simulating only a few hundred/thousand different equity curves, and then using confidence levels to quantify the uncertainty caused by this simplification.

Confidence levels are a concept borrowed from statistics, and are used to measure the degree of uncertainty in a sampling method. A confidence level refers to the probability that the sampled results contain the true value of a certain parameter.

In trading, we are usually concerned with profits and drawdowns. The typical result from a Monte Carlo simulation would look as follows:

If we use a 95% confidence level, it means there is a 5% probability that the actual profit will be smaller than \$672, and that the drawdown will be larger than \$220. The higher the confidence level, the more the metrics will deteriorate, but the higher the probability that those metrics will encompass your future performance.

# Setting Up StrategyQuant’s Monte Carlo Simulation

The setup options for our Monte Carlo simulation are shown below:

1000 different equity curves will be simulated for our strategy. This should provide sufficiently reliable results without much computational burden. StrategyQuant offers two sampling methods: Exact and Resampling.

In the exact sampling method (also known as sampling without replacement), each trade from the original backtest of 372 trades can only be sampled once. This preserves the strategyâ€™s probability distribution, or its performance profile.

The resampling method (sampling with replacement) allows each trade to be sampled more than once. This will alter your strategyâ€™s probability distribution, and may be preferable if you expect market conditions to change drastically in future, or your original backtest only contains a small basket of trades.

Since our strategy was developed over 16 years, and 372 trades is a decent number, letâ€™s stick with the exact sampling method.

# Monte Carlo Simulation Results

The characteristic â€˜straw broomâ€™ charts produced from the simulations are shown below, together with a table showing performance metrics at various confidence levels.

The blue equity curve reflects the original backtest. Notice how all the overall net profit remains the same for all the equity curves; this is a consequence of sampling without replacement.

Ideally, you want the multiple equity curves to be grouped closely together, indicating consistency across the runs. Looking at the 95% confidence level, we can infer that there is a 5% probability that future drawdowns will be larger than \$311.

This is over twice as large as the drawdown in the original backtest. If you are using historical drawdowns to determine your strategyâ€™s capital allocation, using the Monte Carlo-simulated drawdowns can help you determine a more conservative value. Capital allocation is discussed in more detail in theÂ Portfolio CompositionÂ article.

Note that Monte Carlo simulation is probabilistic in nature, so the equity curves and metrics will vary slightly every time you run the test.

# Limitations of Monte Carlo Simulation

While Monte Carlo simulation can be a great tool for anticipating future risks, it has certain limitations. The following is a non-exhaustive list:

## Overfitting Cannot Be Detected

Monte Carlo simulations assume that the input trades from your backtest reflect your strategyâ€™s true performance; only the sequence of trades is altered. If your backtest is the result of an overfitted strategy, your Monte Carlo performance metrics will be artificially good.

This is an example of the popular saying â€˜garbage in, garbage out.â€™ It is therefore best to input trades obtained from out-of-sample testing.

Similarly, if your original backtest only contains a handful of trades or covers a brief historical period, your estimations will lose their predictive value when market conditions change.

## Serial Correlations Are Not Preserved

Serial correlations may exist in some strategies, whereby the outcome of a particular trade may affect the outcome of subsequent trades.

This is especially prevalent if you are a trend-follower, considering that a large trend is likely to be followed by a period of consolidation. Your trades will thus tend to follow a cyclical pattern â€“ one large winner is likely to be followed by a string of smaller losers.

Due to its random sampling from your original backtest trades, Monte Carlo simulation cannot capture such trade dependencies.

Since 1000 simulations is a sizeable number, the effects of serial correlations should be minimal. Nonetheless, if you feel that serial correlations are important, you may consider doing Monte Carlo simulations on equity curve segments instead, whereby each segment would preserve the series of trades in the original backtest.

## Market Returns Are Assumed to Be Normally Distributed

This assumption is used when computing the performance metrics at each confidence level. If your backtest contains a number of unusually large winners/losers, your metrics may be less accurate.

This can be mitigated if your backtest contains a large number of trades, but regardless, it is best to treat your Monte Carlo results as estimations. A \$1000 drawdown at the 100% confidence level does not mean your future drawdowns will never exceed \$1000; there is no computational method/mathematical model that can entirely replicate the sophistication of the markets.

# Wrapping Up

Monte Carlo simulation randomizes your original backtestâ€™s trade sequence, thereby creating multiple equity curves, each with a different maximum drawdown.

This allows a drawdown distribution to be generated, which can help you arrive at a conservative capital allocation for the strategy.

Alternatively, you can use Monte Carlo simulations to randomize prices and strategy parameters, thereby creating an out-of-sample test.

Through these three articles on robustness testing, I hope I have demystified some of the common test methods available in todayâ€™s commercial software. The importance of strategy robustness cannot be overstated. In todayâ€™s rapidly changing markets, robustness should be the foremost concern of every developer.

In the next stage of our development workflow, we will conclude our individual strategy development by runningÂ tick-precision backtestsÂ on them.

# Strategy Development Roadmap

Supercharge your strategy development with StrategyQuant

Access 14-day FREE trial here!

Get up to USD 300 discount!

Strategies need improvement?

Use QuantAnalyzer’s powerful analysis tools

Try the FREE version here!

Get 20% Discount here!

## Automated MACD Divergence Forex Trading Strategy

The MACD is a simple and effective momentum indicator. Hereâ€™s how you can save screen time by programming a MACD divergence strategy for the GBPJPY!

## Laguerre RSI Trend Following Strategy

The Laguerre RSI attempts to improve the responsiveness of the regular RSI, whilst keeping whipsaw trades to a minimum. Letâ€™s see how well it detects short-term pullbacks for a trend following strategy!

## What Is the Kaufman Adaptive Moving Average?

The Kaufman Adaptive Moving Average is a unique indicator that automatically adapts to the marketâ€™s noise. Here I explain its inner workings and show you how to build a trend following strategy around it.

## What is Fixed Ratio Money Management?

Have you heard of fixed ratio money management? How does it compare to the popular fixed fractional approach? Here I’ll explain how fixed ratio works, and see how it stacks up against fixed fractional money management.

## Build a Diversified Portfolio With QuantAnalyzer

The ability to efficiently trade a diversified portfolio of strategies is one of the biggest advantages of algorithmic trading. Here we will use QuantAnalyzerâ€™s Portfolio Master to build a portfolio consisting of high performing, uncorrelated strategies.

## What Is the QQE Indicator?

The QQE is a mysterious indicator that sometimes pops up in trading forums. Does it deserve a place alongside the more traditional momentum indicators like the RSI and CCI? Let’s add it to a trend following strategy to find out!

## Do Bollinger Bands + Candlestick Patterns Work?

Bollinger Bands are great at detecting overbought and oversold conditions. Letâ€™s use them to develop a countertrend strategy, and then refine our entries using limit entries and candlestick patterns.

## How Good Are The Bollinger Bands’ Trailing Stops?

Trailing stop losses are a popular feature in many trend following systems. Bollinger Bands, the ever-popular technical indicator among retail traders, actually contain two inbuilt trailing stops. Are these any good? Let’s find out!

Hey there, Wayne here! I’m on a mission to develop robust algorithmic trading strategies for the forex markets. Trading Tact is where I share my trading methods and insights.

###### Have a Question?

1. After the Monte Carlo test, I didn’t see you do a slippage test. I believe it is one of the most harshest tests so I think you should not skip it. Any comment? Thanks!

• for trend following with a larger expectancy, a few pips slippage wont make much of a difference. Besides i added in 1 pip constant slippage for the backtest

Supercharge your strategy development with StrategyQuant

Access 14-day FREE trial here!

Get up to USD 300 discount!

Strategies need improvement?

Use QuantAnalyzer’s powerful analysis tools

Try the FREE version here!

Get 20% Discount here!

## Forex Weekend Gaps: Can You Exploit Them?

Have you noticed that forex weekend gaps usually reverse within 3 days? Here I’ll program a mean reversion strategy to exploit gaps over the last 18 years!

## Dynamic Position Sizing: Is It Time to Go Big?

Should you increase your lot sizes for higher probability trades? Let’s code a dynamic position sizing scheme to capture more outsized wins!

## Pivot Points: A Reliable Support & Resistance Indicator

Pivot points are the perfect tool if you trade using support & resistance. Here’s how to develop an automated pivot points forex strategy!

## Money Flow Index: An Improved RSI?

The Money Flow Index is sometimes called the volume-weighted RSI. Can it outperform the RSI in this trend following strategy?

## Trade Slippage: How Can You Simulate and Minimize It?

Are you a victim of excessive trade slippage? Here’s how you can minimize slippage, and more realistically simulate it in your backtests!

## Edge Ratio: A Unique Way to Quantify Entry Profitability

Selecting a profitable entry is a critical step in strategy development. Here I’ll demonstrate how to use the Edge Ratio to maximize your profit potential.

## Do You Know Your System Quality Number?

The System Quality Number measures the profitability & consistency of your trading system. Here’s how to calculate your SQN and use it to improve your trading!

## Automated Bollinger Bands Squeeze Forex Strategy

StrategyQuant’s BBWR indicator is the perfect tool to detect a Bollinger Bands squeeze. Here I explain how it’s calculated, and use it to program a breakout strategy for the AUDJPY!

## Automated Schaff Trend Cycle Forex Strategy

The Schaff Trend Cycle is a unique combination of the MACD and Stochastic indicators. Here’s how you can use it to improve your trend following results!

## Should You Use the Kelly Criterion for Forex Trading?

The Kelly criterion is a famous mathematical formula that attempts to maximize your long-term capital growth. In this post, Iâ€™ll apply it to a EURUSD breakout strategy and explain some of its potential shortcomings when applied to forex trading.

## Forex Intermarket Correlations: How Do You Exploit Them?

Knowledge of intermarket correlations can improve your forex trading win rate. Here I explain three important types of correlations, and how you can use them to benefit your trading.

## 5 Forex Day Trading Challenges & How to Overcome Them

Forex day trading seems to have a particular appeal to new traders. Here I highlight five hidden challenges of day trading, and offer some suggestions on how to overcome them.

## Can a Trading Pause Improve Your Trend Following Results?

A temporary trading pause can improve your win rate if youâ€™re trend following a volatile market. Here Iâ€™ll program a trading pause into a simple breakout strategy, and test its effectiveness on the Widow Maker â€“ the GBPJPY.

## Can Partial Profit Taking Benefit Trend Followers?

Partial profit taking is a dilemma often faced by long-term trend followers. Could this benefit your overall strategy performance?

Letâ€™s test!

## Using Maximum Adverse Excursion for Stop Loss Placement

A catastrophic stop loss is a vital risk management tool for many traders. Here Iâ€™ll show you how to optimize your stop loss distance using maximum adverse excursion.

Hey there, Wayne here! I’m on a mission to develop robust algorithmic trading strategies for the forex markets. Trading Tact is where I share my trading methods and insights.

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!

## Make your money work for you!

Â

Get trading ideas and strategy development tips delivered to your inbox!