00001
00052
00053
00054 #include <stdio.h>
00055
00056 #include "invpacktree_int.h"
00057 #include "packtree_int.h"
00058 #include "support.h"
00059 #include "delta.h"
00060 #include "line_int.h"
00061 #include "costwidth.h"
00062 #include "yahooTS.h"
00063
00064
00070 void copy( int *destVec, int *srcVec, const size_t N )
00071 {
00072 for (size_t i = 0; i < N; i++)
00073 {
00074 destVec[i] = srcVec[i];
00075 }
00076 }
00077
00078
00079
00093 size_t calcPacketWidth( packdata_list<int> &bestBasisList )
00094 {
00095 packdata_list<int>::handle h;
00096 size_t totalWidth = 0;
00097
00098 for (h = bestBasisList.first(); h != 0; h = bestBasisList.next( h )) {
00099 packdata<int> *node = bestBasisList.get_item( h );
00100 const size_t len = node->length();
00101 const int *vec = node->getData();
00102 int nodeWidth = support::vecWidth( vec, len );
00103 totalWidth += nodeWidth;
00104 }
00105
00106 return totalWidth;
00107 }
00108
00109
00110
00119 size_t packet_calc( const int *intVec,
00120 const int N )
00121 {
00122
00123 line_int<packcontainer_int> line;
00124
00125
00126 packtree_int tree( intVec, N, &line );
00127
00128
00129 packnode<int> *treeRoot = tree.getRoot();
00130
00131
00132 costwidth cost( treeRoot );
00133
00134
00135 tree.bestBasis();
00136
00137
00138
00139
00140
00141 packdata_list<int> bestBasis = tree.getBestBasisList();
00142
00143
00144
00145 size_t width = calcPacketWidth( bestBasis );
00146
00147 return width;
00148 }
00149
00150
00162 void rollingCompressWindow(int *intVec,
00163 const size_t N,
00164 const size_t winSize )
00165 {
00166 int *window = new int[ winSize ];
00167
00168 for (size_t i = 0; i < N - winSize; i++) {
00169 copy( window, &intVec[i], winSize );
00170 const size_t windowWidth = support::vecWidth( window, winSize );
00171 const size_t packetWidth = packet_calc( window, winSize );
00172 const float compPercent = (1.0 - ((float)packetWidth/(float)windowWidth)) * 100.0;
00173 printf("%7.4f\n", compPercent );
00174 }
00175
00176 delete [] window;
00177 }
00178
00179
00183 void printTS(const double *ts, const size_t N )
00184 {
00185 for (size_t i = 0; i < N; i++) {
00186 printf("%7.4f\n", ts[i] );
00187 }
00188 }
00189
00190
00191
00196 double *calcReturnSeries( double *ret,
00197 const double *ts,
00198 const size_t N,
00199 const size_t period )
00200 {
00201 }
00202
00203
00210 int main()
00211 {
00212 const char *files[] = { "aa",
00213 "amat",
00214 "ba",
00215 "cof",
00216 "ge",
00217 "ibm",
00218 "intc",
00219 "mmm",
00220 "mrk",
00221 "wmt",
00222 0
00223 };
00224
00225 const size_t N = 563;
00226 const size_t winSize = 64;
00227 const char *fileName = "amat";
00228 double realVec[ N ];
00229 int intVec[ N ];
00230 int window[ winSize ];
00231
00232
00233 const char *dataDirPath = "..\\data\\equities\\";
00234 yahooTS ts( dataDirPath );
00235
00236 size_t n = N;
00237 if (! ts.getTS( fileName, realVec, n, yahooTS::Close )) {
00238 printf("error reading file %s\n", fileName );
00239 return 0;
00240 }
00241
00242 if (n != N) {
00243 printf("Error: %d out of %d data elements read\n", n, N );
00244 return 0;
00245 }
00246
00247 support::decimalToInt( intVec, realVec, N );
00248
00249 rollingCompressWindow( intVec, N, winSize );
00250
00251 return 0;
00252 }