## Monte Carlo analysis explained

Monte Carlo is one of the most precious statistical tools which can be used for testing the robustness of a system. It is widely used in mathematical problems where you are not able to apply a deterministic algorithm. Monte Carlo method consists in defining an initial domain of possible inputs, generate inputs randomly from a probability distribution over that domain, perform a deterministic analysis of the results and selecting the best and worst results. That’s exactly what we need to find out: when a strategy is considered failed and should be dropped and what is the maximum drawdown we can expect from a system.

But first, here is an example: suppose you have a numbered target and a pistol. You can fire 5 shots. After that, you add the numbers you previously shoot in. Let’s say that the sum is 20. The question is how valid is that result? Does is show your real shooting skills or you were just lucky?

The simplest solution to answer that dilemma is to keep shooting 5 times/session and keep adding the numbers when the session ends. If you registered almost the same results after 100 shooting sessions then your skill is confirmed. If not, you were just lucky. I have just described Monte Carlo in the most simplest terms I could find, but let’s give a real world example.

Forex Fancy Bot is one forex robot I coded. After backtests, it shows the following characteristics:

Trades: 2788

Average profit trade in pips: 40,90

Average loss trade in pips: -20,73

Won trades: 44,12%

Lost trades: 55,88%

*Before applying Monte Carlo method I must warn you of something and please keep that in mind: backtests shows past performances only, in this case Monte Carlo analysis is valid is long as the market doesn’t change that much in order to invalidate the strategy completely! If Monte Carlo Worst Case Scenario (MCWCS) is reached, then the strategy no longer works and should be dumped.*

Ok, let’s begin by defining our initial domain: 2788 trades out of which 55,88% are lost trades and 44,12% are won trades. Our 2788 trades string looks something like this:

WWLWWWLWLLLLLW (W – won trade, L – lost trade)

For every won trade we add 40,90 pips and for every lost trade we substract 20,73 pips.

Second step is to generate 100,000 such strings and repeat the above operations. For each session we write down the drawdown in pips (as the difference between the previous equity higher high and lower low).

Third step consists in finding out the maximum drawdown we should expect. This is nothing more than finding the maximum drawdown in pips for previously generated 100,000 sessions.

The maximum drawodown out of 100,000 session is the worst case scenario you should expect. But real life conditions are harsh (missed trades, increased slippage, disconnects from broker, different broker feeds, etc) therefore you should add 10% to that worst case scenario. 10% represents the statistical accepted error.

If the drawown exceeds this value, then the strategy is no longer valid.

Thanks for reading! If you liked it, please share ðŸ™‚