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