Menu

Thursday, March 3, 2011

HOWTO: Signal filtering, the better way.

It is hard to find a trading system that does not employ signal filtering through use of sma, ema, wma  and the likes. I'm not going to dive in detail on the inner workings of these filters as this info is widely available.
Filters that prioritize recent data are more suitable taking market dynamics into account but implementing these filters using a for loop in Matlab is anything but efficient. Luckily, Matlab provides the filter function, that can be used to calculate all these types of moving averages and even more.
In the code attached to this post I'm going to show how to filter signals based on an excellent article written by John F.Ehlers. (more articles can be found here) Please read it before playing with the code. I've implemented the different filters mentioned to compare their characteristics.
 Looking at the data, I must draw a conclusion that the hybrid filter provides an improvement in terms of lag over the standard ema.
Using this hybrid filter one can create a simple indicator of the current price imbalance, like shown in the next graph. For this I've used the difference between the current price and emaHibrid(price,0.85,0.3)


Source: demoFilter.m,  emaHybrid.m data: price.mat