00001
00015 #include <iostream>
00016 #include <stack>
00017 #include <algorithm>
00018 #include <vector>
00019
00020 #include <algorithm>
00021 #include <typeinfo>
00022
00023 #include <boost/bind.hpp>
00024 #include <boost/foreach.hpp>
00025 #include <boost/multi_array.hpp>
00026
00027 #include <boost/regex.hpp>
00028
00029 #include <ql/utilities/tracing.hpp>
00030
00031 #include "eleve/src/scal0.hpp"
00032 #include "eleve/src/typing0.hpp"
00033
00034 #include <boost/algorithm/string/trim.hpp>
00035 #include <boost/tokenizer.hpp>
00036
00037 #include "eleve/src/loader0.hpp"
00038
00039 #define BOOST_TEST_NO_MAIN
00040 #include <boost/test/unit_test.hpp>
00041
00042 #include "eleve/src/typing3.hpp"
00043 #include "eleve/src/typing1.hpp"
00044
00045 #include "eleve/src0/csv1.hpp"
00046 #include "eleve/src0/csv4.hpp"
00047 #include "pivot1.hpp"
00048 #include "eleve/src0/csv2.hpp"
00049
00050 #include "acsvt0.hpp"
00051
00052 namespace {
00053
00054 using namespace eepgwde::detail;
00055
00056
00057 struct csv2 {
00058
00059 static const std::string strike;
00060 static const std::string maturity;
00061
00062 std::string service0;
00063
00064
00065 DataFrame::ma_any_t frame_;
00066
00067 DataFrame df;
00068 DataFrame::ma_any_t sorted0;
00069
00070 static std::string init1(std::string fn0) {
00071 return fn0.erase(fn0.find("."));
00072 };
00073
00074
00075
00076
00077 csv2() : service0(csv2::init1(fname0)),
00078 frame_(frame),
00079 df(frame_, service0) {
00080
00081 DataFrame::payloader payload0(df);
00082 std::vector<Attr0> attr0 = payload0;
00083
00084
00085 std::string key("X0");
00086 for_each(attr0.begin(), attr0.end(),
00087 boost::bind(&Attr0::attributes,_1,key) );
00088
00089
00090 std::vector<DataFrame::Record *> s =
00091 pointerize<std::vector<DataFrame::Record *>, std::vector<Attr0> >(attr0);
00092
00093
00094 std::list<record_t *> attrs;
00095 back_insert_iterator< std::list<record_t *> > ii(attrs);
00096 transform(s.begin(), s.end(),
00097 ii,
00098 boost::bind(&DataFrame::Record::attrs,_1));
00099
00100
00101 DataFrame::ma_any_t xframe1;
00102 df.add(&xframe1, s);
00103 DataFrame df0(xframe1, service0);
00104 df = df0;
00105
00106
00107
00108
00109 try {
00110 df.render();
00111 } catch (std::domain_error & e) {
00112 BOOST_TEST_MESSAGE("render: error");
00113 }
00114
00115 Typing t0;
00116 t0.mappings(bbg_mappings);
00117 Typing::mappings_t mappings0 = t0.mappings();
00118
00119
00120 DataFrame::headar h0(&df, mappings0);
00121 DataFrame::attr_pos_t h1 = h0;
00122
00123 df.header = h1;
00124
00125 DataFrame::payloader payload1(df);
00126 std::vector<DataFrame::Record> sort0 = payload1;
00127
00128 boost::regex e("[A-Z]+ISC[^ ]+ Cu.+");
00129 QPXisc comparor(e);
00130
00131
00132 std::vector<DataFrame::Record>::iterator mark =
00133 partition(sort0.begin(), sort0.end(),
00134 boost::bind(&DataFrame::Comparor::compare,
00135 boost::ref(comparor),_1) );
00136
00137 std::vector<DataFrame::Record>::iterator mark0 = sort0.begin();
00138 if (mark != sort0.end() && mark != sort0.begin() ) {
00139 mark0 = mark;
00140 }
00141
00142 BOOST_ASSERT(distance(sort0.begin(), mark0) > 1);
00143
00144
00145
00146
00147 sort(sort0.begin(), mark0,
00148 boost::bind(std::less<int>(),
00149 boost::bind(&DataFrame::Record::as<int>,_1, maturity),
00150 boost::bind(&DataFrame::Record::as<int>,_2, maturity) ));
00151
00152
00153 stable_sort(sort0.begin(), mark0,
00154 boost::bind(std::less<double>(),
00155 boost::bind(&DataFrame::Record::as<double>,_1, strike),
00156 boost::bind(&DataFrame::Record::as<double>,_2, strike) ));
00157
00158 int headings = 1;
00159 DataFrame::ma_any_t sorted00 = payload0.as(sort0.begin(), mark0, headings);
00160
00161
00162
00163 boost::array<DataFrame::ma_any_t::index, 2> shape =
00164 {{ sorted00.shape()[0], sorted00.shape()[1] }};
00165 sorted0.resize(shape);
00166 sorted0 = sorted00;
00167 }
00168
00169 ~csv2() {}
00170
00171 };
00172
00173 const std::string csv2::strike("strike");
00174 const std::string csv2::maturity("maturity");
00175
00176 }
00177
00178 BOOST_FIXTURE_TEST_SUITE (multi_index2,csv2)
00179
00180 BOOST_AUTO_TEST_CASE(e0)
00181 {
00182
00183 std::cerr << df.frame << std::endl;
00184 std::cerr << df.header.left << std::endl;
00185 std::cerr << sorted0 << std::endl;
00186 }
00187
00188
00189
00190 BOOST_AUTO_TEST_CASE(e1)
00191 {
00192 using namespace eepgwde::detail;
00193
00194 BOOST_TEST_MESSAGE("QuantLib::price::sort0::e1");
00195
00196 BOOST_CHECK(sorted0.size() > 1);
00197
00198 std::cerr << sorted0.shape()[0] << " " << sorted0.shape()[1] << std::endl;
00199 std::cerr << sorted0 << std::endl;
00200
00201 DataFrame df0(sorted0);
00202
00203 DataFrame::payloader payload0(df0);
00204 std::vector<DataFrame::Record> sort0 = payload0;
00205
00206 mties0_ = DataFrame::columnar1(df0.column(maturity));
00207 strikes0_ = DataFrame::columnar1(df0.column(strike));
00208
00209 copy(mties0_.begin(), mties0_.end(),
00210 ostream_iterator<double>(std::cerr, " "));
00211 std::cerr << std::endl;
00212
00213 copy(strikes0_.begin(), strikes0_.end(),
00214 ostream_iterator<double>(std::cerr, " "));
00215 std::cerr << std::endl;
00216 }
00217
00218
00219
00220
00221
00222 BOOST_AUTO_TEST_CASE(e2)
00223 {
00224 using namespace eepgwde::detail;
00225
00226 BOOST_TEST_MESSAGE("QuantLib::price::sort0::e2");
00227
00228 BOOST_CHECK(sorted0.size() > 1);
00229
00230 std::cerr << sorted0.shape()[0] << " " << sorted0.shape()[1] << std::endl;
00231 std::cerr << sorted0 << std::endl;
00232
00233
00234 DataFrame df2(sorted0);
00235
00236 std::cerr << df2.header.left << std::endl;
00237 std::cerr << df2.frame << std::endl;
00238
00239 DataFrame::payloader payload2(df2);
00240 std::vector<StrikeMaturity> sort2 = payload2;
00241
00242 BOOST_CHECK(sort2.size() > 0);
00243
00244 Prices px(sort2.begin(), sort2.end());
00245
00246 BOOST_CHECK(px.size() > 0);
00247 BOOST_CHECK(mties0_.size() > 0);
00248 BOOST_CHECK(strikes0_.size() > 0);
00249
00250 DataFrame::ma_any_t mark0;
00251 boost::array<DataFrame::ma_any_t::index, 2>
00252 shape ={{ strikes0_.size(), mties0_.size() }};
00253 mark0.resize(shape);
00254
00255 std::list<boost::any> data;
00256 int failures = 0;
00257
00258 for(std::vector<double>::iterator it0=strikes0_.begin();
00259 it0 != strikes0_.end(); ++it0) {
00260 for(std::vector<double>::iterator it1=mties0_.begin();
00261 it1 != mties0_.end(); ++it1) {
00262
00263 std::pair<Prices::iterator, Prices::iterator> p =
00264 px.equal_range(boost::make_tuple(*it0, *it1));
00265
00266 Prices::iterator p0 = p.first;
00267
00268 if (p0->strike_ == *it0 && p0->maturity_ == *it1) {
00269 double number = p0->price_;
00270
00271 std::cerr << "(" << *it0 << " " << *it1 << " " << number
00272 << ")" << std::endl;
00273 data.push_back(boost::any(number));
00274 continue;
00275 }
00276 std::cerr << "(" << *it0 << " " << *it1 << " " << "null"
00277 << ")" << std::endl;
00278 failures++;
00279 data.push_back(boost::any());
00280 }
00281 }
00282
00283 mark0.assign(data.begin(), data.end());
00284 std::cerr << mark0 << std::endl;
00285 }
00286
00287
00288
00289
00290
00291 BOOST_AUTO_TEST_CASE(e3)
00292 {
00293 using namespace eepgwde::detail;
00294
00295 BOOST_TEST_MESSAGE("QuantLib::price::sort0::e3");
00296
00297 BOOST_CHECK(sorted0.size() > 0);
00298
00299
00300 DataFrame df2(sorted0);
00301 DataFrame::payloader payload2(df2);
00302 std::vector<StrikeMaturity> sort2 = payload2;
00303
00304 BOOST_CHECK(sort2.size() > 0);
00305
00306 Prices px(sort2.begin(), sort2.end());
00307
00308 BOOST_CHECK(px.size() > 0);
00309 BOOST_CHECK(mties0_.size() > 0);
00310 BOOST_CHECK(strikes0_.size() > 0);
00311
00312 Pivotter r0(px, strikes0_, mties0_);
00313
00314
00315 DataFrame::ma_any_t marked0 = r0;
00316 std::cerr << marked0 << std::endl;
00317 BOOST_CHECK(marked0.size() > 0);
00318
00319 try {
00320 QuantLib::Matrix ceurisc = Matrix0(marked0);
00321 std::cerr << ceurisc << std::endl;
00322 } catch (std::exception & e) {
00323 std::cerr << "exception: " << e.what() << std::endl;
00324 }
00325
00326 }
00327
00328 BOOST_AUTO_TEST_SUITE_END()
00329
00330
00331