Newsletter
Article Library
Videos
What's New
About Us
Site Map
Search

 

Unlimited Systems

Auto-generate unique

trading strategies for

TradeStation.

 

Position Sizing Tool

Position sizing software for

trading. Trade smarter.

Maximize results.

 

 

The Breakout Bulletin

The following article was originally published in the April 2005 issue of The Breakout Bulletin.
 

Optimizing Over Multiple Markets

Most mechanical trading systems have one or more parameters, such as the length of a moving average or the size of the money management stop. Ideally, there should be a rational method for choosing values for these parameters. Optimization is one such method. However, the topic of system optimization tends to divide traders. On one side of the debate are those who contend that any optimization is bad and will at best produce parameter sets that are no better than ones chosen at random. On the other side are traders, such as myself, who believe that we can do better than picking numbers out of a hat.

 

In past issues of this newsletter, I've tried to address some of the issues and possible solutions to the problems of system optimization. For example, I've tried to make a distinction between prudent optimization (a good thing) and over-fitting a system to the market (a bad thing). In the May 2003 issue, for example, I looked at least-squares curve fitting and significance testing for possible guidance. While significance tests, at least of the type I discussed, need to be interpreted somewhat loosely, they do tell us one important thing: the more trades in the optimization sample, the less likely the system will be over-fit to the market.

 

As I discussed in the November 2004 issue, optimizing over a large sample of trades can sometimes be tricky because profits over one specific time period can bias the results towards that time period if you're optimizing for net profit or rate of return. To address this, I presented a method (and EasyLanguage function) that makes it easier to optimize effectively over large trade histories. But what if you don't have a large sample of trades from your primary market?

 

One possibility is to optimize the system simultaneously over multiple markets and choose the parameter values that work best (in some sense) over all markets together. Not only will this increase the number of trades in the optimization sample, but it will expose the trading system to a wider variety of market conditions than if you had optimized over just one market. The premise of this article is that a parameter set that works well over several markets may be more likely to hold up well in the future than a parameter set tailored to a single market.

 

In TradeStation, it's not possible to optimize a trading system over more than one market. To make this work, then, we need a sort-of hybrid approach. We'll do the optimizations in TradeStation for each individual market, then bring them all together in Excel, where we'll find the overall winner. In TradeStation, we'll optimize the system for each market using the EqtyCorr function presented in the November 2004 issue (referenced above). The EqtyCorr function records the system parameter values and optimization objective function for each combination of parameters evaluated during the optimization. Since TradeStation iterates through every possible combination of parameter values, the output of the EqtyCorr function is a list of every possible combination of parameter values with the corresponding objective function values. An example is shown in Fig. 1.

 

 

EqtyCorr function output 

Figure 1. Typical output of the EqtyCorr function opened in Excel. The objective function (combination of weighted profit and correlation coefficient) is shown in column A, followed by the weighted profit in column B and the correlation coefficient in column C. The remaining columns list the system parameter values. Each row represents one trial or iterate of the optimization.

 
The first step, then, is to generate a file similar to that shown in Fig. 1 for each market. We do this by optimizing the trading system over each market using the EqtyCorr function. We need to make sure that each optimization uses the same ranges and increments of the system parameters. This will be necessary for step two.
 
