Home › Forums › General Discussions › For the friends of cultivated filtering
This topic contains 16 replies, has 3 voices, and was last updated by simplex 1 year, 6 months ago.

AuthorPosts

Hello everyone,
this thread is a little teaser for those of you who are interested in signal processing / extraction / filtering. Moreover, it is a survey if there are people willing to collaborate in a project. Let me briefly outline the subject of interest in prose:
There are two major classes of signal features in a time series that are of interest from a trader’s perspective. These are the trend component and the turning points. In a strict, mathematical sense, the trend is the zerofrequency component, i.e. the (very) longterm direction of a market if we take the entire price history into account. (So, for natural, nonsynthetic markets one might expect a positive trend over (many) years due to the assumption of an overall economic growth.) A trend according to this definition is easy to identify in retrospective, but extremly difficult to find timely. Basically the same applies to turning points, however, the situation is not quite as hard as with trends. So let’s focus on TPs now. A TP is related to a certain frequency in the signal. Supposing any seasonal market with a yearly cycle (e.g. a market for German biological open land strawberries), you will observe a peak in the spectral density of the signal at the frequency that corresponds to a year. If you want to extract only this cycle in order to separate it from any other components (noises), you would design a bandpass filter around that frequency. Generally, if you are interested in several components, you increase your passband accordingly, and finally, if you want to catch all components lower than a certain cutofffrequency, you end up with a lowpass filter. That is probaby the most prominent filter class in trading. You may also call them smoothers as they (ideally) suppress all higher frequency noises beyond the specified cutofffrequency. So, a signal filered with a lowpass filter will contain only TPs related to any frequency below the cutofffrequency, which you then might want to trade. However, smoothness comes at the price of higher lags (delays), i.e. there is an inevitable tradeoff between reliability (noise suppression) and timeliness.
Typically, you use a wellknown class or even a particular parametrization of lowpass filters such as for instance any variants of moving average, Butterworth, Tschebyscheff, Bessel, Ehler’s filters… The alternative is a “handcrafted” custom design, as hinted above, where you specify a target filter function in the frequency domain and obtain the coefficients of a closely matching, feasible real filter based on a meansquared error (MSE) optimization criterion. The MSE optimization aims to find a real filter realization that comes closest to your ideal, infeasible target specification. That’s the usual approach in filter design.
According to Prof. Dr. Marc Wildi, an econometrist at the ZHAW, the MSE might be devided into several components that address the smoothness, the timeliness and the accurateness of a designed filter individually. In this way, you can emphasize some of these aspects in favor of others. As traders, we’d like to have smoothness and timeliness, whereas the accurateness is of minor interest: All you really need is a signal that is timely compared to the actual market and identifies TPs realiably, but it doesn’t neccessarily have to quantitatively reproduce the prices. In short: there is a way to design a filter based on a target specification such that it will be smoother and/or faster compared to the typical MSE solution (and most probably also compared to standard filter classes). There are some very interesting papers that introduce the entire concept mathematically and there is also some R code for suchlike “customized” filter designs.
I’m planning to reproduce and test this approach and see if it can provide an edge. Are there any people that feel like contributing? What would be helpful:
 interest beyond trading
 patience
 some undergraduate math
 (knowledge of R, C++, C#, math libraries (Eigen), …)
Hi flx,
I’ve been off for some time, so I did not notice your new thread until now. Interesting!
From what you’re writing, you appear to have read most of Ehlers’ papers and / or books, and certainly a bit more.
I agree that it is not necessary to reproduce (smoothed) prices exactly in order to trade successfully, all it takes is timeliness regarding to turning points.
Looking at true seasonal markets, like your fieldgrown strawberries, or intraday volume (not prices) of several FX pairs, obviously a welltuned bandpass filter would be the optimal choice, operating at zero lag if frequencies do not change, and and shortterm disturbances are of minor amplitude.
Looking at FX price data, these are rarely seasonal in a narrower sense, and short term disturbances can frequently appear at major amplitudes.
You wrote:
specify a target filter function in the frequency domain
Would this result in some kind of frequency measurement? If yes, I doubt it would be useful. Frequencies are changing too fast, and even Ehlers quit this approach, as far as I know.
Could you refer to some of Wildi’s papers that appear interesting for you, maybe provide links?
Let’s see if we can develop your thread into an interesting discussion, or more.
simplex
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top and bottomfishing to people on an ego trip. (Dr. Alexander Elder)
Oh, I also missed your thread while I was away during the last weeks. I’m not quite educated when it comes to filtering and Ehler’s methods, but I think it should be relatively easy to implement some of the ideas in R. Thus, count me in for some R tests …
@simplex: I knew you were interested. I haven’t read all of Ehler’s papers… yet, so I’m certainly not an expert in his work. The approach here is basically motivated from a general signal processing background. To put it in a nutshell, it is a standard direct filter design / specification approach with a customized optimization criterion addressing timeliness vs. smoothness vs. accuracy MSE components of the resulting filter instead of just their sum. This results in filters which may be both smoother and faster compared to an ordinary MSE solution at the price of reduced accurateness (poorer quantitative tracking of the input signal).
Don’t worry, the seasonal strawberry market was just a little supid motivation and in the end I’m rather interested in low pass filters with a wider pass band.
You wrote:
specify a target filter function in the frequency domain
Would this result in some kind of frequency measurement? If yes, I doubt it would be useful. Frequencies are changing too fast, and even Ehlers quit this approach, as far as I know.
Hmm, I’m not sure if we are talking about the same thing. If you refer to some sort of online frequency /cycle identification or tuning, no. Specifying a target filter function in the frequency domain is just the standard approach in any direct filter design. You just specify your desired ideal pass and stop bands.
@anti: There is a lot of Rcode provided. I already portet the most computational expensive routines to C++ and they are much faster now, but for any testing purposes, R is certainly the better choice.
Now let the paper speak for some clarification: https://blog.zhaw.ch/sef/files/eco2_script.pdf . You might want to skip the introductory chapters as well as the exercises. It’s getting interesting in chapters 4 and 5, especially. This is only the basic concept. There is a multivariate version (MDFA) which takes cointegrated timeseries of a target market (to be traded) into account in order to design a set of filters that generate a single output signal. But one step at a time…
Re. lowpass vs. bandpass filter:
I generally agree that a lowpass or some similar approach should act as a primary filter.
Guided by earlier Ehlers’ papers, I tried for some time (long ago) to measure current price frequency, and then tune a bandpass accordingly. As you might have guessed from my above post, this approach was not successful
But this afternoon while reading your opening post I had the idea to revisit bandpass filters from a different perspective, as a possibly additional criterion.
Let’s say a lowpass (or whatever) is our primary entry criterion. As traders, we might have a certain average holding time in mind when opening a position, always in line with our money management. Let’s say this would be between 2 and 4 hours (replace this by any range that makes sense for you).
Now what about tuning a bandpass regarding both cutoff frequency and bandwidth to this planned trade interval and wait for the appropriate reversal of that bandpass to act as secondary entry signal? By doing so, we would skip the unreliable frequency measurement by FFT or whatever, and open our position at a time that appears to be optimal regarding the planned time horizon of our trade.
Comments?
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top and bottomfishing to people on an ego trip. (Dr. Alexander Elder)
Sounds nice, theoretically, and is certainly worth a try. However, in any case the timeliness is crucial in my optinion and I think that typical filter classes are just not fast enough in order to produce signals before the show is already over – may it be primary or secondary ones.
Hi @flx23,
Did you proceed your project / ideas in silence? Any ideas to bring this thread back to life?
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top and bottomfishing to people on an ego trip. (Dr. Alexander Elder)
Hi @simplex,
yes, I implemented the original R code in C++/Cuda and did some backtests. In my oppinion there is (tradeable) potential in this approach, especially in the multivariate variant (MDFA) where several cointegrated series are used. The major problem is (as usual) the overfitting arising from the many parameters and I have to figure out how exactly they can be freezed. There are some regularization approaches proposed by Wildi but their R implementation seems to be incomplete.
If you are interested, you should have a look at https://imetricablog.com/ and https://github.com/clisztian.
Ha, thanks for those links! A lot of stuff to read …
The ‘multibandpass filter’ heading immediately got my attention (reminds me of my old Ehlers’ works in mq4). Yet have to postpone indepth reading for a while!
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top and bottomfishing to people on an ego trip. (Dr. Alexander Elder)
Hi Carlos,
I read your most recent 3 posts and all of them contain links to brokers’ websites. Could you please explain? To be honest, this looks a bit suspicious to me regarding spam.
s.
EDIT: spam content moved to the trash bin.
 This reply was modified 1 year, 6 months ago by simplex.
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top and bottomfishing to people on an ego trip. (Dr. Alexander Elder)
To put it bluntly and less politely than simplex, it looks like banalities used to camouflage advertising.
Hi, I’m not sure if this really fits here. However, I have a question in regards to Ehlers ZeroLag MA. I’ve tried to find out which lag this “zero lag” version produces in comparison to its calculation period. Unfortunately without much success. Any hints?
 This reply was modified 1 year, 6 months ago by Anti.
Hi Anti,
There are several mq4versions of ‘Zero Lag’ filters out there, and not all of them are original Ehlers’ works. I assume you’re referring to the one described in this paper.
I tried it years ago, and there’s not so much lag indeed. But on the other hand its smoothing capabilites are not so brilliant – the typical tradeoff to consider when defining a lowpass filter. That limited smoothing has the potential to produce a lot of whipsaw signals.
Given a good overall strategy, it ‘might’ serve as a fast price proxy for trade timing, but that’s all I remember at the moment.
s.
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top and bottomfishing to people on an ego trip. (Dr. Alexander Elder)
Hi Anti,
in the case that you refer to the version mentioned by simplex, there is no direct relation between the (instantaneous) lag and the period. The lag is a function of the “best” gain which is chosen as the one producing the smallest error between the last indicator output (prediction) and the current price. So the lag is data dependent, i.e. nondeterministic. That’s the problem with most zerolag indicator apporaches: they substitute a certain amount of lag by a predictive model and/or adapt the lag depending on their current prediction success. In either case those indicators perform well whenever the data behaves according to anticipated model but lose predictiveness when it gets interesting.
The general idea is certainly related to this topic: try to find a tradeoff between lag and smoothness. However, in terms of Wildi that is rather a trilemma than a dilemma if we introduce a third dimension. We can then shift some amount of the error into the accurateness term.
Thanks a lot, guys. It’s quite interesting to see that there’s no direct relationship between the period and the lag. I don’t like to apply it in trading. However, it seems to be part of CrucialPoint’s indicators (Zerolag MACD) that uses the Zerolag EMA described in the paper you mentioned.
Just a little addition since I think my previous post was a bit misleading: what really decouples the relation between the lag and period is not the data dependency per se but the cherry picking of the gain within the for loop which is a kind of optimization. Generally, the lag of a filter is always dependent on the data by its frequency.
Furthermore, there is no finite “period” or windowsize of an EMA since an EMA takes theoretically infinitely many past data points into account (infinite impulse response). The relation alpha = 2 / (N + 1) is only a trader’s rule of thumb and proposes a smoothing factor alpha of an EMA such that its smoothing is approximately comparable to a SMA of period N. Theoretically it is rather pointless since you are comparing apples with pears.
Yep, IIR vs. FIR filters in shorthand! If considering Ehlers’ lowpass proposals, I would rather have a look at his ‘Supersmoother’ (IIR). Simple, smooth, adjustable.
A good trader is a realist who wants to grab a chunk from the body of a trend, leaving top and bottomfishing to people on an ego trip. (Dr. Alexander Elder)

AuthorPosts
You must be logged in to reply to this topic.