From the August 01, 2012 issue of Futures Magazine • Subscribe!

Exchange emulation vs. simulation is the key to robust testing

With the advent of inexpensive high-speed computing, low-latency, high-bandwidth internet access and today’s electronic exchanges that support highly liquid and low-commission markets, there is a continuous press toward high-frequency technical trading. The desire to automate strategies, applying novel algorithms that can be tested accurately before putting real dollars at risk, is a compelling paradigm, both for the professional fund and the individual retail trader.

These developments have many individual traders asking, “How can I participate effectively in the new world of automated, high-speed, technical trading?”

The answer is they can, but they need to be careful because, in a world where profits can be made by exploiting the slightest of edges, any miscalculation in how a system will perform can create huge divergences in testing and real results. 

Trading desk technology continues to evolve and provide ever greater sophistication for the retail trader. Stock, futures, options and forex markets are now readily available with low monthly subscription, data and transaction fees. Trading tools have evolved from simple automated stock market scans to platforms that fully automate execution. Trade entry and exit decisions can be made entirely by software and executed within milliseconds. Backtesting strategies against historical data have become the standard and continue to evolve. For example, the latest TradeStation 9 product automates the in- and out-of-sample testing needed to vet a new strategy accurately (see “Software Review,” July 2011).

The next step in strategy testing has been the seamless incorporation of trade simulators. These simulators allow the trader to test manual trade execution as well as fully automated software strategies without putting actual dollars at risk. For the novice trader, the simulators support a risk-free practice of various trade entry/exit and management skills, such as using limit vs. stop orders and scale-in/scale-out execution strategies.

For the algorithmic trader looking to automate execution fully, trade simulators allow for the debugging of trade strategy software and the collection of forward, out-of-sample, test results. These are very useful and much-needed tools for the serious trader. 

However, successful trading depends on a lot more than a viable trading strategy, and simply going through the motions of order entry and liquidation does not accurately reflect real trading. If a simulator offers an inaccurate emulation of the electronic exchange, then it can lead the trader down an unprofitable path. Here, we’ll describe simulation vs. emulation and demonstrate why accurate emulation is integral to developing an accurate assessment of a complete trading approach.

Standard entries

Two key considerations of a trade simulator are:

  • Is the use of a simulator identical to live account trading — that is, are the setup and trade execution procedures identical to actual trading? The user should be hidden from any differences, no matter how subtle, between trading against a simulated account and market, and his or her live account. This includes both manually entered trades and those automated by software.
  • Does simulated trading fill orders on an if-touched basis, or does it implement an exchange emulation that accurately mimics the unfilled limit orders that often are a part of live trading? This last point is key as not every (or most) limit order that is touched is filled.  

In the if-touched case, the simulator will fill an order whenever the price specified in a stop or limit order is reached. In the case of a stop, this is the behavior of the order type and if-touched execution is adequate (though not necessarily at that price). In the case of a limit order, it can lead to different results from those achieved with actual trading. Specifically, it can give overly optimistic performance, and especially so with high-frequency strategies that may be scalping a few ticks at a time from the market.

If a trade simulator is used as a training or software debug tool, then if-touched simulation is adequate. For example, the trader will want to use a simulator to learn a new trading platform and gain practice with its various order entry options and interfaces. It also is useful if the algorithmic trader wants to debug trade automation software. In this case, the developer is not looking to verify the profitability of a trade strategy but needs to work out coding bugs. (Novice algorithmic traders often overlook that trade strategy automation involves developing and testing software, and there are always bugs in software, no matter what the application.)

On the other hand, if-touched simulation can lead to different profit and loss results compared to actual exchange execution. “Golden strategy?” (below) shows the result of an E-mini S&P 500 futures intraday scalping strategy using an if-touched simulation of the exchange, from March through April 2012. While we might believe a trading Holy Grail has been discovered, what we have is a misleading result of if-touched backtesting. This kind of equity curve is easy to produce from a combination of a low profit-target to stop-loss ratio (in this case, approximately one-quarter) and a suitable scalping strategy. (See “Can automated scalping work for retail?” Sept. 2008).

