Quantcast aiQUANT » Signal Processing

Archive for the 'Signal Processing' Category

Signal processing with heavy-tailed distributions

Fat Tails, Financial Mathematics, Signal Processing No Comments »

While reading on the subject of hard to forecast events I decided to investigate what the Signal Processing domain had to offer in terms of models that account for “fat-tail” distributions. Thankfully I came across a set of papers that specifically address the nature of such distributions in their modeling approach - which I think is insightful and worth having a look at despite being off-topic to quant work.

The set of papers was collectively published in a special edition journal under the theme “Signal processing with heavy-tailed distributions” and can be found here. I have uploaded the preface to the journal which gives a good overview of applications. You can download it from here.

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.

Negative lag filter - new algorithm

Filter Design, Signal Processing, Technical Indicators 2 Comments »

In an earlier post I mentioned a filtering algorithm which demonstrated negative lag for low frequencies (trending market) and high magnitude gain for higher frequencies (cyclic market).  I modified the algorithm to deal with the high frequency overshoot problem by removing the dependency on the second order power of the price.  Although the filter copes relatively well at higher frequencies, we no longer have negative lag at the low frequency.  Perhaps it would be nice to compare lag and magnitude gain of both filters across all frequencies to understand the actual differences.

negLagNew.png

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

Automatic analysis of volatile financial time series

Signal Processing, Wavelet Transform 1 Comment »

In the previous post I pointed out a model developed by researchers at the University of Surrey for analysing volatile financial time series. The model is actually quite straight forward to implement and my initial plan was to reproduce it, but haven’t got round to doing so because of other commitments. Nonetheless the plan continues and I shall be posting details of the modifications I wish to make to the model already proposed.

I found a poster presentation drawn up by the same researchers which provides a good summary of the paper they published.

wavVolPoster.jpg

Alternatively you can download a PDF file of the diagram from here.

Wavelets and High-frequency data

High Frequency, Signal Processing, Wavelet Transform 1 Comment »

This presentation covers almost everything I have been wanting to convey about the usefulness of wavelets.

The researchers propose a prototype feature extraction system, the block diagram of which is reproduced below:

wavFXsys.png

Questions I ask:

  1. It appears that the researchers settled for a fixed wavelet function for doing the decomposition. Are there any benefits in using a hybrid of different wavelet families for decomposing different parts of the time series?
  2. Is it possible to create a custom wavelet family with the aim that it works better than the other wavelet families commonly used? What should be the line of approach to this kind of problem? Inductive or Deductive?

I am tempted to write a Matlab model to replicate this system and maybe adapt it a little bit, but there is a paper written by the researchers that needs to be understood first. You can download it from here.

Fourier Transforms and financial time series data

Fourier Transform, Signal Processing 2 Comments »

The purpose of this post is two fold:

  1. Discuss aspects of the Fourier Transform that will form necessary grounding for subsequent understanding of the Wavelet Transform.
  2. State why Fourier Transforms are inappropriate for analyzing financial time series data.

The Fourier Transform

In the previous post I hinted at the relationship between the time domain and the frequency domain representations of a signal. The figure below gives a clearer picture of that

fourierTdFd.png

A signal that oscillates rapidly with respect to time has a higher frequency relative to one that oscillates slowly. A pure sine wave has only one frequency component, but not all signals are sinusoidal - some may be composed of a number of different frequency signals added together, others such as stock prices can have signal frequency components that change with time. In order to determine the frequency content of a signal, one needs to perform a conversion into the frequency domain, there by giving us a view in the direction shown by the yellow arrow in the figure above (the spectrum of the signal).

The Fourier transform is one of a number of algorithms that provide a way evaluating the frequency content of a signal. The transformation into the frequency domain follows the equation

X(f)=\int_{\small-\infty}^\infty\text{x(t)}e^{-2j\p\text{ft}}dt

and the inverse Fourier transform is

\text{x(t)}=\int_{\small-\infty}^\infty\text{X(f)}e^{2j\p\text{ft}}df

Now the equations listed above belong to one of the many variants of the Fourier transform - the Continuous Time Continuous Frequency Fourier transform. There are few general points to note:

  1. The equation of the Fourier transform tells us that the integration needs to occur for all times within the range \small-\infty to \small\infty. The implication of this is that the occurrence of time domain signal \small\text{x(t)} needs to exist for any value of time within the said range.
  2. For the given integration bounds, frequency \small\text{f} needs to be a constant value. This implies that signal \small\text{x(t)} needs to be time-invariant i.e. stationary.

