[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Wavelet's



PureBytes Links

Trading Reference Links

Hi Angel

"... The wavelet transform code is adapted from the Imager Wavelet Library
written  by Bob Lewis at University of British Columbia.  The library and
excellent lecture notes are available by ftp from
ftp.cs.ubc.ca/pub/local/bobl/wvlt/ or on
WWW at http://www.cs.ubc.ca/nest/imager/contributions/bobl/wvlt/top.html.

{I think that this stuff is downloadable in Ghost Script}

Also ... from the Timestat "Tutorial.txt" ... since Wavelets are not covered
in the KyPlot help files

11. Discrete wavelet transform (DWT) - the wavelet transform has been a hot
topic in math, science, engineering, and more recently, economics and
finance.
Broad references are generally abundant and easy to find; references on
applications in economics and finance are few right now but increasing in
number.  I cannot possibly do justice to its richness and complexity here or
in
the program.  My implementation does allow you to play with the
1-dimensional
DWT and hopefully gain some understanding through actual examples.  The
algorithm itself is actually much simpler than the mathematical concepts in
my
opinion.  The actual DWT code in C is probably no more than 100 lines.  I
adapted this version from Bob Lewis' Imager Wavelet Library (see
README.TXT), so some of the bases implemented are probably more suitable
for image processing.  Basically, wavelets allow simultaneous decomposition
of
a time series into components (bases) which are localized in both time and
frequency.  This is unlike FFT where the component sine and cosine waves are
localized in frequency but totally unlocalized in time.

Example: With file '1994.xls' loaded, select column B (DJIA), select menu
item
'Calculations/Z-Score' to normalize the series to zero mean and variance one
(this is not necessary for DWT but it makes the charting below easier).
Select
the newly created column C (the Z-score); select menu item
'Analysis/Discrete
Wavelet Transform'.  The DWT dialog allows you to choose from a selection of
bases and perform thresholding on the coefficients.  For now leave the
threshold
slide bar at 0% (no thresholding), choose the Daubechies 4 basis, check the
forward transform box (default) and check the 'Freq. Band Decomposition'
box.
Click 'OK'.  On the spreadsheet you now have a new column of Daub4 DWT
coefficients arranged in the standard manner: rows 130 to 257 represent the
upper frequency band detail (roughly Fc/2 to Fc, where Fc is the Nyquist
critical
frequency or 1/2 the sampling rate of the input series.  In this case, the
sampling
rate is 1/trading day so Fc is 1/(2 trading days)).  Rows 66 to 129
represent the
next band (Fc/4 to Fc/2), and so on until the first coefficient represents
the
scaling function.  This arrangement comes from the multiresolution analysis
(MRA) of wavelet transform; look up any introduction to wavelets for a
discussion.  The next 7 columns represent the spectral components of the
input
series.  Summing the 7 columns row by row would reproduce the original input
series.  As the column titles indicate, each column represents the
'information
content' of the frequency bands as described above.  At this point one can
throw
away the high (or the low) frequency bands similar to filtering using FFT's.
One recently proposed technique involves using separate neural networks to
forecast each individual decomposed series and recombine the results to
obtain a
forecast for the original series.  Select column D (Daub4 DWT) and select
menu
item Analysis/Discrete Wavelet Transform.  Uncheck the Forward/Reverse
check box (to get the reverse transform).  Clicking 'OK' at this point would
just
give us back the original input series (Z-score of DJIA).  Move the
'Quantile
threshold' slide bar to 75%, make sure the basis option is set for
'Daubechies 4'
and click 'OK'.  The program now sets those coefficients that represent the
smallest 75% in magnitude to zero, and then performs the inverse transform.
Select columns C and E and chart them.  Note that, with only 25% of the
wavelet coefficients we get a surprisingly good reproduction of the original
series.  Note also that this 'approximation' is different from the usual
smoothing
or averaging in that small rapid oscillations are eliminated but all sharp
turns or
significant magnitude are faithfully captured with great accuracy.  This is
one of
the advantages of wavelets over Fourier transform; you would need large
number of FFT coefficients to accurately reproduce large,  rapid, and
isolated
variations while it takes only a few compact wavelets to do the same job.

Some final comments about the DWT.  To actually see what the wavelet bases
look like, first inverse transform a series with only one non-zero
coefficient.
For example, fill an empty column with zeroes from row 1 to row 256, set row
12 to = 1, inverse transform this column with a basis of your choice, and
then
chart the output series to see what the wavelet looks like.  What is the
downside
to using the DWT?  Like the FFT, the DWT suffers from aliasing effects at
the
ends.  The algorithm assumes the series are periodic just as the FFT.
Padding
with zeroes alleviates but does not solve the problem.  For forecasting and
financial time series analysis, the ending points of the series are
precisely where
the most important informations may lie.  The solution to this problem is to
use
orthonormal bases which 'live' in finite intervals.  I hope to implement
such
wavelets on the interval sometime.  Which basis should you use?  There is no
'wrong' basis--any basis will transform any data series.  You can choose a
'best' basis based on the data pattern.  For example, I used Daub4 basis
above because these wavelets has sharp corners
(mathematically--discontinuities
in the first derivative) which happen to suit the stock data well.  If I had
used smoother wavelets (Daub8 or Daub16 for example), the inverse transform
with 75% thresholding would show rounded corners.  There are more systematic
ways to understand and choose bases, but that is beyond our scope here.

=================

KyPlot has all of this ... plus lots more in dropdown menus in "Math" -->
"Wavelet Analysis" etc.

Best regards

Walter