Visualizing Price Data as a Complex Phasor
Hilbert Transform, Signal Processing, Technical Indicators March 25th. 2008, 1:33amIn a previous post regarding a modified wavelet feature extraction model I talked about replacing the DWT/FFT part with a customized Hilbert Transform for the purpose of capturing cyclic behavior of the price data. Here I discuss this in more detail and introduce the first of 3 Hilbert Transformer variants I am excited about.
For those not too familiar with phasors please have a look at the following links:
- http://resonanceswavesandfields.blogspot.com/2007/08/phasors.html
- http://www.jhu.edu/~signals/phasorapplet2/phasorappletindex.htm
Simply put a phasor is an alternative way of representing a time-domain signal using a complex set of measures namely InPhase and Quadature. Recall that Hilbert Transformed signal takes the form where
is the “real” or InPhase part and
is the “imaginary” or Quadrature part. Plotting
and
on the complex plane and tracing out the trajectory formed by the phasor is supposed to reveal, among other things, the cyclic components of the signal.
There are many variants of the Hilbert Transform, but they all have a common structure which was popularized by [Ehlers]. For future reference we shall refer to Ehlers’ model as Variant 1.

Applying a chirp signal to the input:

Due to the phase differential between the InPhase and Quadrature signals it becomes possible to trace out the trajectory taken by the phasor on the complex plane. The figure to the left shows this for a signal with frequency 20bars/cycle. Now if we superimpose a short
term cycle on a longer one we see a change in the trajectory due to the presence of the new cycle. The figure to the right shows this. Notice that the cycle only shows up on the phasor plot with a lag of 4 bars. We were expecting a shift after the 10th bar, but only appeared after the 14th bar.
Short term cycles show up as a distortion of circles with bigger diameter and it is possible to use this feature to visualize underlying behavior in price data or any financial time series for that matter. I simulated a 31 step Brownian motion with drift = 10, diffusion = 10 and evaluated it’s complex phasor. We can clearly see how short term cycles influence longer term cycles, which is not obvious by inspecting the time series alone.

Inspecting the phasor plot we can see the presence of cycles as represented by circular features being formed by individual points. The following cycles exist:
- Cycle 1: On Phasor plot points 7, 8, 9 => 3 bar cycle. On time series plot this cycle pertains to points 3, 4, 5.
- Cycle 2: On Phasor plot points 12, 13, 14, 15, 16, 17 => 6 bar cycle. On time series plot this cycle pertains to points 8, 9, 10, 11, 12, 13.
- Cycle 3: On Phasor plot points 25, 26, 27, 28, 29, 30, 31 => incomplete cycle. On time series plot this cycle pertains to points 21, 22, 23, 24, 25, 26, 27.
We also make the following observations:
- Cycles 1 and 2 could actually be noise. We can only confirm this if we define a minimum diameter for a circular feature to qualify as a cycle and ignore all those with diameter less than the minimum.
- Cycle 1 & 2 distort cycle 3.
- Cycle 3 is incomplete but is the dominant one. The only way can predict its frequency is to count the number of points in the 2nd quadrant (points 26, 27, 28, 29, 30) and multiply by 4. Given that there are 5 points we predict that Cycle 3 is roughly a 20 bar cycle.
Key Points:
- The Complex Phasor plot provides an excellent way of visualizing cycles and how they interact with each other. A cycle is one complete circular feature whose frequency is equal to the number of complex price points forming that circle.
- Due to the lag constraint of Hilbert Transformer model used in this test (Variant 1) it is only possible to view cycles with a lag of 4 bars. In future I shall discuss Variants 2 and 3 which attempt to detect cycles with less lag.
- It is possible to develop a trading strategy that exploits the cycle information obtained via Hilbert Transform. For instance we could use the InPhase vector as an anchor to decide when to buy or sell depending on whether pre-defined lines/points on the complex plane have been crossed. I have high hopes for such a method, particularly in an algorithmic trading setting.
- It may actually be usefull to filter the input data before evaluating its complex phasor, but this may distort any micro-structure that may exist in the time series. It all depends how much filtering is acceptable.

