Sunday, January 16, 2011

Building a Trading System: Part 8–Optimization (cont.)

In the last post we introduced the concept of optimization. Simply put, this is a quick way to fine tune the rules of our basic system and determine how to wring out the very best performance. You might remember that two of our system rules (hey, we only had three… try to stay with me) were:

  • BUY when the price closed 5% or more below the 5-day moving average; AND
  • the closing price was also above the 200-day moving average.

To better explain optimization we’re going to run an optimization for each of these parameters… the 200-day MA, and the 5% stretch. I won’t bore you with the code, but in plain language here’s what we’ll check:

  • We’ll check every stretch, or pullback, from 2% to 8%, in 1% increments; AND
  • Every moving average from 50 to 300, in 50 day increments (in other words 50, 100, 150, etc.).

All in all, this will be 42 back-tests, and with Amibroker it takes all of about… oh… 60 seconds. What’s really cool is the resulting chart. The three dimensional chart helps us clearly see optimal performance. Before I get to that, however, it’s important to decide in advance what “optimal performance” means. This brings us to the topic of the performance indicators.

Simply put, the system developer needs to make a personal decision about what good performance looks like. The optimal settings for the highest CAGR will probably be different than the optimal settings for the highest return per trade. In this case (for illustration only) I’ll use the Sharpe ratio. I’m quite fond of a smooth equity curve.

optimize4

You can quickly see, through the chart here, what optimal settings would be, and how they perform, at least in a broad sense. It looks to me like the best Sharp ratio comes from a short moving average and a larger pull-back. In the next post I’ll show the back-test as compared to our earlier developments and we can evaluate the improvements.

Good Trading…

4 comments:

  1. Hi Will,

    Congrats on a great blog. The "Building a Trading System" series is excellent. Just a quick question - doesn't the graph show that a larger pullback produces a higher Sharpe ratio?

    ReplyDelete
  2. Dj,
    You are exactly right. Thanks for catching that. The better results come from deeper pullbacks. My mistake, I will see if I can edit in the correction. Thanks for pointing that out.

    Bill

    ReplyDelete
  3. No problem. The relationship between the Sharpe Ratio and the pullback size is quite linear. I think this lends further support to the validity of the mean reversion theory.

    ReplyDelete
  4. Hello.
    I have seen your Blog.. Its too informative. There are many posts which are really too Good and very useful. System Optimization

    ReplyDelete