Tuesday, February 13, 2007

Designing a Robust Mechanical Trading Strategy


One of the questions that I often get asked about strategy design is, “how do you design a robust mechanical trading strategy?”

To understand how to build a robust mechanical strategy it is important to understand what a robust mechanical strategy is. A mechanical strategy is simply a quantified decision stream that leads either a “trading robot” or the trader himself to determine position size, entries, exits and stops all in a completely hands off fashion – in other words if you have a working mechanical system your input is not needed (or if so to a very limited degree). Additionally, for a mechanical strategy to be robust, it must capitalize on a “trading edge”. This can be anything from a statistical edge (trending) to an executionary edge (arbitrage). Furthermore, this strategy must hold up over an extensive period of trades historically (at least several hundred) and must hold up in future trading (which can be simulated).

A mechanical system has several advantages that discretionary traders do not such as the ability to perform quantitative and data mining analysis quickly and over extended historical periods. Additionally, mechanical systems can alleviate some of the emotional distress that accompanies discretionary trading – particularly among new traders. However, it is important to recognize that mechanical trading has several disadvantages as well. The first being that you must be able to quantify each and every trading decision that the system will make, secondly the mechanical system will have to be periodically adjusted (just like a discretionary trader adjusts their methods) either through inherent adaptivity, optimization, or diversification. Lastly, mechanical systems only work if one puts in the tremendous amount of time and effort required to program, test, debug, and continually adjust it.

To design any mechanical strategy it is important to consider three things before anything else: 1) your objective for that system, 2) your market, 3) your timeframe. Once you have determined this, it is easy to find your essential methodology because there are only 4 ways to trade any market: 1) trend trading, 2) momentum trading, 3) reversion to the mean trading, 4) and fundamental trading. Once you have determined your objective, market, timeframe and method you are ready to attempt to put together your first strategy. Many of you are probably thinking at this point, “what if I don’t know any of that stuff?”

If you are already an experienced discretionary trader this should not prove to be overly difficult. However, if you do not have extensive experience you will have to find a method that works. This method can be as simple as a moving average cross long/short to as complicated as a continually adjusting collaborative neural network that is genetically re-optimized daily. The very best way for the inexperienced trader to build a new system is to test ideas. This can be done in two ways – visually or programmatically. For someone without extensive programming experience, the best would be to start with what I call “candle by candle” back testing. This is performed by taking an idea (such as a moving average crossover) and testing it with historical data on the given market and time frame by moving your charts forward from the past into the future and trading the way the system would – without future knowledge of the markets.

This method is how I tested my first ten “strategies”, four of which I still continue to trade today (including two that were designed by Phil McGrew which I tested using this method and still trade today). Here is an example of how I tested Phil's indicators (with my own exits). However, I had to test nearly fifty or sixty ideas to get down to those ten strategies that work, and finally refine the process until I had found four of those ten systems that I found tradable. To give you an example of how time consuming this process is, I tested these ten strategies extensively often looking at over 2 years of 15 minute bars and “executing” hundreds of trades. I spent nearly 700 real hours doing this testing (and I’m pretty quick with a chart and excel). It sounds like a lot of work right? Well it was, but it also gave me a feel for those markets that is nearly as good as having traded those markets in real time.

After doing this for some time, I felt that there had to be a more effective way to test ideas. And there is – programmatic testing. Programmatic testing again can be very easy – a simple moving average cross is a simple thing to program in nearly any programming language. However, the difficulties that can destroy the beginning programmatic trader are nearly endless. Many popular trading packages do not trace your equity position tick by tick, rather it is tracked bar by bar (and if you’re trading daily bars you can imagine the problems). Also, ideas that I had tested extensively by hand sometimes were difficult to program. I have had so many experiences where I miscoded a critical concept (even by a slight degree) and this ended up giving drastically different results than my hand testing. Without the knowledge that it was the code that was incorrect, I might have falsely dismissed many trading ideas that were in fact valid. This coding problem is haunting if you think about it.

Additionally, at this level of programmatic trading it is very important to consider factors of minimizing inputs (degrees of freedom) and utilizing flexible inputs. An example of this would be to utilize a 3 ATR stop instead of a 60 pip stop so that as the prices and volatility of the market fluctuate your stop is not being taken out because of random noise. Other ways that you can improve the robustness of your strategy include utilizing realistic fills and commissions and ensuring that your limit orders would have actually been filled (this is not as easy to test in some software as it should be). Optimization is another useful tool to consider at this point in your strategy testing career. This is a powerful but two edged sword. Utilization of genetic algorithms and similar “hill climbing” techniques are a common way to ensure that your optimization does not give you a single point anomaly, but rather that there are similar input values surrounding your inputs that give similar equity graphs. Walk forward testing is another useful tool that can help you achieve realistic results and see for yourself whether a strategy would have been successful on data that was not optimized (similar to the future).

Going further into programmatic trading, after having experienced many pitfalls, I feel that I ought to be able to test more than one idea at a time. In fact, ideally I would like to test many ideas, over multiple time frames and multiple markets. Right now this is the work that I am involved in designing and I feel that this will help me analyze the markets with the speed and precision that will take my trading to the next level. This is the arena of the best strategy designers, where statistical data mining, market analysis, timeframe analysis, technical analysis, fundamental analysis, and money management are combined with realistic evolutionary testing into a single package.

As you can see, advanced programmatic testing and trading is a complex arena. I myself am still learning and by no means consider myself an expert. The good news is that successful robust mechanical strategy creation and implementation can be done in as simple or as complex a manner as you choose. After all, the very simple strategies tested and/or designed with candle by candle backtesting are still a cornerstone of my trading methodology.

Save to del.icio.us

5 comments:

LifePost said...

That's a nice article you've written. I'm looking into backtesting a few strategies. Tradestation looks like it would be easiest for me to backtest my strategies, however I was looking for some more options.

Can tradestation make indices based on a basket of stocks you've combined?

(neoticker has the TICK16 which is the 500 stocks of the SP500 combined to show you a tick by tick comparison, I haven't watched it in real time but the idea seems like there would be an edge there as well as following a stock in an index with a TICK index setup for that stocks sector)

Also, can tradestation be programed to make signals based on volume profile levels? If not, what software? (ie. the last 2 days the POC has been rising and the current price is near the LVA for day, and you want to setup the system to make a signal for a long entry when this scenario occurs)

Lord Tedders said...

If you're already using NeoTicker then I'd recommend sticking with it. NeoTicker has functionality that TradeStation simply doesn't and will likely never have. In fact I am currently attempting to convert myself from TradeStation to NeoTicker.

The problem with backtesting in TradeStation is the following: 1) no time stamped tick data, 2) no control over data management, 3) no control over backtesting, 4) no automated trading for Forex, etc.

The only thing that TradeStation has over NeoTicker is ease of use and a strong support forum that only has to deal with one programming language. The unofficial joke at the NeoTicker forum is that if you are top level TradeStation programmer that will just qualify you to be a NeoTicker newbie :)

To answer your other two questions, no TradeStation does not have TICK16 (or any of the advanced combined data stream options that NT has), nor does it have an elegant (or even halfway decent) solution for volume profile where you can take signals based off it.

Tedders

LifePost said...

Thanks for the reply. I've got the demo version of neoticker right now and its hard to work with, I'm sure I would have to spend a month to learn just to how to add my own indicators.

Lord Tedders said...

Check out the formula language examples on the NeoTicker blog (101, 201, 301). I've found them to be very helpful. Good luck.

Steve said...

If TradeStation can work out the bugs with it's latest/greatest version 8.3 , FOREX should be fully automatable. This day can not happen soon enough for me.