System development final step: Money management, Monte Carlo and a review

February 28, 2013 06:00 PM

Like most system development, the journey determines the destination. In developing this system, we first collected data with our basic random entry system and used that data to optimize our initial rules (“Guide to system development,” September 2012). Next, we discovered that by revising our entry time, to 4 a.m. from 8 a.m., we could induce the system to be profitable. (Perhaps not coincidentally, 4 a.m. is the end of the first hour of the London forex session.) This change yielded a profitable system with a positive expectancy. We  then could proceed with optimizing our initial stop loss and profit target parameters (“How to set up profit targets and control losses,” December 2012).

Optimizing the stop loss resulted in a reduction of the net profit by nearly 50%, but in return we gained the ability to limit and quantify our risk for each trade. As we shall see, the ability to quantify our risk plays an important role when we address possibly the most important step of system development: Money management.

Unfortunately, we didn’t fare as well with optimizing the profit target, which resulted in wiping out nearly all of the already reduced profit. This was unacceptable, and thus a predetermined profit target was removed from consideration. The original time-stop exit — that is, exiting the trade at the end of the trading session, or 5 p.m. — will be used in the money management phase (see “Time and trailing stops,” last page).

In the money management phase, a trade-size algorithm will be added to the random entry system with an initial stop loss. After that phase is complete, we’ll apply a simplified form of Monte Carlo simulation to determine if our profitable results (if any) truly are because of the system having an edge — that is, the ability to identify and exploit a repeating pattern of market behavior.

Money management

There are many money management techniques, but for our purposes we’ll employ a simple fixed-fraction scheme. This method involves using a constant fraction of the account balance (usually expressed as a risk percent) to calculate the size of the trade. Because our model system trades the forex market, trades are sized in terms of lots (in the stock market, trades would be sized in terms of shares of stock, and in the futures market, in terms of contracts). The formula for calculating the trade size is:

Lots = (Account Balance x Risk Percent) / Initial Stop Loss

For example, assume a starting account balance of $10,000, a risk percent of 2% and an initial stop loss of 40 pips (because we are trading with mini-lots at $1/pip, this is equal to $40):

Lots = ($10,000 x 2%) / $40
Lots = $200 / $40
Lots = 5 

The trade would be entered with a trade size of five lots. 

As noted previously, the general advice to traders is to restrict per-trade risk within a range of 1% to 3% of the account balance. Thus, we will run our optimization using this range, and will use increments of 0.25% to fine-tune our trade size. This results in nine possible values of our risk percent.

Our optimization runs will follow the pattern set down in the second part of our series: A six-month in-sample optimization followed by a two-month walk-forward test, using the data from January 2010 through December 2011 as before. This time, we will optimize on two variables simultaneously: The initial stop loss and the risk percent. For the initial stop loss, we will use the same range as before (40-88 pips in increments of two). This results in 25 possible values of our initial stop loss. The total number of combinations that must be tested is equal to the product of both sets of values (9 x 25 = 225 combinations). Fortunately, because of the speed of modern computers, this will take two minutes or less.

In our previous optimizations, we held the lot size constant at one lot. As such, the drawdowns experienced during the optimization runs were not excessive, and we focused on net profit as the criterion by which to choose the best parameter from that optimization set. However, when using lot sizes greater than one, drawdowns can, and do, become excessive. Therefore, we will attempt to find the sweet spot in our optimization set: The best compromise between net profit and a drawdown that does not exceed 10% of our account. (We can stretch that up to about 12% if the net profit warrants doing so.)

The results of the full optimization are far better than were expected: Net profit increased from $775.92 to $4,431.48. Expectancy was slightly less than before at 1.164 vs. the previous 1.19, but that was more than compensated for by proper trade sizing and money management. Also, despite a winning percentage of only 45%, the system still turned a profit. The full results are shown in “Strategy tester report” (below).

Monte Carlo simulation

The final results of our optimizations are encouraging, but first we must determine whether the results are because of the system exploiting a reliable pattern of market behavior or if it’s a happy coincidence between the current market environment and the order of our trades. (Of course, we are using a random system; any edge would result from the optimized price and time stop controls.)

To answer this question, we turn to Monte Carlo simulation, which was invented in the 1940s by scientists working on the Manhattan Project. They used statistical sampling to help in modeling thermonuclear reactions. In situations where mathematical models of a process are either too complex or difficult to derive, using many simulations of the process can provide the information necessary with a high degree of accuracy.

For trading purposes, the one criterion that can be simulated easily is the order in which trades occurred. A proper Monte Carlo simulation involves running 1,000 or more trials where the order of the trades is randomized and the results tabulated. Sophisticated software exists for automating this process, as well as some simpler programs that work within Microsoft Excel. We will load the merged data from our walk-forward tests into a simple Excel spreadsheet; the trade order then is manually randomized. We will restrict the simulation to 120 trials.

However, it is not enough simply to scramble the trade order and add the wins and subtract the losses. The basic commutative property of arithmetic tells us that no matter the order of the trades, the final result is always the same. Yes, the equity curves will vary substantially, and in some instances the account balance may become negative (which in reality would result in the cessation of trading), but such an analysis would have little value.

For each simulated trade order, we will use the following procedure:

  1. Calculate the number of lots traded with the trade-size algorithm using the current account balance and the initial stop loss that was in place for the current trade.
  2. Multiply the number of lots by the actual number of pips won or lost on that trade to determine the dollar amount won or lost. Remember, in our system, one pip = $1.
  3. Add or subtract that amount from the account balance to obtain a new account balance.
  4. Repeat steps one, two and three for all remaining trades.

By doing the simulation this way, the running account balance accurately reflects the effect of the trade size algorithm in determining the amount of profit or loss for a given trade, regardless of the order in which that trade occurs.

“Equity curve madness” (above) is a composite of 16 representative equity curves created by the spreadsheet for each of 16 randomized trade orders. These equity curve screenshots were taken at random from the set of simulations. These simulations fell into the following categories in terms of their bottom-line profitability:

  • Positive net profit: 112 (93.33%)
  • Breakeven (+/–$50 or less): Two (1.67%)
  • Negative net profit: Six (5%)

Though it would be better to run 1,000, these simulations clearly demonstrate the advantage of running the Monte Carlo analysis. As can be seen from the shape of the equity curves, the results run the gamut from nearly flat to wide fluctuations in trade-by-trade equity. Compare these to the equity curve from our walk-forward tests: None exhibits the relative smoothness of that curve. This information is needed before deciding to deploy a system: Whether or not the potential exists for wide swings in the day-to-day equity of the system. Clearly, that potential exists with our random entry system.

This series has provided a framework for developing automated trading systems. We started with our market model, and then collected data using the simplest system based on that model. Applying statistical analysis, we derived maximum adverse excursion and maximum favorable excursion data for use in finding optimal stop losses and profit targets.

Along the way, we discovered that the base system had a negative expectancy, but that a simple change of a single parameter turned expectancy positive, saving the system from the trash heap. Adding a stop loss produced an acceptable compromise between reduced profit and limitation/quantification of risk, but adding a profit target reduced profit too much to be acceptable. The profit target was discarded, leaving the system time stop as the sole means of exiting trades. 

Applying money management in the form of the trade size algorithm demonstrated the importance of having a stop loss to quantify risk. We also saw how proper trade sizing could increase profitability greatly. Finally, Monte Carlo analysis demonstrated that the system is robust as the majority of simulations produced profitable results. However, the Monte Carlo analysis also demonstrated that the system will tend to produce wide fluctuations in equity such that, despite its seeming robustness, it would be unwise to deploy the system in the markets trading real money without further modification.

One purpose of this series was to reflect the real issues and frustrations, as well as the triumphs, surrounding the development of an automated trading system. To that end, these articles were written in real time: The results of the subsequent step were not known prior to completing the previous installment. There was no attempt to massage data to depict a perfect up-sloping, linear equity curve. It is often the case that an idea that seemed so promising in our minds turns out to be a losing proposition. When you are searching for a diamond in the rough, you have to dig through a lot of dirt to find it.

Time and trailing stops

The system under study incorporates a time stop. The trade exits at the end of the New York forex trading session regardless of profit or loss. This would be a session-based time stop. Another type would be the period-based time stop. The trade is closed after some number of chart periods have elapsed. For example, if a trade fails to show a profit after a certain amount of time, it is closed by the time stop.

Another important stop is the trailing stop. As its name implies, this stop trails the market in an attempt to lock in a portion of accumulated profit. A trailing stop moves only in the direction of profit, with the frequency and distance of its moves determined by the trader or system developer. When the market retraces, the trailing stop stays where it is.

For our model system, a trailing stop could be a better alternative to profit management than the use of the profit target.

Neil Rosenthal is a retired dentist who trades his own account. He also is an experienced computer programmer. He can be reached at

About the Author

Neil Rosenthal is a retired dentist who trades his own account.  He also is an experienced computer programmer.  He can be reached at