But suppose that rather than the simple if-touched simulator, the simulator emulates the exchange, attempting to provide a more accurate fill rate from limit orders. Then, the trade strategy testing might give accurate profit-loss results and can be used as an honest testbed for developing profitable trade strategies. 

With this approach:

  1. A high-frequency trading strategy is fast-prototyped against historical data. As part of a first pass, if-touched testing can be used (perhaps with a slippage factor) as the developer is making a first approximation to gauge a trading idea.
  2. Once a successful backtest is achieved with in- and out-of-sample data, the trade strategy is moved online with a simulator that emulates the exchange. Initial testing also serves to debug the strategy implementation.
  3. Forward testing of the strategy is conducted with exchange emulation to provide realistic, out-of-sample, forward results. Emulation offers an accurate test environment to develop additional logic to take a strategy to greater profitability.

Emulation example

“Side-by-side” (right) shows actual account and simulated account price ladders for the E-mini June 2012 contract adjacent to each other. The five deep bid-ask queues are shown in the price ladders. Note that the values are identical across live trading and simulation.

The emulator continuously mirrors the exchange order book and inserts the user’s limit orders into simulated bid-ask queues. The software attempts to mimic the exchange order book and move the user’s order up in the queue based on the active trading taking place. In addition, network and exchange delays are inserted in the simulator logic to model these real-world variables. The result is a test environment that approximates the exchange and actual limit order fills.

(Interestingly, the simulation is executed entirely on the end-user’s computer. An alternative, and perhaps even more accurate, but less-scalable implementation would physically mirror the exchange servers, but this probably is outside the scope of a general retail product.)

“Market entry” (below) shows a chart view of the scalping strategy that generated the if-touched equity curve in “Golden strategy?”

The strategy is based on the following logic:

  • If a trend is indicated by measuring the rate-of-change of the 20-period exponential moving average (EMA), then
  • If a lookback of recent price action shows a highest high (long-entry trigger) or lowest low (short-entry trigger) that exceeds a price channel extreme (high and low channel lines on the chart), then a limit order is entered a small number of ticks above (long) or below (short) the 20-period EMA.
  • A profit target of several ticks is used with a profit target to stop-loss ratio of approximately one-half.
  • Various optimized time-of-day and time-to-entry threshold filters are applied to give improved results.

“Market entry” shows cases where the strategy filled, as well as a case where the strategy went unable to fill, based on exchange emulation. The equity curve from March-April 2012 emulation testing is shown in “Accurate analysis” (below). These results give the developer a more correct assessment of the trade strategy. From the forward-test with exchange emulation exercise the developer can better decide if the original trade strategy concept is worth pursuing. 

Many of us have been there. We’ve developed a trading strategy based on sound logic. We’ve honed it on in-sample data. We’ve verified it on out-of-sample data. We’ve even paper traded the approach to get a feel for its performance and logistical considerations in active markets. However, unless you also take into consideration the variable slippage of the market and how that can affect not just the quality of fills but the prospect of getting filled in the first place, you aren’t doing the full due diligence necessary to evaluate a trading strategy completely.

One unavoidable reality of order-entry emulation is that it’s effectively impossible without capable software and fill algorithms designed to evaluate live price data. This is not something you can achieve with a home-grown effort, particularly for the high-frequency strategies for which it’s most effective. That said, few, if any, intraday E-mini traders are operating inside a technological vacuum and adopting order-entry emulation software should be a relatively approachable step.

The accurate emulation of an exchange, whether by NinjaTrader or an equivalent trading platform, gives the developer the confidence needed to proceed and eventually put a strategy online in a live account. Exchange emulation offers the most accurate environment for trade strategy development and testing currently available. 

Michael Gutmann was a software engineer and manager at Intel Corp for 20 years. He recently published the second edition of “The Very Latest E-Mini Trading: Using Market Anticipation to Trade Electronic Futures.” He can be reached at www.anticipationtrading.com. 

Page 1 of 6
Comments
comments powered by Disqus