Monte Carlo Trade System Simulator

There’s a lot of discussion out on the web about trading system expectancy. I first heard about it from Trader Mike, and then in Van Tharp’s Trade Your Way to Financial Freedom. If expectancy is a new subject to you, read Trader Mike’s excellent article for definitions and details. Short version:

average win rate * average amount won – average loss rate * average amount lost = expectancy

Or average expected profit (or loss) per trade taken.

So say you know the theoretical or historical expectancy of your system. What could really happen when you start trading (or keep trading)? How many losses could you possibly see in a row? How many losses will you get in a row on average? What happens when the law of large numbers meets a relatively small number of trades (like 200)?

There is a trap in treating expectancy as gospel. It is this: “Past performance is no guarantee of future results!” Taking a series of past trades, you can calculate a historical expectancy. The number accurately describes these actual trade results. However, the expectancy of a trade system is a living thing. Each future trade outcome is unknown, and unknowable. Literally anything can happen. Therefore, system expectancy should be:

1) Monitored and updated as trades are taken to ensure the system remains as you have tested and experienced it,

2) Given uncertainty bands that are representative of different probability outcomes over small trade samples.

Number 1 just protects you from a system that stops working, or alerts you that conditions are changing and your strategy needs to adapt. Number 2 is something that needs a bit more thought. Over a very, very large number of samples, the outcomes of actual results will approach the odds of each outcome happening–the expectancy will match your outcome. But over a very small number of samples, there can be wide variation in what should happen according to the odds, and what does happen in reality. Here’s a few examples:

Say I’m flipping a coin. 50% odds of heads (H), and 50% odds of tails (T). If I flip this coin hundreds of millions of times, probability and expectancy say I should have very close to 50% heads and 50% tails (0.5H and 0.5T). No problem. What if I flip only once? I will have either one heads (1H) and zero tails (0T), or 0H and 1T. Only two possible outcomes. That’s not a 50/50 distribution. But this is a trivial example. Who puts on just one trade? You do, each time you trade. You could get zero or 100% as your outcome. You can’t judge a system on one trade, just as you shouldn’t judge yourself by the outcome of one trade!! (This is written for my benefit as much as yours.)

Back to the example: How about with 3 flips? There are 8 possible and equally probable outcomes now: TTT, HTT, THT, TTH, THH, HTH, HHT, HHH. Now we’re getting more complicated. If you guessed heads each time, you could end up with 0 wins, 33% wins, 67% wins, or 100% wins. Not exactly 50/50, but better than the results for 1 flip.

Lets move on–what about 200 flips? Rather than do that by hand, I used my Monte Carlo Analysis tool. This tool simulates a series of occurrences to get the outcome distribution, then does it again and again, as many times as you specify. Each simulation is a randomized outcome based on the odds of each result happening (win or loss) over a series of trades. If you repeat the simulation many times, the variations of outcomes can be seen. We let “reality” present itself rather than try to predict and model what will happen. That’s what Monte Carlo methods are all about.

Here’s my results for flipping a coin 200 times in a row, and then repeating that experiment 100,000 times (took 44 minutes to run):

sim_overview

By way of explanation, refer to the chart legend:

sim1

Each point of the green line is the peak net profit encountered for that trade over all 100,000 simulations. Similarly, the red line is made from the peak net losses encountered at each trade. No one outcome distribution matched either of those lines. Rather, it is a composite of all 100,000 simulations for each of the 200 trades taken. Most trade outcome distributions will fall within these lines, though they may touch them at some point. The probability of reaching this envelope is much higher in the beginning few trades, and gets less and less likely as you get more and more samples and the law of large numbers kicks in. The white line is the simple midpoint of the high and the low PnL lines. The blue line is the current outcome distribution for the last 200 trade simulation that has been run.

As you can see from the overview picture, over our large sample size (20 million coin flips overall) the simple median outcome distribution is very near 50/50, though any random group of 200 outcomes can end up above or below that. Also, note that the largest losing streak encountered was 22 in a row! The average losing streak was 6.98, meaning that over 200 trades with these probability parameters, it is common and actually likely that you will see at least 7 losses in a row. If you risked 15% of your capital on each trade, you would have even odds of blowing out your account. If you risked only 7% of your capital per trade, you would on average experience at least one 50% drawdown at some point during the 200 trades. Also note that every single simulation had a losing streak of at least 3 in a row. So if you get three strikes, you’re not out, you’re just living in the world where reality meets probability. Seven losses in a row? Par for the course for flipping 200 coins, on average.

After running the 100,000 simulations to populate the red and green lines, you can Re-Calculate a new 200 trade run to see how it stacks up next to the extreme values. Here are a few more interesting plots showing some different outcomes that can happen:

sim_hi

sim_lo

sim_mid

All 50/50 theoretical odds, yet you can be a net winner, a net loser, or some of each over a finite number of trades. This also says to me that a small edge, e.g. 55% win, 45% loss, is no better than random chance over small (i.e. real life) sample sizes. High consistency beats sporatic home runs, hands down.

Now imagine if you had a system that only had a 33% win rate, but an average win amount to loss amount ratio of 3:1? That has a positive expectancy, but real life could bite your head off with a streak of 11 losses in a row on average! Look at this outcome, where you got 74% losses instead of the expected 67%:

sim2

Ouch. Did you “expect” that outcome? BOOM HEADSHOT!

The need for systemic risk management becomes clear; you need to know more than just “where’s my stop loss on this next trade”. You also have to size your positions to withstand the likely string of adverse outcomes (commonly known as a run of bad luck). You must also forge your psyche to withstand the losses or wins that will probably come to you in groups. Again, this is for me as much as it is for you. In summary, if you make something like 20 million trades, your results should match your expectancy, and your broker will be rolling in a pile of money. If you take a more realistic number, like 200, not so much. All because probability is an average over very large samples, while each trade is a binary: 1 or 0, all or nothing.

So what sort of variance could you see with your current system’s expectancy? What edge do you need in terms of win rate vs. loss rate, and average winner vs. average loser in order to make sure you don’t draw down your account dramatically? How much (or how little) of your account should you risk per trade to deal with the number of losses in a row your system may (and probably will) encounter?

Download MonteCarloAnalysis.xls* and find out! Remember to enable macros.

*By downloading this, you agree that Prospectus is awesome. And that you should some money. And you never call anymore. We used to be close…

Tags: , , ,

11 Responses to “Monte Carlo Trade System Simulator”

  1. manatrader Says:

    Donation, check, awesome, check, great post. I used something similar recently woodshedder posted on, Equity Monaco, it uses your win/loss amounts and randomizes. Cheers

  2. Read the Prospectus :: Move the Markets :: Entries :: Says:

    […] name tells you right away that he has a gift for writing entertaining material. His most recent post about monte carlo simulations is a great example of how he can be informative, as […]

  3. eaglex Says:

    nice info thx for sharing

  4. Bill Smith Says:

    Great stuff! I’ve played with a few of these simulators and this is one of the better ones.

  5. Prospectus Says:

    Thanks, Bill! I must say that I got inspiration from some of the other simulators out there. That’s one reason I released this tool with the code unlocked and donation optional. My programming wouldn’t be where it is today if I hadn’t been able to learn from the efforts of others. I’m not running a very good business here (or am I)? Time will tell, but I have the heart of a teacher, and money or not, teach I will. Thanks to all my readers and donors. May they continue to grow into one group 😉

  6. Cuervos Laugh Says:

    Nicely written up. I think I’ll be hanging around here some now that I’ve stumbled onto it.

  7. Prospectus Says:

    Hey, Cuervos, glad you’re here.

  8. 8f0mph Says:

    Nice work.

    Your scripts, and excel samples are a great addition to TOS’s limited thinkScript docs—Which I am struggling through. Your blog and commentary are first-class.

    My two-cents on your Monte Carlo work:

    In my experience MC methods can be used at **TWO** very distinct ends of the TA puzzle:

    1) Strategy Measurement & Expectation
    — Which your simulator does (extremely) nicely

    **AND**

    2) Strategy Selection & Optimization
    — Which (in my opinion) is a much more beneficial tool

    If you are interested in using an MC generator for Strategy Selection, take a look at:

    David Aronson’s, “Evidence Based Technical Analysis”, Wiley, 2006.

    Chapters 4-6 will **REALLY** complement the work you have done on the MC generator.

    I’d be interested in your thoughts (if you can find the time) on Aronson’s methods.

    Problem is:

    I can see no way to implement Aronson’s work via thinkScript within TOS.

    That’s my summer project!

    Thanks again for untangling the thinkScript juggernaut!

    –850mph

  9. Risk of Ruin - Psychology and Money Management Says:

    […] on Monte Carlo simulation and a few images from his Excel Monte Carlo simulator (attached): Monte Carlo Trade System Simulator Read the Prospectus Please register to view the post attachment(s) – it's simple and free. Please register to view […]

  10. Trad Says:

    When I increase comm size, I get BETTER results. It appears that comm should be negative, but the worksheet does not allow me to enter negative values.

  11. Prospectus Says:

    Negative values should show up with (parenthesis) around them. Is it doing that?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: