00001
00013 #include <iostream>
00014 #include <stack>
00015 #include <algorithm>
00016 #include <vector>
00017
00018 #include <algorithm>
00019 #include <typeinfo>
00020
00021 #include <boost/bind.hpp>
00022 #include <boost/foreach.hpp>
00023 #include <boost/multi_array.hpp>
00024
00025 #include <boost/regex.hpp>
00026
00027 #include <ql/utilities/tracing.hpp>
00028
00029 #include "eleve/src/scal0.hpp"
00030
00031 #include <boost/algorithm/string/trim.hpp>
00032 #include <boost/tokenizer.hpp>
00033
00034 #include "eleve/src/loader0.hpp"
00035
00036 #define BOOST_TEST_NO_MAIN
00037
00038 #include <boost/test/unit_test.hpp>
00039
00040 #include "eleve/src/typing3.hpp"
00041 #include "eleve/src/typing1.hpp"
00042 #include "eleve/src0/csv1.hpp"
00043
00044 #include "acsvt0.hpp"
00045
00046 BOOST_GLOBAL_FIXTURE ( csv0 )
00047
00048 BOOST_AUTO_TEST_SUITE (frame0)
00049
00051
00052 BOOST_AUTO_TEST_CASE(csv1)
00053 {
00054 using namespace eepgwde::detail;
00055
00056 BOOST_TEST_MESSAGE("QuantLib::price::frame0::csv1");
00057
00058 BOOST_TEST_MESSAGE("QuantLib::price::frame0::csv1: " << frame.shape()[0] );
00059 BOOST_TEST_MESSAGE("QuantLib::price::frame0::csv1: " << frame.shape()[1] );
00060
00061 for (DataFrame::ma_any_t::size_type a = 0; a < frame.shape()[0]; ++a) {
00062 for (DataFrame::ma_any_t::size_type b = 0; b < frame.shape()[1]; ++b) {
00063 std::cerr << (frame[a][b]).type().name() << " "
00064 << boost::any_cast<std::string>(frame[a][b]) << " ";
00065 }
00066 std::cerr << endl;
00067 }
00068 }
00069
00071
00072 BOOST_AUTO_TEST_CASE(csv2)
00073 {
00074 using namespace eepgwde::detail;
00075
00076 BOOST_TEST_MESSAGE("QuantLib::price::frame::csv2");
00077
00078 BOOST_TEST_MESSAGE("QuantLib::price::frame::csv2: " << frame.shape()[0] );
00079 BOOST_TEST_MESSAGE("QuantLib::price::frame::csv2: " << frame.shape()[1] );
00080
00081 DataFrame::ma_any_t::size_type a = 0;
00082 for (DataFrame::ma_any_t::size_type b = 0; b < frame.shape()[1]; ++b) {
00083 std::cerr << (frame[a][b]).type().name() << " "
00084 << boost::any_cast<std::string>(frame[a][b]) << " ";
00085 std::cerr << endl;
00086 }
00087 }
00088
00090
00091 BOOST_AUTO_TEST_CASE(csv3)
00092 {
00093 using namespace eepgwde::detail;
00094
00095 BOOST_TEST_MESSAGE("QuantLib::price::frame::csv3");
00096
00097 BOOST_TEST_MESSAGE("QuantLib::price::frame::csv3: " << frame.shape()[0] );
00098 BOOST_TEST_MESSAGE("QuantLib::price::frame::csv3: " << frame.shape()[1] );
00099
00100 typedef boost::multi_array_types::index_range range;
00101
00102 DataFrame::ma_any_t::array_view<2>::type myview =
00103 frame[ boost::indices[range() <= 0][range()] ];
00104
00105 BOOST_TEST_MESSAGE("myview: "
00106 << myview.shape()[0] << " "
00107 << myview.shape()[1]);
00108
00109 DataFrame::ma_any_t::size_type rows0 = myview.shape()[0];
00110 DataFrame::ma_any_t::size_type cols0 = myview.shape()[1];
00111
00112 for (DataFrame::ma_any_t::size_type i = 0; i < rows0; ++i) {
00113 for (DataFrame::ma_any_t::size_type j = 0; j < cols0; ++j) {
00114 std::cerr << (myview[i][j]).type().name() << " "
00115 << boost::any_cast<std::string>(myview[i][j]) << " ";
00116 }
00117 std::cerr << endl;
00118 }
00119
00120 }
00121
00123
00124 BOOST_AUTO_TEST_CASE(csv4)
00125 {
00126 using namespace eepgwde::detail;
00127
00128 BOOST_TEST_MESSAGE("QuantLib::price::frame::csv4");
00129
00130 DataFrame df(frame);
00131
00132 cerr << "Frame header mappings\n";
00133 cerr << df.header.left;
00134 cerr << "\n";
00135
00136 DataFrame::ma_any_t::size_type rows0 = df.payload->shape()[0];
00137 DataFrame::ma_any_t::size_type cols0 = df.payload->shape()[1];
00138
00139 for (DataFrame::ma_any_t::size_type i = 0; i < rows0; ++i) {
00140 for (DataFrame::ma_any_t::size_type j = 0; j < cols0; ++j) {
00141 std::cerr << ( (*df.payload)[i][j]).type().name() << " "
00142 << boost::any_cast<std::string>( (*df.payload)[i][j]) << " ";
00143 }
00144 std::cerr << endl;
00145 }
00146
00147 }
00148
00150
00151 BOOST_AUTO_TEST_CASE(csv5)
00152 {
00153 using namespace eepgwde::detail;
00154
00155 BOOST_TEST_MESSAGE("QuantLib::price::frame::csv5");
00156
00157 DataFrame df(frame);
00158
00159 DataFrame::ma_any_t::size_type rows0 = df.payload->shape()[0];
00160 DataFrame::ma_any_t::size_type cols0 = df.payload->shape()[1];
00161
00162 for (DataFrame::iterator0 i = df.payload->begin();
00163 i != df.payload->end(); ++i) {
00164 DataFrame::iterator1 ii = (*i).begin();
00165 std::cerr << (*ii).type().name() << std::endl;
00166 }
00167
00168 }
00169
00171
00172 BOOST_AUTO_TEST_CASE(csv6)
00173 {
00174 using namespace eepgwde::detail;
00175
00176 BOOST_TEST_MESSAGE("QuantLib::price::frame::csv6");
00177
00178 std::cerr << frame << std::endl;
00179
00180 }
00181
00182 BOOST_AUTO_TEST_SUITE_END()
00183
00184 BOOST_AUTO_TEST_SUITE(col)
00185
00187
00188 BOOST_AUTO_TEST_CASE(d0)
00189 {
00190 using namespace eepgwde::detail;
00191
00192 BOOST_TEST_MESSAGE("QuantLib::price::frame::d0");
00193
00194 DataFrame df(frame);
00195
00196 DataFrame::r_itr a = df.header.right.find("PX_ASK");
00197 BOOST_CHECK( a != df.header.right.end() );
00198 BOOST_TEST_MESSAGE( "column: " << a->first << " " << a->second );
00199
00200 DataFrame::ma_any_t::size_type rows0 = df.payload->shape()[0];
00201 DataFrame::ma_any_t::size_type cols0 = a->second;
00202
00203 for (DataFrame::ma_any_t::size_type i = 0; i < rows0; ++i) {
00204 for (DataFrame::ma_any_t::size_type j = cols0; j <= cols0; ++j) {
00205 renderer<double>((*df.payload)[i][j], (null0<boost::any>())(), 1, 0);
00206 std::cerr << ( (*df.payload)[i][j]).type().name() << " "
00207 << any_cast<double>((*df.payload)[i][j]) << " ";
00208 }
00209 std::cerr << endl;
00210 }
00211
00212 }
00213
00216
00217 std::string as1(boost::any & o) {
00218 std::string r("");
00219 try {
00220 r = boost::any_cast<std::string>(o);
00221 } catch (...) {
00222 }
00223 return r;
00224 }
00225
00226 BOOST_AUTO_TEST_CASE(d1)
00227 {
00228 using namespace eepgwde::detail;
00229
00230 BOOST_TEST_MESSAGE("QuantLib::price::frame::d1");
00231
00232 DataFrame df(frame);
00233
00234 typedef DataFrame::ma_any_t::iterator irow;
00235 typedef DataFrame::ma_any_t::subarray<1>::type::iterator icol;
00236
00237 BOOST_TEST_MESSAGE("QuantLib::price::frame::d1::frame");
00238
00239 int it3 = 0;
00240 int it2 = 0;
00241 for (irow i = frame.begin(); i != frame.end(); ++i) {
00242 std::cerr << "it3: " << it3++ << std::endl;
00243 for(icol ii = (*i).begin(); ii != (*i).end(); ++ii) {
00244 std::cerr << "it2: " << it2++ << ": "
00245 << as1(*ii) << " "
00246 << (*ii).type().name() << std::endl;
00247 }
00248 }
00249
00250 BOOST_TEST_MESSAGE("QuantLib::price::frame::d1::df.frame");
00251
00252 it3 = 0;
00253 it2 = 0;
00254 for (irow i = df.frame.begin(); i != df.frame.end(); ++i) {
00255 std::cerr << "it3: " << it3++ << std::endl;
00256 for(icol ii = (*i).begin(); ii != (*i).end(); ++ii) {
00257 std::cerr << "it2: " << it2++ << ": "
00258 << as1(*ii) << " "
00259 << (*ii).type().name() << std::endl;
00260 }
00261 }
00262
00263 }
00264
00266
00267 BOOST_AUTO_TEST_CASE(d2)
00268 {
00269 using namespace eepgwde::detail;
00270
00271 BOOST_TEST_MESSAGE("QuantLib::price::frame::d2");
00272
00273 DataFrame df(frame);
00274
00275 DataFrame::r_itr a = df.header.right.find("PX_ASK");
00276 BOOST_CHECK( a != df.header.right.end() );
00277 BOOST_TEST_MESSAGE( "column: " << a->first << " " << a->second );
00278
00279 typedef boost::multi_array_types::index_range range;
00280 DataFrame::ma_any_t::index_gen indices;
00281 DataFrame::ma_any_t::array_view<1>::type myview =
00282 (*df.payload)[ boost::indices[range()][a->second] ];
00283
00284 typedef DataFrame::ma_any_t::subarray<1>::type::iterator icol;
00285
00286 for (icol i = myview.begin(); i != myview.end(); ++i) {
00287 renderer<double>(*i, (null0<boost::any>())(), 1, 0);
00288 std::cerr << (*i).type().name() << " "
00289 << any_cast<double>(*i) << " ";
00290 }
00291
00292 }
00293
00295
00296 BOOST_AUTO_TEST_CASE(d3)
00297 {
00298 using namespace eepgwde::detail;
00299
00300 BOOST_TEST_MESSAGE("QuantLib::price::frame::d3");
00301
00302 DataFrame df(frame);
00303
00304 DataFrame::ma_any_t::array_view<1>::type myview = df.column("PX_ASK");
00305
00306 for (DataFrame::iterator1 i = myview.begin(); i != myview.end(); ++i) {
00307 renderer<double>(*i, (null0<boost::any>())(), 1, 0);
00308 std::cerr << (*i).type().name() << " "
00309 << any_cast<double>(*i) << " ";
00310 }
00311
00312 }
00313
00315
00316 BOOST_AUTO_TEST_CASE(d4)
00317 {
00318 using namespace eepgwde::detail;
00319
00320 BOOST_TEST_MESSAGE("QuantLib::price::frame::d4");
00321
00322 DataFrame df(frame);
00323
00324 DataFrame::ma_any_t::array_view<1>::type myview = df.column("PX_ASK");
00325 df.render<double>(myview);
00326
00327 DataFrame::ma_any_t::array_view<1>::type myview0 = df.column("X2");
00328 df.render<int>(myview0);
00329
00330 std::cerr << df.frame << std::endl;
00331
00332 }
00333
00334 BOOST_AUTO_TEST_CASE(d5)
00335 {
00336 using namespace eepgwde::detail;
00337
00338 BOOST_TEST_MESSAGE("QuantLib::price::frame::d5");
00339
00340 DataFrame df(frame);
00341
00342 DataFrame::ma_any_t::array_view<1>::type myview = df.column("PX");
00343 df.render<std::string>(myview);
00344
00345 std::list<boost::any> a = DataFrame::columnar(myview);
00346
00347 BOOST_CHECK( a.size() == myview.size() );
00348
00349 BOOST_TEST_MESSAGE( "std::string: " << " "
00350 << eepgwde::detail::count<std::string>(&a) );
00351
00352 DataFrame::ma_any_t::array_view<1>::type myview0 = df.column("X2");
00353 df.render<int>(myview0);
00354
00355 a = DataFrame::columnar(myview0);
00356
00357 BOOST_CHECK( a.size() == myview0.size() );
00358
00359 BOOST_TEST_MESSAGE( "int: " << " "
00360 << eepgwde::detail::count<int>(&a) );
00361
00362 }
00363
00364 BOOST_AUTO_TEST_CASE(d6)
00365 {
00366 using namespace eepgwde::detail;
00367
00368 BOOST_TEST_MESSAGE("QuantLib::price::frame::d6");
00369
00370 DataFrame df(frame);
00371
00372 DataFrame::ma_any_t::array_view<1>::type myview = df.column("PX");
00373 df.render<std::string>(myview);
00374
00375 DataFrame::ma_any_t::array_view<1>::type myview0 = df.column("X2");
00376 df.render<int>(myview0);
00377
00378 DataFrame::iterator0 h0 = df.frame.begin();
00379 std::list<boost::any> a = DataFrame::rowar(&df, h0);
00380
00381 BOOST_TEST_MESSAGE( "std::string: " << " "
00382 << eepgwde::detail::count<std::string>(&a) << " "
00383 << eepgwde::detail::count<int>(&a) );
00384
00385 a = DataFrame::rowar(&df, ++h0);
00386
00387 BOOST_TEST_MESSAGE( "int: " << " "
00388 << eepgwde::detail::count<std::string>(&a) << " "
00389 << eepgwde::detail::count<int>(&a) );
00390
00391 }
00392
00393 BOOST_AUTO_TEST_CASE(d7)
00394 {
00395 using namespace eepgwde::detail;
00396
00397 BOOST_TEST_MESSAGE("QuantLib::price::frame::d7");
00398
00399 DataFrame df(frame);
00400
00401 DataFrame::ma_any_t::array_view<1>::type myview = df.column("PX");
00402 df.render<std::string>(myview);
00403
00404 DataFrame::ma_any_t::array_view<1>::type myview0 = df.column("X2");
00405 df.render<int>(myview0);
00406
00407 DataFrame::iterator0 h0 = df.frame.begin();
00408 record_t m = DataFrame::rowar(&df, h0);
00409 std::cerr << as(*m[std::string("PX")]) << std::endl;
00410 m = DataFrame::rowar(&df, ++h0);
00411 std::cerr << as(*m[std::string("PX")]) << std::endl;
00412
00413 }
00414
00415 BOOST_AUTO_TEST_SUITE_END()
00416
00417 BOOST_AUTO_TEST_SUITE (schema0)
00418
00420
00422
00423 BOOST_AUTO_TEST_CASE(csd0)
00424 {
00425 using namespace eepgwde::detail;
00426
00427 BOOST_TEST_MESSAGE("QuantLib::price::schema0::csd0");
00428
00429 std::string service0(fname0);
00430 service0 = service0.erase(service0.find("."));
00431
00432 BOOST_TEST_MESSAGE(service0);
00433
00434 DataFrame df(frame, service0);
00435
00436 #ifndef NDEBUG
00437 call(df);
00438 #endif
00439
00440 std::cerr << df.frame << std::endl;
00441 }
00442
00444
00445 BOOST_AUTO_TEST_CASE(csd1)
00446 {
00447 using namespace eepgwde::detail;
00448
00449 BOOST_TEST_MESSAGE("QuantLib::price::schema0::csd1");
00450
00451 std::string service0(fname0);
00452 service0 = service0.erase(service0.find("."));
00453
00454 BOOST_TEST_MESSAGE(service0);
00455
00456 DataFrame df(frame, service0);
00457
00458 df.render();
00459
00460 std::cerr << df.frame << std::endl;
00461 }
00462
00464
00465 BOOST_AUTO_TEST_CASE(csd2)
00466 {
00467 using namespace eepgwde::detail;
00468
00469 BOOST_TEST_MESSAGE("QuantLib::price::schema0::csd2");
00470
00471 std::string service0(fname0);
00472 service0 = service0.erase(service0.find("."));
00473
00474 BOOST_TEST_MESSAGE(service0);
00475
00476 DataFrame df(frame, service0);
00477
00478 df.render();
00479
00480 std::cerr << df.frame << std::endl;
00481
00482 int rows0 = 0, rows1 = 0, cols0 = 0;
00483
00484 std::list<boost::any> data0;
00485 std::list<boost::any> data1;
00486
00487 int rows00 = 0;
00488 for (DataFrame::iterator0 i = frame.begin(); i != frame.end(); ++i) {
00489 std::cerr << "rows00: " << rows00++ << std::endl;
00490 if (i == frame.begin()) {
00491 int cols1 = 0;
00492 for(DataFrame::iterator1 ii = (*i).begin(); ii != (*i).end(); ++ii) {
00493 cols1++;
00494 data0.push_back(*ii);
00495 data1.push_back(*ii);
00496 }
00497 cols0 = cols1;
00498 continue;
00499 }
00500
00501 if ( (rows00 % 2) == 0) {
00502 rows0++;
00503 std::cerr << "rows0: " << rows0 << " rows1: " << rows00 << std::endl;
00504 for(DataFrame::iterator1 ii = (*i).begin(); ii != (*i).end(); ++ii) {
00505 data0.push_back(*ii);
00506 }
00507 } else {
00508 rows1++;
00509 for(DataFrame::iterator1 ii = (*i).begin(); ii != (*i).end(); ++ii) {
00510 data1.push_back(*ii);
00511 }
00512 }
00513
00514 }
00515
00516 std::cerr << "cols0: " << cols0 << " rows: " << rows0 << std::endl;
00517 std::cerr << "cols0: " << cols0 << " rows: " << rows1 << std::endl;
00518
00519 boost::array<DataFrame::ma_any_t::index, 2> shape0 ={{ rows0 + 1, cols0 }};
00520 boost::array<DataFrame::ma_any_t::index, 2> shape1 ={{ rows1 + 1, cols0 }};
00521
00522 DataFrame::ma_any_t frame0(shape0);
00523 frame0.assign(data0.begin(), data0.end());
00524
00525 DataFrame df0(frame0);
00526
00527 DataFrame::ma_any_t frame1(shape1);
00528 frame1.assign(data1.begin(), data1.end());
00529
00530 DataFrame df1(frame1);
00531
00532 BOOST_TEST_MESSAGE("QuantLib::price::schema0::df0");
00533 std::cerr << df0.frame << std::endl;
00534 BOOST_TEST_MESSAGE("QuantLib::price::schema0::df1");
00535 std::cerr << df1.frame << std::endl;
00536
00537 }
00538
00539 BOOST_AUTO_TEST_SUITE_END()
00540
00541 BOOST_AUTO_TEST_SUITE(split0)
00542
00544
00545 BOOST_AUTO_TEST_CASE(a4)
00546 {
00547 using namespace eepgwde::detail;
00548
00549 BOOST_TEST_MESSAGE("QuantLib::price::split0::a4");
00550
00551 std::string service0(fname0);
00552 service0 = service0.erase(service0.find("."));
00553
00554 DataFrame df(frame, service0);
00555
00556 df.render();
00557
00558 int rows00 = 0;
00559
00560 for (DataFrame::iterator0 i = frame.begin(); i != frame.end(); ++i) {
00561 std::cerr << "rows00: " << rows00++ << std::endl;
00562 DataFrame::iterator1 ii;
00563 DataFrame::l_itr lhi;
00564 std::map<std::string, const boost::any *> record;
00565
00566 for(ii = (*i).begin(), lhi = df.header.left.begin();
00567 ii != (*i).end() && lhi != df.header.left.end(); ++ii, ++lhi) {
00568 record[lhi->second] = &(*ii);
00569 std::cerr << lhi->second << " " << as(*ii) << std::endl;
00570 }
00571 std::cerr << "PX: " << as(*record[std::string("PX")]) << endl;
00572 }
00573
00574 }
00575
00577
00578 BOOST_AUTO_TEST_CASE(a5)
00579 {
00580 using namespace eepgwde::detail;
00581
00582 BOOST_TEST_MESSAGE("QuantLib::price::split0::a5");
00583
00584 std::string service0(fname0);
00585 service0 = service0.erase(service0.find("."));
00586
00587 DataFrame df(frame, service0);
00588
00589 df.render();
00590
00591 int rows00 = 0;
00592
00593 for (DataFrame::iterator0 i = frame.begin(); i != frame.end(); ++i) {
00594 std::cerr << "rows00: " << rows00++ << std::endl;
00595 record_t record = DataFrame::rowar(&df, i);
00596 std::cerr << "PX: " << as(*record["PX"]) << std::endl;
00597 }
00598
00599 }
00600
00601 BOOST_AUTO_TEST_SUITE_END()
00602
00603
00604 BOOST_AUTO_TEST_SUITE(colt)
00605
00607
00608 BOOST_AUTO_TEST_CASE(d0)
00609 {
00610 using namespace eepgwde::detail;
00611
00612 BOOST_TEST_MESSAGE("DataFrame::colt::d0");
00613
00614 std::string service0(fname0);
00615 service0 = service0.erase(service0.find("."));
00616
00617 DataFrame df(frame, service0);
00618
00619 Typing::types0_t tt0 = df.types0();
00620
00621 std::cout << "boost::any().type().name()"
00622 << ":" << '"' << "value" << '"' << std::endl;
00623 for(Typing::types0_t::iterator i=tt0.begin();
00624 i!=tt0.end(); ++i) {
00625 std::cout << i->first << ":" << '"' << i->second->null() << '"' << std::endl;
00626 }
00627
00628 }
00629
00631
00632 BOOST_AUTO_TEST_CASE(d1)
00633 {
00634 using namespace eepgwde::detail;
00635
00636 BOOST_TEST_MESSAGE("DataFrame::colt::d0");
00637
00638 std::string service0(fname0);
00639 service0 = service0.erase(service0.find("."));
00640
00641 DataFrame df(frame, service0);
00642
00643 for(DataFrame::l_itr i=df.header.left.begin();
00644 i != df.header.left.end(); ++i) {
00645 std::cerr << i->second << " "
00646 << df.column_t0(i->second).first
00647 << std::endl;
00648 }
00649
00650 }
00651
00652 BOOST_AUTO_TEST_SUITE_END()
00653
00654
00655