00001
00012 #ifndef ACSVT0_
00013 #define ACSVT0_
00014
00015 #include <queue>
00016 #include <boost/algorithm/string/trim.hpp>
00017 #include <boost/tokenizer.hpp>
00018
00019 #include "eleve/config.hpp"
00020
00021 #include "eleve/src/utilities.hpp"
00022 #include "eleve/src/typing0.hpp"
00023 #include "eleve/src/scal0.hpp"
00024 #include "eleve/src/loader0.hpp"
00025
00026 #include "eleve/src/typing3.hpp"
00027 #include "eleve/src/typing1.hpp"
00028 #include "eleve/src0/csv1.hpp"
00029
00030 namespace eepgwde { namespace detail {
00031
00032
00033
00034
00035 extern DataFrame::ma_any_t frame;
00036
00037 extern std::string fname0;
00038 extern std::queue<std::string> fnames;
00039 extern std::map<std::string, boost::any> results;
00040
00041 extern std::vector<double> mties0_;
00042 extern std::vector<double> strikes0_;
00043
00044 extern eepgwde::detail::Typing::mapping_t bbg_mappings[];
00045
00046 class CounterA {
00047 protected:
00048 double total_;
00049 int calls_;
00050
00051 public:
00052 CounterA() : total_(0.0), calls_(0) {}
00053 virtual ~CounterA() {}
00054
00055 virtual bool operator()(record_t & r) {
00056 return ++calls_ % 2 == 0 ;
00057 }
00058
00059 virtual double total() const {
00060 return total_;
00061 }
00062
00063 virtual int calls() const {
00064 return calls_;
00065 }
00066 };
00067
00068
00069
00070 struct QPXisc : public CounterA, public DataFrame::Comparor {
00071
00072 QPXisc(const boost::regex & e) : DataFrame::Comparor(e) {}
00073
00074 virtual bool is_isc(const std::string& s) {
00075 return regex_match(s, e, boost::match_partial );
00076 }
00077
00078
00079 virtual bool operator()(record_t & r) {
00080 std::string s( any_cast<std::string>(*r["name"]) );
00081 return is_isc(s);
00082 }
00083
00084
00085 bool compare(DataFrame::Record & r) {
00086 std::string s( any_cast<std::string>(*r.r_["name"]) );
00087 return is_isc(s);
00088 }
00089
00090 };
00091
00092 }}
00093
00094 namespace {
00095
00096 using namespace eepgwde::detail;
00097
00098
00099 struct Attr0 : public DataFrame::Record {
00100 Attr0(DataFrame *df,
00101 DataFrame::iterator0 itr,
00102 eepgwde::detail::record_t r) : DataFrame::Record(df, itr, r) {}
00103
00104 void attributes(const std::string & key0) {
00105 boost::any o = *r_[key0];
00106 std::string text = eepgwde::detail::as(o);
00107 std::string regx(".+ ([0-9.-]+)%[ ]+([0-9]+)Y$");
00108
00109 boost::regex e(regx);
00110 boost::smatch what;
00111 if (boost::regex_match(text, what, e)) {
00112 attrs0_.push_back(boost::any(static_cast<std::string>(what[1])));
00113 attrs0_.push_back(boost::any(static_cast<std::string>(what[2])));
00114 std::list<boost::any>::iterator a = attrs0_.begin();
00115 attrs_["strike"] = & * a;
00116 attrs_["maturity"] = & * (++a);
00117 }
00118 }
00119
00120 };
00121 }
00122
00123
00124 namespace {
00126
00127 using namespace std;
00128 using namespace eepgwde::detail;
00129
00130 struct csv0 {
00131 static void load0(const std::string & n, DataFrame::ma_any_t & f) {
00132 char * csv;
00133 string s1;
00134 int toks_header = -1;
00135
00136 loader l(n);
00137
00138 int line=0;
00139
00140 std::list<boost::any> data;
00141
00142 while ( csv = l.get() ) {
00143 string s(csv);
00144
00145 tokenizer<escaped_list_separator<char> > tok(s);
00146 tokenizer<escaped_list_separator<char> >::iterator beg;
00147 int pos=0;
00148
00149
00150 for(beg=tok.begin(), pos=1; beg!=tok.end(); ++beg, pos++)
00151 ;
00152 int toks_counted = pos;
00153 if (line == 0 && toks_header < 0) {
00154 toks_header = toks_counted;
00155 }
00156
00157 #ifndef NDEBUG
00158 std::cerr << "(line, line(), toks_counted) : ("
00159 << line << ", "
00160 << l.line() << ", "
00161 << toks_counted << ") " << endl;
00162 std::cerr << "line: " << line << ": " << s << endl;
00163 #endif
00164
00165 if (toks_counted != toks_header) {
00166 continue;
00167 }
00168
00169 for(beg=tok.begin(), pos=1; beg!=tok.end(); ++beg, pos++) {
00170 data.push_back( boost::any( *beg) );
00171 }
00172 line++;
00173 }
00174
00175 BOOST_TEST_MESSAGE( "data: " << data.size() << " "
00176 << toks_header << " "
00177 << line << " " << l.line());
00178
00179 int cols0 = toks_header - 1;
00180 int rows0 = line;
00181
00182
00183 boost::array<DataFrame::ma_any_t::index, 2> shape ={{ rows0, cols0 }};
00184 f.resize(shape);
00185 f.assign(data.begin(), data.end());
00186 }
00187
00188 csv0() {
00189 BOOST_TEST_MESSAGE("QuantLib::frame0::csv0");
00190
00191 int argc = boost::unit_test::framework::master_test_suite().argc;
00192 char **argv = boost::unit_test::framework::master_test_suite().argv;
00193
00194 #ifndef NDEBUG
00195 cerr << argc << endl;
00196 fname0 = std::string(argv[argc-1]);
00197 cerr << fname0 << endl;
00198 #endif
00199
00200 for (int i=1; i<argc; i++) {
00201 cerr << i << " " << argv[i] << endl;
00202 std::string a(argv[i]);
00203 fnames.push(a);
00204 }
00205
00206 #ifndef NDEBUG
00207 {
00208 std::queue<std::string> f(fnames);
00209 while (!f.empty()) {
00210 std::string a(f.front());
00211 std::cerr << a << std::endl;
00212 f.pop();
00213 }
00214 }
00215 #endif
00216
00217 csv0::load0(fname0, frame);
00218 }
00219
00220 ~csv0() {}
00221 };
00222
00223
00224 }
00225
00226 #endif
00227