Welcome to forexlab
This website is dedicated to wavelet analysis applied to realtime forex data.
The application can be started through this link: forex-analyzer
(The application is down at the moment because I work on a new version using Scala and D3.js)
For the user interested in mathematics I put together a short introduction in signal theory.
When it comes to signal analysis one of the first steps is to study the relationship between the time and frequency domain. It is the fourier transform (from the french mathematician Jean Baptiste Joseph Fourier) which establishes this time-frequency connection for integrable signals f(t) using the formula below:
Consequently the fourier transform shows what frequencies are present in the underlying signal f(t) and in what proportions. Then in the frequency domain we can analyse, filter or denoise our signal and finally send it back to the time domain using the inversre fourier transform.
I would like to illustrate this technique with a couple of examples:
1) f(t) = 4sin(2π25t) + 3sin(2π50t) + 2sin(2π100t) 2) f(t) = 4sin(2π25t) + 3sin(2π50t) + 2sin(2π100t) + noise(t) 3) f(t) = sin(2π100t2)
Example 1) is a superposition of three sinusoids with amplitudes 4, 3 and 2 with frequencies 25Hz, 50Hz and 100Hz.
On the left side is the signal in the time domain and on the right side is the spectrum.
The fourier transform clearly detects the three frequencies represented with the three bars. The height of the bars correspond to the amplitude.
Now in example 2) I take the same signal but corrupt it with zero-mean white noise.
Note how the signal in the time domain starts to get blurred but in the spectrum analysis we can still distinguish between the three frequencies.
In example 3) I am using a sinusoid whose frequency is getting steadily faster (a linear up-chirp).
Although we can calculate and plot the spectrum, it is not particularly useful. The fourier transform basically says all frequencies are present in the underlying signal f(t). Of course this is true but in this special example we are more interested in the instantaneous frequency. As you can see an up-chirp has a low frequency at the beginning and a high frequency at the end. The fourier transform cannot resolve this non-stationary feature. To illustrate this even better I show a linear down-chirp and no surprise, the spectrum is exactly the same.
In order to overcome this problem, researcher came up with the idea to divide a longer time signal into shorter segments (windows)
and then calculate the Fourier transform separately on each shorter segment.
This approach is called short-term Fourier transform (STFT) and for more details I refer to wikipedia.
It looks like this is a solution for analysing time dependant frequency but the problem with STFT is, the resolution is fixed (based on the width of the window) and it is not possible to get a good resolution in both domains, time and frequency. For example I can use a wide window which gives a good frequency resolution but a bad time resolution. On the other hand a narrow window gives a poor frequency resolution but a better time resolution. This limitation of the STFT is closely linked to the Heisenberg Uncertainty Principle.
Fourier analysis is like the starting point in signal analysis and it has many applications in physics, acoustics, optics, partial differential equations and many more. It is best suited for stationary, periodic signals. However many signals are non-stationary (especially in the financial markets) and in order to analyse these we need a framework which can give a good time and frequency resolution for both high- and low frequency events. This is where wavelets come in.
In the financial world many time series are of a non-stationary nature. The forex market for example exhibits quite complicated patterns over time. Sometimes it is trending, then it has abrupt changes or it can have big intraday gaps when economic news are announced. As I demonstrated in the last section the Fourier transform cannot efficiently capture such events.
In order to overcome this, we have to abandon the decomposition into sine waves of various frequencies and start to break up the signal into shifted and scaled versions of a mother wavelet ψ. But first of all, what are wavelets? It can be best described as "mini waves", a short burst of waves that quickly die away (in contrast to a sinus which goes on forever). In mathematical terms, a wavelet ψ has to satisfy the following two equations:
There exist many different wavelet functions. In the plot below I show the Morlet wavelet which is a continuous-time wavelet,
then variants of the Daubechies and Symlet wavelets which belong to the family of orthogonal and compactly supported wavelets.
Finally the Haar wavelet which was first discovered and is the simplest possible wavelet.
Now I can introduce the continuous wavelet transform W(s,u) which is a function of scale (s) and translation (u) and is obtained by projecting the underlying signal f(t) onto a particular wavelet ψ via
where ψ(s,u) is the scaled and translated version of the mother wavelet ψ.
Through this process we can capture features that are local in time and local in frequency because the scale in a wavelet transform is inversely proportional to a frequency interval. To show this graphically I added a diagram which is scaling a Daubechies-4 wavelet having scales from 2,4,6,..., to 18.
Note the general correspondence between scale and frequency:
Low scale s → compressed wavelet → rapidly changing details → high frequency High scale s → stretched wavelet → slowly changing details → low frequency
The disadvantage of the continuous wavelet transform lies in its computational complexity and redundancy. It turns out, that if we choose scales and positions based on powers of two (so-called dyadic scales) then the wavelet transform will be much more efficient and just as accurate. This approach is called the discrete wavelet transform DWT. It was Mallat who implemented 1988 such an algorithm using filter banks. In the following paragraph I give a short overview regarding this.
Each wavelet ψ has corresponding low- and high pass filters G0 and G1 which are used to decompose a signal into a details part (D) using G1 and an approximation part (A) using G0. This decomposition process can be iterated on successive approximations such that the signal is broken down into many lower resolution components. This is called a wavelet decomposition tree and the following picture should demonstrate this.
At each step the filtering results are downsampled by a factor of two (↓2) in order to preserve the original signal length. This results into the following representation of a signal f(t)
f(t) = A1(t) + D1(t) = A2(t) + D2(t) + D1(t) = A3(t) + D3(t) + D2(t) + D1(t) = AL(t) + DL(t) + DL-1(t) +...+ D1(t)
This process is invertible, meaning that we can reconstruct the signal f(t) using H0 (lowpass) and H1 (highpass) filter and upsampling by a factor of two (↑2).
In order to achieve perfect reconstruction it is required that the decomposition filters (G0,G1) together with their associated reconstruction filters (H0,H1) form a system of so-called quadrature mirror filters.
Now it is time to apply this technique to real case: Look at the noisy doppler signal below:
I use a a Daubechies-4 wavelet and the DWT algorithm to extract the details D1 to D5.
Pay attention how the low level details (D1, D2) capture the high frequency part (where all the noise is) whereas the details of higher order (D3, D4, D5) represent more the actual content of the signal.
This idea to separate a signal into a "true" part and a "noisy" part is very appealing to researchers. The DWT approach gives us a framework where we can denoise the details using various threshold methods. The most widely-used are hard- and soft thresholding:
where λ is the universal threshold suggested by Donoho and Johnstone (1994) and n is the length of the signal. Hence the details D1 to D5 are passed through such a thresholding process before they are used to reconstruct the signal. The reconstruction indeed is then the denoised version of the original signal.
Below I went through these steps using a soft threshold and added the denoised signal (red) to the noisy doppler (blue).
Wavelet analysis is a very powerful tool to explore all kind of signals and to fully capture the information in a time series regarding time and scale. In the 90s big progresses were made (DWT, filter banks) and today wavelets are used in image compression, smoothing/denoising data and communication applications.
My goal is to add wavelet analysis in the area of technical analysis for financial time series. Since this idea is not very widespread, I developed my own application: Forex-Analyzer
My name is Thomas Saladin and I founded forexlab.ch in the year 2015.
I am holding a Master’s degree in Mathematics (1997) from the Swiss Federal Institute of Technology (ETH) in Zurich.
In 2003 I earned the Financial Risk Manager (FRM) designation.
Since more than 15 years I am a full-stack software developer (JavaEE/Spring, Scala, PL/SQL, Webservices, Java/Typescript, Angular).
When I was young, I was an enthusiastic chess player and I played many years in the NLB.
Today I like to follow the economic news and to trade the forex market.
White moves and wins.