March 26th, 2008 at 11:06 pm
[…] AI Quant suggests Visualizing Price Data as a Complex Phasor. Perhaps I’m odd, but I find this type of information far more intriguing and potentially useful than trying to make inferences about “inflation” or “consumer spending” from some blogger’s wife’s trip to the grocery or mall. […]
March 28th, 2008 at 7:47 pm
This is all fine and dandy, but I fail to see how it makes money or how it is better (no use for it really) than any other indicator.
On top of it all, I find the lack of implementation details, high-level maths that can only be drawn and done in MatLab, really abstract.
If anything works, it is open in idea and code. And if it is open as such, it usually doesn’t work (as in make money).
Just another though that you’d ought to be really demonstrating system PL performance as well as code implementation details. You know, where the drawbacks and *potential* profit bits are.
The filters will obviously not guarantee any returns or make them consistent enough to be relevant.
March 29th, 2008 at 2:35 pm
I am not pushing anyone to adopt these methods as the focus of my blog is to show ways in which Signal Processing can be applied to problems in the financial domain.
I certainly can’t comment on whether it is better, but this is the only indicator I know of that can tell me cyclic content of a time series on a tick by tick basis. Perhaps you know of other indicators that do similar things in better ways - which you might care to share?
The purpose of this post was to discuss how price data can be displayed as a complex phasor, and not to discuss a trading strategy based on the indicator. As to whether it makes money or not I think you might want to ask yourself how you can go about using this cyclic information to develop a strategy that makes money.
The block diagram is a very clear implementation of the model. The only operator you might be unfamiliar with is “1/Z” which represents unit delay by one tick. So if you apply a sequence [1, 2, 3, 4, 5] to the input of “1/Z” you get [0, 1, 2, 3, 4, 5]. I dont know if you can do it Excel, given my limited experience using that software, but any well versed programmer will not find converting this block diagram into code a problem.
Also, I have no intention of releasing any code or PnL details of these systems. It is up to the reader to persue and implement these ideas if they find worthwhile.
March 29th, 2008 at 4:06 pm
Abstract? Not really. This and a couple of other blogs have inspired me to pop my interest in DSP off my to-do stack and pick up a book. Within a week I should have what I need to understand and extend the work that AI Quant has posted. Abstract is a relative term, though this topic being covered in an elementary DSP book is to me self evident that it is not abstract at all. I’m quite familiar with the analysis of financial time series and understand that there is a high probability that in and of itself this topic wouldn’t produce more P than L, but that shouldn’t stop you from the investigation. Chances are, you’ll be able to find something that when joined with previous efforts will provide something exciting.
As for posting code of profitable strategies, you have got to be crazy. What I really like about this blog is the focus on the application of Signal Processing to the financial arena, without the distraction of building full on trading models. I would much rather see a link to an academic paper on some filter design than a plot of strategy returns (which would shift the focus to backtest environment, trading implementation, slippage measurement, . . . .)
I don’t want to turn this into some sort of flame war. I just wanted to express my gratitude toward AI for generously posting his (her?) thoughts and research for the Internet community to follow. I look forward to the next installment.
April 15th, 2008 at 7:20 pm
Okay, fair points.
Let me address the more important which evidently has resulted in taking down your latest entry because, that is what is: too abstact for high-level systematic traders to comprehend. That makes my point clear.
However I greatly appreciate your writing. It is just that I think if you don’t describe your ideas in code you’ll end up with ambigous interpretation (it is a well known out artifact out there).
I can tell you it is not better. DSP or use of indicators does not in any shape of form guarantee anything. Using cyclic information itself does not protect you from volatility which is becoming commonplace (and if you are decomposing for trends you are in the same boat).
The block diagram, on a second read of your explanation (appreciated, thanks) has better a ‘view’ if you see my point. People will still make assumption on the insertion of 0 in a sequence.
Yes you can do it in Excel, but it is not an ideal platform (for prototyping sure, but just like Matlab - I used this piece when people didn’t know or or had Internet). For production system you never ever deploy MatLab code, some hedge funds do, but they are just playing the same game every man on the street does. They interview for people who understand DSP, FFT in particular and analogue domain, MatLab etc while not grasping the basic concepts of psychology and timing.
Of course you should not be releasing code (I thought it was implicit in my, ok I admit, unfair post). However, the only benchmark I know of and that always presents a fair picture is PnL. So we concur on the former, but not on latter.
PnL performance is widely published out there, on methods that surpass seminal computational work out there and they are available either for free or with simplest email registration. It reveals no quality information on the strategy whatsoever. Each fund manager does it and most people simply report it as a form of awareness, marketing and plenty more (Btw, it is an irrelevant detail, I work for one of the top 10 for a particular continent - that is how it is usually categorised).
Remember the 95% of traders lose money theorem. It hasn’t been disputed yet.
Many quants have lost plenty of money trading on cyclic and similar value information especially in credit markets. I just want to make sure that whatever you read, whatever books, and whatever is made public, by default never ever works for long enough to make money at all.
I’d suggest pseudo code of the things you disclose as it makes it more valuable and gets your points across more effectivelly. It is evident you come from the DSP background but this is not music, medical imaging etc.
Also, the word ‘model’ is so overloaded I doubt people understand what it means. It is only applicable to few markets and they are so specialised no retail market has access to it whatsoever. In fact, electronic markets are not friendly towards it.
One more point, stay clear from academia or better put, academic papers, when dealing with live markets.
Despite the above, quite likely, sounding negative, it isn’t.
Keep it up and all the best.
April 15th, 2008 at 9:34 pm
Lol. That was a harsh post.
Just to make a remark, “Applying Signal Processing and Machine Learning concepts to problems in Mathematical Finance” that is the blog subtitle you know?… So you shoud expect to see DSP and Machine Learning ideas applied to financial data, and as far as i know aiQuant is just doing that (really good by the way).
I also consider ridiculus the idea of aiQuant posting trading systems lol, that is like going to a quant hedge fund and asking them their trading strategies, it just wont do lol.
As far as the code, i think that while he stays as clear and helpful for explaining his posts as he is, there’s not really any need for code, besides, as a friend told me once, just google it! LOL.
There’s plenty of code on the subjects aiQuant is posting, and even more books you can refer to.
Other thing, always i hear the 90-95% of traders commentary i have some good laughs with my coworkers, because that means that they and i are on the 5-10%! Lol, i’ve been trading for 5 years and paid my whole college tuition, apartment, and everything else, with what i earn trading (and obviously save most of it)(by the way, im a economics student).
Well, enough of this.
Now going to the post itself.
This stuff is really interesting, i’ve seen it before and considered applying it myself (and as aFan said, it remained on my to-do list).
In theory with this idea you could “see” the cyclical behavior of the time series (if any, and if you have enough data).
Nice post.
April 15th, 2008 at 10:11 pm
Ramon:
The reason I took down yesterday’s post was because a couple of readers had identified a source of confusion in the description which would have lead one to completely misunderstand the concept being conveyed. It is not off line permantly, but wil re-appear after I make corrections.
Like I have said before I have no intention of releasing code. To avoid ambiguity I shall attempt to explain clearer what I am trying to convey.
Not better than than what? DSP is not a trading strategy hence it will never guarantee any returns whatsoever. It is simply a branch of mathematics aimed at understanding and interpreting signals. I never said the phasor will protect you from volatility - it is just a way of computing cycles in the signal. How you use that information, either for making a profit or a loss is up to you.
I won’t argue with you on this one - not because I agree with you but because I think you are making a senseless generalisation about Quants.
The phasor plot is not a trading strategy. It is a way of visualising cyclic content which can be exploited in the form of a strategy. It is up to you to apply it to derive abnormal PnL.
You only mention the losers. What about the winners? I can certainly assure you there are even more Quants who have made money by applying mathematics to the markets. You implicitly curse my models and hope they never make money. Seriously mate you need to see Dr Phil.
I will continue to explain my methods in the same way I have been explaining them since the inception of this blog and hope my readers will be inspired to investigate further how they can be applied to generate abmormal profit. Unless I see an incentive in doing so, I shall not release any code.
I hope I am not one of those people. But just to confirm the Oxford dictionary describes a model as “a simplified mathematical description of a system or process, used to assist calculations and predictions”. Now if what I discuss are not models then please suggest a suitable term for them.
Thats a matter of preference really and unless you can provide a solid reason for this I am afraid I would have to disagree with you.
Sure, a very positive gloss on things! I appreciate your comments and hope you will return to read my posts in future.
April 16th, 2008 at 10:57 pm
Okay, we need to get a little technical then.
First of all the latest reference, C code is not the type of work, in my humblest opion, anyone should be looking at. It is an utter mess.
Second point regarding Phasors, Hilberts and Wavelets which has been the focus from what I understand. From my chair, the entire show is inconsistent and on the following:
- Phasors, there is no example what the input is and what output will be. You keep mentioning the tick data and I can tell you here it is, trade prices : 1, 3, 5, 11, 13, 17, 13, 5. What’s the output? Is there an example or validator you can point to? That is how you should approach in my opinion.
- Hilbert Transofrm for mode detection. Again, I cannot see you do anything with it as is an not looking at 3 ticks at least.
- Wavelets vs FFTs. Coming from DSP background I cannot understand why you eliminated FFTs, yet oddly the slides some academia guys posted (and that type of analysis will lose money, more than 300 billion quants crushed playing with derivatives pricing) is plain fire material. Moreover, harmonic wavelet requires an FFT right?
I’d rather not go into why I am always a skeptic of any xyz trader doing a ‘model’. Model, in markets, models. It is a very simple definition. Modelling and strategy are two widely different things. Model either satisfies or produces past data and outputs its characteristics, usually described when it works and when not (key is ‘not’ and why), or it does it for the future (again this has nothing to do with scenario analysis although a model can be an input there).
A strategy simply acts on future data in piecewise fashion, not predict, not model or anything like it, and you can forget the word model straight away. A model is not a state machine type of thinking. And I can tell you no GA or SA or NN will model anything for the future. You might combine outputs and again act on incoming data and output of those but you are still not modelling anything ahead or for the past by definition.
In constrast, a pricing model on options will model.
The above is just a very crude way to describe what goes on within hedge funds. They don’t trade forex as people think they do, they hedge forex with such complex instruments (just like all types of banks do) they require a Galactic ‘model’, they hedge risk and porfolios or transactions on the book because the exposure or money played with is huge.
I hope this clarifies it a bit more, and yes I am still reading, but believe me, markets require more than science to consistently make money out of. Psychology, timing and management are key, and those you will not see easily, if at all, expressed in DSP, Quantum Mechanics, or anything else for that matter. Sure, you can get lucky with most basic moving averages for all I care and would use instead of DSP, but once it stops working, it stops working before you can usually stop it.
Now imagine how poorly that scales on a fund of a few billion invested and on top of that leveraged; if you get ‘hit’ (with Taleb nonsense speak or not), the only thing you should be looking for in maths is: how to run.
(btw, Taleb writes because he makes money with it more than on the markets; why doesn’t he trade or run his own fund of his theory rather than just consult and write what is widely known out there and popularising it: brokerages transferring to professionals aka 60 year wipe of amateur/retail traders)
April 16th, 2008 at 11:11 pm
Juan, yes you can Google anything these days.
What you will not see is internals of a hedge fund working or any idea how they work. I can tell you that much, as I went to one before there was a word coined or you could see a price on a screen.
Economics, you know the econometrics bits you do, sure it is in demand but again: you will not make money with it consistently and will blow up a fund before they know it.
Understanding markets is not understanding waves, or playing with surf boards. It is high tech business far more reliant on implementation details than Google will ever provide.
Which is what I mentioned earlier on, if you see the code or a diagram for it: it, does, not, work.
Hope you can pay more with money from markets, but your consistency says nothing about methods you use (I’ve noticed you keep pulling commercial software references out of the bag, and that tells me you’re not doing it as a main job because you wouldn’t use any other software but yours). So, with all due respect, delusions are a first sign of a fall. Second one is rejection and then fear kicks in. 3 phases you will not describe with any filtering mechanism in Z-space or not. Hope you can avoid them.
Again, I am enjoying reading this and what’s a blog without a troll or a bad guy around
Please bear with me as it could make your focus less ‘dangerous’, for yourselves and others, in my humblest opinion again.
April 16th, 2008 at 11:19 pm
And for reference, the reason I have this tone (again it is a positive one if you flip the coin for a living or marketing), is because I see Brownian motion up there.
So obviously you either know someone in a hedge fund or work for one. And from my experience, the moment you put something out from that environment: it is primarily because it did not work!
That is my main worry really.
April 17th, 2008 at 1:33 am
Sorry, I didnt realise that I said somewhere that i didnt know any hedge fund…
Oh, maybe that’s because i never said that!
In fact, i know many hedge funds, and im friend with many directives of investment banks.
Obviously you wont find the trading strategies published on Google… But you can find more than enough information to make your own strategies.
I appreciate your concern on my revenue..
And yes, I can pay more (you should have seen me in my vacation in st. barts and then on cerdeña).
Again, just as aiQuant im not planing either on releasing any of my trading methods.
Commercial software references? The most that i referenced was Matlab or some open source code.
And I dont see where’s the problem with taking advantage of looking at existing open source code.
That’s just funny, for the past 3 years, me and some of my coworkers have been developing our own (private) trading and research platform, so yes, i use most of the time my own software, but also rely on the research other people has done, there’s no sense on redoing the wheel.
Besides, I dont see a point in your comments, if you just consider DSP and AI as worthless, then the real question is what are you doing on a blog of DSP and AI…
April 17th, 2008 at 9:03 am
Ramon:
Thats exactly what I have done using the example sine waves shown here. I have taken sine waves with known cycle period and shown what the resulting phasor gives me the measurement I expect. I then go on to apply the algorithm to a simulated brownian motion to show how it would work in practice. Why don’t you calculate the output of your price series yourself and post them here, We shall then discuss any issues you are not convinced with.
The main purpose of the hilbert transform is to convert raw price data into IQ (InPhase-Quadrature) form. IQ signals then allow you to do lots of clever things like determine cyclic content, noise ratio, entropy etc of the time series. Now how you use these measures is up to you.
I eliminate the FFT when I find it is mathematically inconsistent to be applied to the problem at hand. The FFT assumes that your signal is stationary i.e. fixed mean, variance etc which clearly does not hold for price data. Why does price data have to be stationary?
Also I dont know why you have a problem with Juan posting links. They are very relevant and certainly compliment topics discussed here.
April 17th, 2008 at 11:34 am
This might be useful to understand what aiQuant presented in this post.
It’s a nice article by Ehlers.
April 17th, 2008 at 8:03 pm
Ok, I’ve noticed Juan referenced a few implementations and for retail software that is littered with casualties and limbs and roofs under administration, especially for where it is applied.
First of all, FX market is by large non-regulated. You guys evidently hang ‘out there’ in that space (at least Juan seems to). Code you get off those sites is littered with bugs trying to only copy a product student can design in a day. And those products DO NOT make money, it is a mass marketing exercise with overloaded technical terminology, simple.
Eliminating lag is a pointless exercise imho, but I am enjoying reading it (and being a bad/miserable guy in general).
Anyway, you should not play with fire in forex, because it does some spectacular ‘noise’ in execution and quoting, this is a quantum-non-mechanics-level hint :-). Period.
(Juan, so many people produce so many products out there these days most of them even in with a PhD in the title haven’t seen how they operate so they start supporting broker interfaces for a living and apply flawed theory and understanding to prices, calculation, assumptions, code and plenty more. No need to name names but they all have plenty of users, amateur or delusioned and plenty of forums. I’d leave it there if we can, but it is a business and ‘milky’ one too).
I don’t need Ehlers references as it really is not Rocket Science. Maybe its just me, but now I see 4 bars underlined while the reference was for 0-lag recently (can’t keep track of all the variables, sorry, might be just my impression but the article seems edited better).
Okay, I concede I’m harsh
So what now, I’ll have to play with you guys with real data? Inputs and outputs, well that’s fine, very simple. You’re all on, for the sake of humanity
aiQ, I know you work in a glass building and I know what you specialised in (it isn’t DSP but it is on your diagrams). See, it is all relative (lol).
April 17th, 2008 at 8:09 pm
So for the trick question: there is no output, at least according to Ehlers mass following.
That should give you a hint, so how about we go into real live datasets, you guys pick some historical data not to get in trouble with vendors,
April 17th, 2008 at 9:16 pm
I guess saying all this has gone far out topic at this point is a little late, isn’t it?
I do trade FX, but mainly to hedge my currency exposure on my international stock positions, or if i see some particular economic situation i can benefit better by using FX.
Besides that, i mostly trade stock options and the ocational bond.
I seriously dont get the point of your comments…
In fact this is the last time i answer to you.
By the way, aiQuant, dont you think it would be best to move/edit the unrelevant comments for the sake of clarity for those looking for more info on the post itself?
April 17th, 2008 at 11:24 pm
aiQuant, i’ve implemented the I/Q as described on the Ehlers paper i atached on comment 13, is this one the one you are referring on the post?
Also, i’ve tryied it out on both sine waves and real market data. My results show that on a single sine wave it works perfectly, but when adding more sines to the signal the results are not nearly that good. Most probably this problem is due to the interference between the diferent cycles in the data.
On market data the results are unclear, once again probably caused by the interference between cycles. This results are quite similar to the ones i’ve got some years ago when i tryied the Cycle Period measurement indicator from Ehlers.
I think the best way for identifiing cycles or seasonal activity i using wavelets. They are far have far more stable results.
(By the way, on market data i used both filtered and not filtered data, and while results with filtered data seemed better, they still where poor).
April 18th, 2008 at 9:11 am
The model described in ehler’s article is the same one I have implemented here. You might want to change the gains to see how it affects your result. While I cannot comment on whether its better than wavelets (because it really depends on the application) I will certanly say that this technique is by far the best approach to determint cyclic activity in real-time using individual tick data. Ofcourse ehler’s model (Variant 1) is pretty basic but you can do lots of things to improve the estimate.
April 18th, 2008 at 10:33 am
I’ve tryied modifying the gains.
The only difference i see is a change of amplitude in the quadrature (as expected due to the equation). One interesting experiment would be to lag the quadrature and optimize the two gains in order to reduce the squared error between the original function and the quadrature (to find the gains that let the amplitude of the quadrature just as the amplitude of the original signal (in this case a sine wave)).
April 18th, 2008 at 11:23 am
Variant 3 of my Hilbert transformer uses adaptive gain to change the amplitude of InPhase and Quadrature relative to a measure made at a higher resolution level. Although one might argue adaptive gain is overkill (which ofcourse it is if you apply it to resolutions greater than end of day prices), I have found that is yeilds significantly different results when applied to the high frequency tick.
April 18th, 2008 at 1:25 pm
Im just too anxious for when you post Variant 2 and 3! lol
I noted that both gains have equal number of delays in their inputs (0+6 for Gain1 and 2+4 for Gain2). I tryed modifying the delay number (i took of delays 1 and 6) and results are quite similar. Is there any sense on what i did?
April 19th, 2008 at 10:22 am
I have a little doubt, can we find the quadrature using the Pythagorean theorem?
Amplitude^2 = (InPhase)^2 + (Quadrature)^2
I mean, InPhase is already there, and the Amplitude can be estimated right?