Posts Tagged ‘trading_system’

Monte Carlo Trade System Simulator

April 2, 2009

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):


By way of explanation, refer to the chart legend:


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:




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%:


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…

Testing a New Trading Strategy

February 6, 2009

I’m starting to look at some different things for my trading plan. I have the beginnings of a strategy starting to come together. With my emotional makeup and out-of-phase intuition, a mechanical system, even if I am manually executing it, is absolutely essential to me at this time.

I have a simple mechanical entry indicator, a mechanical trailing stop, and a situationally-based pre-emptive profit target exit. I ran a study on NQ 5 minute charts over the last 20 days, long side only so far. Here’s the intital results for one contract:

Strategy Report
Symbol: /NQ
Work Time: 2009-01-08 – 2009-02-06

Max trade P/L: 684.00
Total P/L 2,751.00
Total 142 order(s)

Win rate was around 50%.

On 142 orders, that would be $497 in commissions, so net $2,254.00 on one contract. This tells me that my strategy has merit, at least for the market environment that we have had. I’ll report more on the exact strategy, along with Think or Swim strategy files, later on as things get more concrete. Plus, I’ll have more detailed reports after I get something that automatically parses the ToS strategy output.