Step two is combining the spreadsheet files for each market into a single spreadsheet. We do this by copying and pasting the columns for each market side-by-side. The resulting spreadsheet should look something like Fig. 2. The first set of columns are the same as shown in Fig. 1. To the right of those are three columns copied from the EqtyCorr generated file for the NQ (E-mini Nasdaq) market. The columns for the parameter values will be the same in each file (assuming we've used the same ranges and increments for the parameters, as advised above), so I've only copied the three columns related to the objective function. To the right of the three columns for the NQ are the three columns for the ER2 (E-mini Russell 2000). Other markets could be added to the right if desired.

 

Combined EqtyCorr results 

Figure 2. Combined spreadsheet with EqtyCorr function results for all markets.

 
To find the parameter value set that works best over all markets, we need an objective function for the combination of markets. The objective function is a measure of how well the system performs. The objective function produced by the EqtyCorr function is a weighted average of the net profit and the correlation coefficient of the equity curve. It basically says we want a high net profit but also a straight equity curve. This objective function is listed in columns A, J, and N of Fig. 2. For the combined result, we'll take an average of these individual objective functions and divide by the standard deviation. The result is shown as column R in Fig. 3.
 
 
Combined spreadsheet with objective function
 

Figure 3. Combined spreadsheet with overall objective function in column R. The overall objective function is the average of the objective functions for each market divided by their standard deviation.

 

The Excel formula for column R is as follows:
 
R2=AVERAGE(A2,J2,N2)/STDEV(A2,J2,N2)
 
where columns A, J,  and N contain the individual objective functions for each market. Cell R2 is "filled down" to the other cells in column R.
 
The "best" parameter set will be the one with the highest value in column R. Dividing by the standard deviation of the individual objective functions means that the overall objective function will be higher when the individual objective functions are similar in value. This helps prevent an unusually strong result in one market from biasing the results towards that market at the expense of the other markets. We want a parameter set that gives good results in all markets, even if the results are not optimal in any one market.
    

The final step is to sort the columns by the values in column R (in descending order) using the Sort command of the Data menu in Excel. This will put the row with the highest value of the objective function at the top of the spreadsheet. The parameter values in columns D through H in the top row will be our optimal parameter set.

 

As an example, consider the West Coast Index system. This system has one input parameter for entering trades and four for exiting (two for longs and two for shorts), for a total of five input parameters. We want to find the best set of parameter values for trading the system on the four major E-mini stock index futures at the CME exchange: ES (E-mini S&P 500), NQ (E-mini Nasdaq 100), ER2 (E-mini Russell 2000), and EMD (E-mini S&P MidCap 400).

 

The first parameter was varied from 15 to 45 in increments of 5. The next two were varied from 3 to 9 in increments of 1, and the last two from 1 to 5 in increments of 1. The same ranges and increments were used for all markets. This resulted in a total of 8575 tests per market (and therefore 8575 rows of data in the spreadsheet). Slippage and commission costs of $30 per round turn were deducted from each trade. After running each individual optimization, the output files from the EqtyCorr function were combined into a single spreadsheet and the objective function was defined as shown above. After sorting the rows in descending order of the objective function, the resulting spreadsheet is as shown in Fig. 4.

 

 

Combined spreadsheet for West Coast Index

 

Figure 4. Combined spreadsheet for West Coast Index system with results sorted in descending order of the overall objective function (column V). The optimal parameter values are in columns D - H in row 2.

 

The overall objective function is shown in column V, where the highest (optimal) value is at the top in row 2. The optimal parameter values are shown in columns D - H in row 2: 25, 5, 5, 4, 5. These are the parameter values that maximize the objective function and therefore give the best historical performance over all markets, as defined by the objective function.

 

The individual equity curves for each market obtained using the optimal parameter values are shown in Figs. 5 - 8. The number of trades generated by the system is not very large in any one market, ranging from about 55 to 80 trades per market. However, when you combine the trades into a single portfolio equity curve, as shown in Figs. 9 and 10, there are 270 trades in all. That larger number of trades should give us confidence that the system has not been over-optimized. Moreover, the fact that the same set of parameter values works well in four different -- albeit correlated -- markets further increases the chances of the system holding up well in the future. Also note that the equity curve for the portfolio, as shown in Fig. 9, is smoother and straighter than any of the individual equity curves -- one of the virtues of diversification.
 
Equity curve, WCI, ES, optimal parameters

Figure 5. One-contract equity curve for the West Coast Index system on 30 min bars of the E-mini S&P 500 using parameter values optimized over the ES, NQ, ER2 and EMD markets simultaneously. $30 was deducted from each trade for slippage and commissions.

 

 

Equity curve, WCI, NQ, optimal parameters

Figure 6. One-contract equity curve for the West Coast Index system on 30 min bars of the E-mini Nasdaq using parameter values optimized over the ES, NQ, ER2 and EMD markets simultaneously. $30 was deducted from each trade for slippage and commissions.

 

Equity curve, WCI, ER2, optimal parameters

Figure 7. One-contract equity curve for the West Coast Index system on 30 min bars of the E-mini Russell 2000 using parameter values optimized over the ES, NQ, ER2 and EMD markets simultaneously. $30 was deducted from each trade for slippage and commissions.

 

Equity curve, WCI, EMD, optimal parameters

Figure 8. One-contract equity curve for the West Coast Index system on 30 min bars of the E-mini S&P MidCap 400 using parameter values optimized over the ES, NQ, ER2 and EMD markets simultaneously. $30 was deducted from each trade for slippage and commissions.

 

 

Portfolio equity curve, one-contract, WCI

 

Figure 9. One-contract portfolio equity curve for the West Coast Index system on the ES, NQ, ER2 and EMD markets using parameter values optimized for all markets together. $30 was deducted from each trade for slippage and commissions.

 

 

Portfolio equity curve, fixed risk, WCI

 

Figure 10. Portfolio equity curve for the West Coast Index system with a variable number of contracts on the ES, NQ, ER2 and EMD markets using parameter values optimized for all markets together. 5% of account equity was risked on each trade. $30 was deducted from each trade for slippage and commissions.

 

 

The method presented above can be applied to any TradeStation system, provided you have access to the EasyLanguage code (for adding the call to EqtyCorr). The spreadsheet manipulations involve little more than copying and pasting columns of data. There's only one spreadsheet formula (shown above) that needs to be entered. Of course, the usual admonitions apply when optimizing a trading system: always test out-of-sample and preferably in real-time before committing real money.

 

Notes:

  1. The EqtyCorr function is available for free download.
  2. To learn more about the West Coast Index system or to order, please visit [discontinued].
  3. The portfolio equity curves were generated using Market System Analyzer. For more information, please visit http://www.adaptrade.com/MSA/index.htm.

 

That's all for now. Good luck with your trading.

 

Mike Bryant

Breakout Futures