Quantcast aiQUANT » Hilbert Transform

Archive for the 'Hilbert Transform' Category

Visualizing Price Data as a Complex Phasor

Hilbert Transform, Signal Processing, Technical Indicators 22 Comments »

In 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:

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 \small\text{a + ib} where \small\text{a} is the “real” or InPhase part and \small\text{b} is the “imaginary” or Quadrature part. Plotting \small\text{a} and \small\text{b} 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.

HilT_var1.png

 

Applying a chirp signal to the input:

ChrResHT2.png

 

cplxPhasVar1.pngDue 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 shortShowCycVar1_2.png 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.

 

brnMotPhasor.png

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:

  1. Cycle 1: On Phasor plot points 7, 8, 9 => 3 bar cycle. On time series plot this cycle pertains to points 3, 4, 5.
  2. 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.
  3. 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.

Wavelet feature extraction model - some thoughts

Hilbert Transform, Signal Processing, Wavelet Transform 7 Comments »

In the previous post I highlighted a wavelet based feature extraction model for financial time series. The intention was to use it as a starting point for developing an improved model. To start with let me explain what the model referred to in the previous post is meant to do.

There are two sections to the model. Common to both sections is a DWT smoother which is basically a lowpass filter. The first section analyses the smoothed volatility of the time series to determine the break points which they refer to as “variance change”. The second section performs FFT decomposition on the smoothed time series to obtain the dominant cycle. The trend and turning points are determined from the smoothed time series also.

Here is what I think about the model

  • Firstly I don’t support the researchers’ choice of applying the Fourier Transform to determine the dominant cycle period. I explain in this post why FFTs should be avoided when analysing financial time series data. I am in favour of the Hilbert transform mainly for two reasons:
    1. The Hilbert transform works under the assumption that each price point has a phase difference to the previous and subsequant price points. This allows evaluation of the cycle length on a bar-by-bar basis, which unlike the FFT does not impose a constraint on the observation window length.
    2. The Hilbert transform provides a way of visualising interaction of short term cycles with longer term cycles on a phasor plot.
  • What I wish to do is to replace the FFT part with the Hilbert Transform and another algorithm to determine the phasor plot of the actual time series - as shown below:

wavModel.png

Using Simulink to implement and test models

Hilbert Transform, Matlab, Signal Processing, Transform Algebra 4 Comments »

In addition to Matlab, The Mathworks offer a product called Simulink which is a design platform for implementing and testing model-based systems. Most of my experience using Simulink borders on modelling Control Systems and DSP architectures. However, as the Mathworks have pointed out in a recent webinar, Simulink can be extended to develop and test finance based models such as a trading system or sub-systems that form part of a larger model.

I decided to implemented a Hilbert Transformer model for price data using Simulink which is shown below:

HilbertDiagram.jpg

The model has input “simin” which takes the price data from the matlab workspace as discrete points one at a time and applies unit delay (represented by “1/Z”) and gain which is basically multiplication by the shown number. Individual Real and Complex parts are combined to create complex numbers which is then outputted to the workspace.

Simply put, the Hilbert Transform converts price data into complex number form so that one may go about calculating different measures that are not possible to calculate using just the price itself. My previous post mentions measures that are calculated using hilbert transformed price. The relationship between the actual price and the hilbert transformed price is

\small \text{Actual Price = sqrt{a^2 + b^2}} for a hilbert price \small\text{a + ib}.

As one would expect the model implemented above suffers lag. This is confirmed by comparing the Actual price with the price reconstructed from the hilbert complex numbers:

HilbertSimulinkModel.png

The model does not induce any loss or gain in magnitude, but there is a lag of 4 bars. This implies that the hilbert price for the current bar actually corresponds to the price 4 bars ago - something we should consider when using hilbert prices to deduce other measures.

Other Links:

  1. The wikipedia page covers basics of the hilbert transform.
  2. The Mathworks have a webinar which has a section on using Simulink for designing and testing Algorithmic Trading models. You can view this webinar here. Its round about 40:00mins into the presentation where the section on Simulink begins.
  3. Simulink totorial can be found here.
  4. There a number of webinars and example models at the Mathworks website for one to get started using simulink.

Creating “Complex” price from “Real” price

Hilbert Transform, Technical Indicators No Comments »

There are many benefits of converting price data in complex number form. The presence of an Imaginary component gives one the freedom to create other kinds of indicators which can provide further insight into the statistical properties of the asset price. For example, indicators that fall into the categories below can only be derived from complex price data:

  • Signal to Noise ratio (SNR)
  • Cycle Period
  • Phasor diagrams
  • Predictive Indicators (i.e. filters with Negative Lag)
  • Power Spectral Density of the price

A complex number takes the form

a + ib where i=sqrt{-1}

Real price data only have an a component, aka the InPhase component. The aim is to derive the corresponding Quadrature component using the InPhase data of the price at a given bar. The Hilbert Transform provides a way of doing this, and an excellent description can be found at wikipedia.

To complement the notes we can think of the Hilbert Transform as a control system, the simplest of which looks like:

HilTransf.png

Note that z^{-n} represents the z-domain delay operator. It remembers its input value for n samples into the future.

We shall discuss Indicators based on Complex Price Data in due course.

Close
E-mail It