Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

nonstat.cpp File Reference

Wavelet spectral analysis for non-stationary data (e.g., equity close prices). More...

#include <assert.h>
#include <stdio.h>
#include <vector>
#include "signalUtil.h"
#include "spectrum.h"
#include "yahooTS.h"
#include "line.h"

Go to the source code of this file.

Functions

void calcReturn (double *ret, const double *close, size_t N)
int main ()
 \function. More...


Detailed Description

Wavelet spectral analysis for non-stationary data (e.g., equity close prices).

Non-stationary signals are signals that do repeat infinitely, as sine and cosine based signals do.

The documentation in this file is formatted for doxygen (see www.doxygen.org).

Copyright and Use

You may use this source code without limitation and without fee as long as you include: This software was written and is copyrighted by Ian Kaplan, Bear Products International, www.bearcave.com, 2002.

This software is provided "as is", without any warranty or claim as to its usefulness. Anyone who uses this source code uses it at their own risk. Nor is any support provided by Ian Kaplan and Bear Products International.

Please send any bug fixes or suggested source changes to:

     iank@bearcave.com

Author:
Ian Kaplan

Definition in file nonstat.cpp.


Function Documentation

void calcReturn ( double * ret,
const double * close,
size_t N )
 

Definition at line 51 of file nonstat.cpp.

Referenced by main().

00052 {
00053   for (size_t i = 1; i <= N; i++)
00054     ret[i-1] = (close[i] - close[i-1])/close[i-1];
00055 }

int main ( )
 

\function.

The entry point for code to test the wavelet packet transform.

The code in main provides a simple example of how to call the wavelet packet transform code.

This test case can be used with various wavelet functions (e.g., Haar, linear interpolation, Daubechies D4, polynomial interpolation). In the context of filters, the polynomial interpolation wavelets (see poly.h and polyHaar.h) are very bad choices. The polynomial interpolation wavelets do not divide the spectrum into high and low frequency components. Instead, the power spectrum shows one peak. I'm not sure if this means that the polynomial interpolation wavelets are bad for all applications. For example, another way to look at wavelets is as approximation functions. For example, wavelet compression relies approximation functions. In this case polynomial wavelets may be a good choice for some data sets.

Definition at line 82 of file nonstat.cpp.

00083 {
00084   const size_t NClose = 513;
00085   double close[NClose];
00086 
00087   const char *path = "..\\data\\equities\\";
00088   yahooTS ts( path );
00089   const char *stock = "amat";
00090 
00091   size_t n = NClose;
00092   ts.getTS( stock, close, n, yahooTS::Close );
00093 
00094   if (n != NClose) {
00095     printf("Error reading file %s%s\n", path, stock );
00096     return 0;
00097   }
00098 
00099   const size_t N = 512;
00100   double ret[ N ];
00101 
00102   calcReturn( ret, close, N );
00103 
00104   // prVec( ret, N );
00105 
00106   // linear interpolation wavelet
00107   line<double *> w;
00108 
00109   double *ptr = ret;  
00110   w.forwardTrans( ptr, N );
00111 
00112   std::vector<double> powerVec;
00113   spectrum::spectralCalc( ret, N, powerVec );
00114 
00115   //
00116   // Print out the power spectrum
00117   //
00118   size_t len = powerVec.size();
00119   for (size_t i = 0; i < len; i++) {
00120     // printf("%2d, %7.4f\n", i, powerVec[i] );
00121   }
00122 
00123   double d1[N], d2[N];
00124 
00125   spectrum::copyBands( d1, ret, N, 0, 7 );
00126   spectrum::copyBands( d2, ret, N, 8, 9 );
00127 
00128   ptr = d1;
00129   w.inverseTrans( ptr, N );
00130 
00131   ptr = d2;
00132   w.inverseTrans( ptr, N );
00133 
00134   //
00135   // Print out the lower half of the spectrum
00136   //
00137   // signalUtil::prVec( d1, N );
00138 
00139   //
00140   // Print out the upper half of the spectrum
00141   //
00142   signalUtil::prVec( d2, N );
00143 
00144   return 0;
00145 }


Generated at Tue May 27 21:56:17 2003 for Wavelet compression, determinism and time series forecasting by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001