00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "eleve/config.hpp"
00028
00029 #include "utilities.hpp"
00030 #include <ql/instruments/payoffs.hpp>
00031 #include <ql/indexes/indexmanager.hpp>
00032 #include <ql/termstructures/yield/flatforward.hpp>
00033 #include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
00034 #include <ql/time/calendars/nullcalendar.hpp>
00035
00036 #define CHECK_DOWNCAST(Derived,Description) { \
00037 boost::shared_ptr<Derived> hd = boost::dynamic_pointer_cast<Derived>(h); \
00038 if (hd) \
00039 return Description; \
00040 }
00041
00042 namespace QuantLib {
00043
00044 std::string payoffTypeToString(const boost::shared_ptr<Payoff>& h) {
00045
00046 CHECK_DOWNCAST(PlainVanillaPayoff, "plain-vanilla");
00047 CHECK_DOWNCAST(CashOrNothingPayoff, "cash-or-nothing");
00048 CHECK_DOWNCAST(AssetOrNothingPayoff, "asset-or-nothing");
00049 CHECK_DOWNCAST(SuperSharePayoff, "super-share");
00050 CHECK_DOWNCAST(GapPayoff, "gap");
00051
00052 QL_FAIL("unknown payoff type");
00053 }
00054
00055
00056 std::string exerciseTypeToString(const boost::shared_ptr<Exercise>& h) {
00057
00058 CHECK_DOWNCAST(EuropeanExercise, "European");
00059 CHECK_DOWNCAST(AmericanExercise, "American");
00060 CHECK_DOWNCAST(BermudanExercise, "Bermudan");
00061
00062 QL_FAIL("unknown exercise type");
00063 }
00064
00065
00066 boost::shared_ptr<YieldTermStructure>
00067 flatRate(const Date& today,
00068 const boost::shared_ptr<Quote>& forward,
00069 const DayCounter& dc) {
00070 return boost::shared_ptr<YieldTermStructure>(
00071 new FlatForward(today, Handle<Quote>(forward), dc));
00072 }
00073
00074 boost::shared_ptr<YieldTermStructure>
00075 flatRate(const Date& today, Rate forward, const DayCounter& dc) {
00076 return flatRate(
00077 today, boost::shared_ptr<Quote>(new SimpleQuote(forward)), dc);
00078 }
00079
00080 boost::shared_ptr<YieldTermStructure>
00081 flatRate(const boost::shared_ptr<Quote>& forward,
00082 const DayCounter& dc) {
00083 return boost::shared_ptr<YieldTermStructure>(
00084 new FlatForward(0, NullCalendar(), Handle<Quote>(forward), dc));
00085 }
00086
00087 boost::shared_ptr<YieldTermStructure>
00088 flatRate(Rate forward, const DayCounter& dc) {
00089 return flatRate(boost::shared_ptr<Quote>(new SimpleQuote(forward)),
00090 dc);
00091 }
00092
00093
00094 boost::shared_ptr<BlackVolTermStructure>
00095 flatVol(const Date& today,
00096 const boost::shared_ptr<Quote>& vol,
00097 const DayCounter& dc) {
00098 return boost::shared_ptr<BlackVolTermStructure>(new
00099 BlackConstantVol(today, NullCalendar(), Handle<Quote>(vol), dc));
00100 }
00101
00102 boost::shared_ptr<BlackVolTermStructure>
00103 flatVol(const Date& today, Volatility vol,
00104 const DayCounter& dc) {
00105 return flatVol(today,
00106 boost::shared_ptr<Quote>(new SimpleQuote(vol)),
00107 dc);
00108 }
00109
00110 boost::shared_ptr<BlackVolTermStructure>
00111 flatVol(const boost::shared_ptr<Quote>& vol,
00112 const DayCounter& dc) {
00113 return boost::shared_ptr<BlackVolTermStructure>(new
00114 BlackConstantVol(0, NullCalendar(), Handle<Quote>(vol), dc));
00115 }
00116
00117 boost::shared_ptr<BlackVolTermStructure>
00118 flatVol(Volatility vol,
00119 const DayCounter& dc) {
00120 return flatVol(boost::shared_ptr<Quote>(new SimpleQuote(vol)), dc);
00121 }
00122
00123
00124 Real relativeError(Real x1, Real x2, Real reference) {
00125 if (reference != 0.0)
00126 return std::fabs(x1-x2)/reference;
00127 else
00128
00129 return std::fabs(x1-x2);
00130 }
00131
00132
00133 IndexHistoryCleaner::IndexHistoryCleaner() {}
00134
00135 IndexHistoryCleaner::~IndexHistoryCleaner() {
00136 IndexManager::instance().clearHistories();
00137 }
00138
00139 }