#include <hurst_stocks.h>
Inheritance diagram for hurst_stocks::
Public Methods | |
hurst_stocks (const char *path) | |
~hurst_stocks () | |
void | test () |
Test the rescaled range algorithm on stock returns. More... | |
Private Methods | |
hurst_stocks (const hurst_stocks &rhs) |
Definition at line 10 of file hurst_stocks.h.
|
|
|
Definition at line 16 of file hurst_stocks.h. 00016 : hurst_test_base( path ) {} |
|
Definition at line 17 of file hurst_stocks.h. 00017 {} |
|
Test the rescaled range algorithm on stock returns. By hacking this code (e.g., uncommenting the commented parts and commenting out others) you can test the rescaled range on either a single stock over a range of n-day returns or you can test against the table of stocks (see the base class hurst_test_base). Sorry for the hackish nature of this code, but it worked for generating tests and the results on the Hurst exponent web page. Reimplemented from hurst_test_base. Definition at line 23 of file hurst_stocks.cpp. Referenced by main().
00024 { 00025 const size_t days = 10; 00026 // const size_t ReturnSize = 1024; 00027 const size_t ReturnSize = 8192; 00028 // const size_t DataSize = ReturnSize + days; 00029 const size_t DataSize = 8192; 00030 00031 // These arrays have to be static to get around some Microsoft 00032 // wierdness with large stack allocated arrays. 00033 static double data[ DataSize ]; 00034 static double returns[ ReturnSize ]; 00035 00036 rescaled_range hurst; 00037 rescaled_range::hurstInfo info; 00038 00039 // 00040 // To test a single return period against the table of stocks 00041 // uncomment this for loop and assign a single n-day return 00042 // period to blockSize. Comment out the enclosed for loop 00043 // (see below). 00044 // 00045 // for (size_t tableEntry = 0; tableEntry < tableSize_; tableEntry++) { 00046 // const char *fileName = equityTable_[tableEntry].file(); 00047 const char *fileName = "ibm_30year.csv"; 00048 size_t n = DataSize; 00049 if (ts.getTS( fileName, data, n, yahooTS::Close )) { 00050 assert(n == DataSize ); 00051 00052 // 00053 // Comment out the for loop if you are calculating returns 00054 // on a table of stocks and use a fixed return period. 00055 // The return period is defined by blockSize. 00056 // 00057 for (size_t blockSize = 1; blockSize <= 30; blockSize++) { 00058 for (size_t i = 0; i < ReturnSize; i++) 00059 returns[i] = 0; 00060 00061 size_t numReturns; 00062 numReturns = blockedLogReturn( data, returns, DataSize, blockSize ); 00063 00064 hurst.calc_hurst_est( returns, numReturns, info ); 00065 00070 00071 // const char *companyName = equityTable_[tableEntry].name(); 00072 00073 const char *companyName = "IBM Corp."; 00081 00082 // printf("%2d %7.4f\n", blockSize, sigma ); 00083 printf("%2d %7.4f\n", blockSize, info.slope()); 00084 } 00085 00093 } // for 00094 } |