Monday, January 3, 2011

Building a Trading System: Part 4 - Filters

In the last post we introduced a very basic system for trading our mean reversion theory. As we saw, the system worked... that is, it made money, but it had some serious flaws. The most significant flaw was the extreme volatility in the equity curve. On our way to making nice annual profits we had so many ups and downs I was getting sea-sick.

Today I'll introduce an extremely simple filter to see if we can smooth things out a bit. Again, this is based on a pretty common sense theory. The basic idea is: We should only take long trades when the market is trending up, and we should only take short trades when the market is trending down. And since this is a long-only system, we'll just take trades when things are in an uptrend.

Okay, next question: What's an uptrend? In other words, how do we decide whether the market is trending up. Well... there are many ways to define a trend, but we'll pick one that is pretty well recognized and accepted -- the 200-day moving average. When price closes above the 200-day moving average, we'll call that an uptrend. When price closes below the 200-day MA, we'll call that a downtrend. With that said, we need a new rule that says we only take the trades when price is above the 200-day MA. Again, this rule is very simple. Added to our last rules, the new code looks like this:

  • Buy = Close < MA(C,5) * 0.95 AND
  • Close > MA(C,200);
  • Sell = Close > MA(C,5);

So how did we do?

Now we’ll run the same backtest we did before, just with this new line of code in place. All of the other settings are the same as described before. The “A” column is from the basic system, and the “B” column is with the new 200-day filter. I like the improvement:

As you can see, virtually every category shows improvement. Trades were lower by about 1,000, which will reduce work and transaction costs. And it looks like most of the trades filtered out were the bad ones. This is the kind of result that a very simple, yet logical filter can provide.


The equity curve looks much better than before, but I still don’t love the retreat the system took in 2004, where the system posted a substantial loss. Next time we’ll look at some other possibilities for improvement. Please let me stress - yet again - that this is purely instructional and informational. I would not and do not trade this system, and do not recommend that you do. My only goal is to show some the things I do during system development.

Good Trading...

No comments:

Post a Comment