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

nonstat.cpp

Go to the documentation of this file.
00001 
00038 
00039 #include <assert.h>
00040 #include <stdio.h>
00041 
00042 #include <vector>
00043 
00044 #include "signalUtil.h"
00045 #include "spectrum.h"
00046 #include "yahooTS.h"
00047 #include "line.h"
00048 
00049 
00050 
00051 void calcReturn( double *ret, const double *close, size_t N )
00052 {
00053   for (size_t i = 1; i <= N; i++)
00054     ret[i-1] = (close[i] - close[i-1])/close[i-1];
00055 }
00056 
00057 
00058 
00081 int
00082 main()
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 Sun Aug 18 16:56:41 2002 for Wavelet Spectral Analysis by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001