00001
00002
00003
00004
00005
00006 #ifndef CSV3_
00007 #define CSV3_
00008
00009 #include <string>
00010 #include <map>
00011 #include <list>
00012 #include <string>
00013 #include <stdexcept>
00014
00015 #include <boost/any.hpp>
00016 #include <boost/multi_array.hpp>
00017
00018 #include <boost/multi_index_container.hpp>
00019 #include <boost/multi_index/ordered_index.hpp>
00020 #include <boost/multi_index/member.hpp>
00021 #include <boost/multi_index/composite_key.hpp>
00022
00023 #include "eleve/src/typing0.hpp"
00024
00025 namespace eepgwde { namespace detail {
00026
00027 using namespace boost::multi_index;
00028
00033 struct StrikeMaturity : public DataFrame::Record {
00034 int maturity_;
00035 double strike_;
00036 double price_;
00037
00038 static const std::string strike0;
00039 static const std::string maturity0;
00040 static const std::string price0;
00041
00042 StrikeMaturity(DataFrame *df,
00043 DataFrame::iterator0 itr,
00044 eepgwde::detail::record_t r) :
00045 DataFrame::Record(df, itr, r),
00046 maturity_(maturity()), strike_(strike()), price_(price()) {
00047 }
00048
00049 template<typename T>
00050 T as_(const std::string & key) const throw(std::exception) {
00051 boost::any o = *(r_)[key];
00052 T r0;
00053 if (!eepgwde::detail::as<T>(&r0, o))
00054 throw (std::domain_error("cast fail: " + key));
00055 return r0;
00056 }
00057
00058
00059 int maturity() const throw(std::exception) {
00060 return as_<int>(maturity0);
00061 }
00062
00063
00064 double strike() const throw(std::exception) {
00065 return as_<double>(strike0);
00066 }
00067
00068
00069 double price() const throw(std::exception) {
00070 return as_<double>(price0);
00071 }
00072 };
00073
00076 typedef multi_index_container<
00077 StrikeMaturity,
00078 indexed_by<
00079
00080 ordered_non_unique<
00081 composite_key<
00082 StrikeMaturity,
00083 member<StrikeMaturity,double,&StrikeMaturity::strike_>,
00084 member<StrikeMaturity,int,&StrikeMaturity::maturity_>
00085 >
00086 >
00087 >
00088 > Prices;
00089
00091 struct Pivotter {
00092 const Prices & px;
00093 const std::vector<double> & rs;
00094 const std::vector<double> & cs;
00095
00096
00097
00098
00099 mutable int failures;
00100
00101 Pivotter(const Prices & px,
00102 const std::vector<double> &rows,
00103 const std::vector<double> &cols) :
00104 px(px), rs(rows), cs(cols), failures(0) {}
00105
00106
00107
00108
00109 operator DataFrame::ma_any_t () const;
00110
00111 };
00112
00113 }}
00114
00115 #endif