ftFamFigure.png

I have drawn up a chart showing the different variants of the FT and their relationship with each other. The diagram is work in progress so please feel free to recommend any changes that can be made. I intend to extend the family tree to show other transforms relevant to our discussions.

The choice of invoking a particular transform depends on the nature of the signal undergoing the transformation (continuous or discrete in time) and the level of detail we wish to obtain in the frequency domain (continuous or discrete frequency bins). This also applies to the inverse Transform.

I do not wish to talk any more than this about the FT as I have provided a few good resources at the end of this post to complement what has already been discussed.

Application to financial time series data

There are two main reasons why FTs are inappropriate for analyzing financial data:

  1. Bullet points (1.) and (2.) above do not hold for stock prices or any other asset price. Particularly with regard to bullet point (2.) stock prices do not have a constant frequency with respect to time. This points to another short-coming of the algorithm - it tells us nothing about the points at which a frequency change occurs in the time domain, which is essentially one of the things we want to know.
  2. The other reason is that FTs deliver poor resolution for cycle period measurement. Suppose we perform a 128-point FFT. The largest cycle the algorithm can record is 128 bars. Cycles larger than 128 cannot be recorded because the window length is not large enough for it to be captured fully. One may wish to increase the window length, but it is likely that stationarity is not maintained. And also, only cycles that are an integer power of two (2, 4, 8, 16, 32, 64) can be recorded (in the case of the DTDF transform). Anything that falls between these boundaries cannot be measured accurately as it is mathematically impossible for the algorithm to do so.

Further Reading:

Waves and Wavelets

Fourier Transform, Signal Processing, Wavelet Transform 1 Comment »

Here I write about things that may aid those who are new to Signal Processing to grasp a few concepts without necessarily referring to a textbook.

The table below shows some the differences between a Wave and a Wavelet.

waveLetComp.png

Essentially a Wavelet is a small wave with pretty much the opposite characteristics to that of a wave. This is exactly what makes their application appealing to time variant signals such as stock prices. Accompanying wavelets is the Wavelet transform algorithm, of which there are many variants, but all essentially do the same thing using different ways. The table below shows the difference between two contrasting analytical algorithms.

comp2.png

So what are these “domains” we are referring to? Any signal that is a function of time is in the time domain. Stock prices are in the time domain because the each point in time has a price associated with it. Now consider another time domain signal such as a sine wave. Lets assume that this signal has amplitude 2 and takes 5 seconds before it begins to repeat itself i.e. it’s period is 5 seconds. Now the frequency of this signal is the inverse of the period which is 0.2 hertz in our case. Also the amplitude of the signal is the in the frequency domain our sine wave will look like a single spike of height 2 at the point 0.2 hertz. This is because the frequency domain shows the amplitude or power of the signal (y-axis) for different frequencies (x-axis), which is referred to as the spectrum. The spectrum of a stock price takes a more complicated form and is more difficult to determine, but the wavelet transform takes care of that.

Now it is worth pointing out that wavelets are usually combined with other signal processing algorithms to form “systems” that enable the transformation from the time domain into the frequency domain to happen in particular ways, depending on what you want to achieve. For instance instead of determining the spectrum of the stock price one may want to develop a filtering scheme or a trend/cycle estimation scheme. We shall see more of that later.

Notes on Sampling rate conversion

Fourier Transform, Signal Processing, Wavelet Transform 5 Comments »

For those not too familiar with wavelet theory I have attached some notes here for easy view. The idea of a non-fixed sampling rate is fundamental to the Wavelet Transform and it is very important to understand these concepts before delving into actual applications. The newbie may find some of the material heavy going in terms of the maths involved, but I believe understanding ideas are more important than being able to evaluate intagrals.

The first set of notes presents basic multirate concepts. The notion of upsampling and downsampling are discussed in terms of time and frequency domain characteristics.

The second set of notes gives a very friendly introduction to the Wavelet Transform and shows it’s advantages over the Fourier Transform.

I have also attached a very readable paper titled “Wavelets for kids“. You can download it from here

Over the next few posts we shall look at some wavelet decomposition models for financial time series.

Wavelet textbooks

Signal Processing, Wavelet Transform 2 Comments »

I wish to start discussing wavelets, which is yet another branch of signal processing that has had success in feature extraction and volatility forecasting for time series. I suggest the following three excellent books for the reader who is interested in wavelets:

Additionally there are numerous web resources on wavelets and the like, with about two million hits via google search.

Close
E-mail It