2.Normal 5-Day Simple Moving Average
3.Continuous Wavelet Transform of Keppel Corp
4. Compression
5. Residuals of Compression
6. Denoised and original signal
7. Independent interval thresholds for change in characteristics
8. Residuals of Denoising
10. Residuals of Regression
3.Continuous Wavelet Transform of Keppel Corp
4. Compression
5. Residuals of Compression
6. Denoised and original signal
7. Independent interval thresholds for change in characteristics
8. Residuals of Denoising
10. Residuals of Regression# Credits and Citations for posts on Wavelets: Much of the pioneering work on denoising using wavelets and the use of thresholds was done by D.L Donoho and I.M Johnstone (USA) and Kerkyacharian and Picard (France). Also thanks to Amara Graps of the South-West Research Institute , Colorado and and Robi Polikar of Rowden University,NJ whose articles made understanding of Wavelets by the layman possible. And finally, thanks to Matlab, whose Wavelet Toolbox is the industry standard, and whose User Guide is better than any text book.
Every technical analysis enthusiast is familiar with the Moving Average and what it does- it smoothes the signal and thus acts as a de-noiser so that you can ignore the noise. But noise always has to be user-defined as what is not noise to a short term investor is noise to the long term investor. Although a useful tool for medium term and longer term traders, a Moving Average is less useful to the short term trader; and choosing the optimal period for an MA is a bit of guesswork, since you can back test all you want, but the market and the stock's characteristics are always changing.
In this post we use Wavelets to denoise a stock signal [the example used here is Keppel Corp- a Blue Chip on the Singapore Exchange]. Wavelets are a more recent technology used in digital signal processing for working with signals that are not regular, and have sharp sudden and transient moves. Fourier transforms with their regular sinusoids cannot handle such signals. Stock market signals fit this category of signals. In wavelet methodology, the signal is also decomposed into constituent wavelets like in Fourier transforn, but different parts of the signal in time are handled by different stretched and shifted versions of the mother wavelet. Thus changes in characteristics of the stock signals can be accomodated, Moreover, wavelets have compact support and are orthogonal. Compact support means the wavelest have a cut-off point unlike regular sine waves which go on forever. Orthogonal means there is no overlap of information being handled by different constituent wavelets. There are three different ways that Wavelets can take away noise from a signal: (1) by normal denoising (2) by compression (3) by regression. Although the algorithms for each is different, the end result is the same: you get a signal that is smoother than the original signal. The test for how good a denoiser is can be shown by the residuals. That is, after denoising, compression or regression, the leftovers, if they are indeed (white) noise will show a random distribution. Lets go through each image from the top:
Image 1 shows a technical indicator I developed using the wavelets methods below. The idea is to Buy when the indicator crosses above zero and sell when it crosses below zero. As you can see from the vertical lines aligned with the stock chart, the indicator is quite efficient. Only problem is how do we determine whether the crossing of zero can be sustained. We will have to use it in conjunction with another indicator.
Inage 2 shows a normal 5-day Simple Moving Average of the stock. 5- day is too short and you won't want to move in and out of the market so often.
Inage 3 shows a Continuous Wavelet Transform of Keppel Corp using a Daubechies 4 to Level 5, and scale 1: 128. All it can tell you is that the stock does not move randomly. There is a large deterministic component, but it is always changing in its parameters. The image shows the fractal self- similarity characteristic of Chaos Theory.
Image 4 shows how compression can give you a smoother less noisy signal. In this case, 99 % of the signal's energy (entropy) was retained while 92 % of the image was padded with zeroes. That is, only 8 % of signals's content was sufficient to derive the compressed signal. But if you look at the residuals in image 5 , the residuals are not as random as the residuals for denoising and regression below. Which means that some useful content was also taken away. Still I think that if we are trading a Blue Chip like Keppel Corp where we can have a greater tolerance for 'noise', this derived signal is the best of the four methods here.
Image 6 shows the signal after denoising, and it hugs closely the original signal and has no lag. This denoising was done with two different thresholds. As shown in image 7, the market got noiser and more volatile during the last 300 trading days or so, so a different threshold for defining what is noise was used. The residuals show that the denoising was quite effective.
Image 9 and 10 shows how regression can also be considered a form of denoising. Regression algorithms are 'fitting' algorithms but the end result is the same. We get a smoother less nosiy derived signal.
I could fine-tune the regular denoising and regression algorithms to hug the main signal less as in the compression algorithm. But it's hard work and still a trial and error thing choosing the right wavelet family, the appropriate number of vanishing moments, level of decomposition etc. Nevertheless my point is that it's time the people who design technical indicators think of using Wavelets to do the work. Wavelets are a better tool to analyse the kind of signals that stock markets generate, taking into account the non-linear adaptive dynamics that characterise stock markets.

