Update of /cvsroot/quantlibaddin/QuantLibAddin/qlo
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv30876/qlo
Modified Files:
enumclassctors.cpp enumclassctors.hpp termstructures.cpp
typefactory.hpp typeregistry.hpp
Log Message:
extend Enumeration Registry to support creation of curves based on pair of strings
Index: typeregistry.hpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/qlo/typeregistry.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** typeregistry.hpp 29 Jun 2006 10:47:33 -0000 1.2
--- typeregistry.hpp 4 Jul 2006 17:07:56 -0000 1.3
***************
*** 2,5 ****
--- 2,6 ----
/*
Copyright (C) 2005 Plamen Neykov
+ Copyright (C) 2006 Eric Ehlers
This file is part of QuantLib, a free-software/open-source library
***************
*** 27,36 ****
namespace QuantLibAddin {
! typedef std::map<std::string, void*> TypeMap;
! typedef boost::shared_ptr<TypeMap> TypeMapPtr;
! typedef std::map<std::string, TypeMapPtr> AllTypeMap;
!
class Registry {
public:
std::vector<std::string> getAllRegisteredTypes() const;
std::vector<std::string> getTypeElements(const std::string&) const;
--- 28,38 ----
namespace QuantLibAddin {
! template <typename KeyClass>
class Registry {
public:
+ typedef std::map<KeyClass, void*> TypeMap;
+ typedef boost::shared_ptr<TypeMap> TypeMapPtr;
+ typedef std::map<std::string, TypeMapPtr> AllTypeMap;
+
std::vector<std::string> getAllRegisteredTypes() const;
std::vector<std::string> getTypeElements(const std::string&) const;
***************
*** 42,46 ****
};
! class EnumTypeRegistry : public Registry, public QuantLib::Singleton<EnumTypeRegistry> {
friend class QuantLib::Singleton<EnumTypeRegistry>;
private:
--- 44,48 ----
};
! class EnumTypeRegistry : public Registry<std::string>, public QuantLib::Singleton<EnumTypeRegistry> {
friend class QuantLib::Singleton<EnumTypeRegistry>;
private:
***************
*** 48,56 ****
};
! class EnumClassRegistry : public Registry, public QuantLib::Singleton<EnumClassRegistry> {
friend class QuantLib::Singleton<EnumClassRegistry>;
private:
EnumClassRegistry();
};
}
--- 50,66 ----
};
! class EnumClassRegistry : public Registry<std::string>, public QuantLib::Singleton<EnumClassRegistry> {
friend class QuantLib::Singleton<EnumClassRegistry>;
private:
EnumClassRegistry();
};
+
+ typedef std::pair<std::string, std::string> KeyPair;
+ class EnumCurveRegistry : public Registry<KeyPair>, public QuantLib::Singleton<EnumCurveRegistry> {
+ friend class QuantLib::Singleton<EnumCurveRegistry>;
+ private:
+ EnumCurveRegistry();
+ };
+
}
Index: termstructures.cpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/qlo/termstructures.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** termstructures.cpp 3 Jul 2006 10:27:21 -0000 1.13
--- termstructures.cpp 4 Jul 2006 17:07:56 -0000 1.14
***************
*** 63,73 ****
// true);
! libraryObject_ = boost::shared_ptr<QuantLib::Extrapolator>(
! new QuantLib::PiecewiseYieldCurve<QuantLib::Discount,
! QuantLib::LogLinear>(
! nDays, calendar,
! rateHelpersQL,
! dayCounter,
! 1.0e-6));
/*
--- 63,76 ----
// true);
! //libraryObject_ = boost::shared_ptr<QuantLib::Extrapolator>(
! // new QuantLib::PiecewiseYieldCurve<QuantLib::Discount,
! // QuantLib::LogLinear>(
! // nDays, calendar,
! // rateHelpersQL,
! // dayCounter,
! // 1.0e-6));
!
! libraryObject_ = Create<boost::shared_ptr<QuantLib::YieldTermStructure> >()
! ("Discount", "LogLinear", nDays, calendar, rateHelpersQL, dayCounter);
/*
Index: enumclassctors.cpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/qlo/enumclassctors.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** enumclassctors.cpp 4 Jul 2006 08:42:52 -0000 1.3
--- enumclassctors.cpp 4 Jul 2006 17:07:56 -0000 1.4
***************
*** 224,228 ****
}
! /* *** EURIBOR *** */
boost::shared_ptr<QuantLib::Euribor> EURIBOR_SW(
const std::string& handleYieldTermStructureID) {
--- 224,228 ----
}
! /* *** Euribor *** */
boost::shared_ptr<QuantLib::Euribor> EURIBOR_SW(
const std::string& handleYieldTermStructureID) {
***************
*** 346,349 ****
--- 346,364 ----
}
+ /* *** YieldTermStructure *** */
+ boost::shared_ptr<QuantLib::YieldTermStructure> DISCOUNT_LOGLINEAR_PiecewiseYieldCurve(
+ const long &nDays,
+ const QuantLib::Calendar &calendar,
+ const std::vector<boost::shared_ptr<QuantLib::RateHelper> > &rateHelpers,
+ const QuantLib::DayCounter &dayCounter) {
+ return boost::shared_ptr<QuantLib::YieldTermStructure>(
+ new QuantLib::PiecewiseYieldCurve<QuantLib::Discount,
+ QuantLib::LogLinear>(
+ nDays, calendar,
+ rateHelpers,
+ dayCounter,
+ 1.0e-6));
+ }
+
}
Index: enumclassctors.hpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/qlo/enumclassctors.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** enumclassctors.hpp 4 Jul 2006 08:42:52 -0000 1.3
--- enumclassctors.hpp 4 Jul 2006 17:07:56 -0000 1.4
***************
*** 104,108 ****
const QuantLib::Matrix& zData);
! /* *** EURIBOR *** */
boost::shared_ptr<QuantLib::Euribor> EURIBOR_SW(
const std::string& handleYieldTermStructureID);
--- 104,108 ----
const QuantLib::Matrix& zData);
! /* *** Euribor *** */
boost::shared_ptr<QuantLib::Euribor> EURIBOR_SW(
const std::string& handleYieldTermStructureID);
***************
*** 136,139 ****
--- 136,145 ----
const std::string& handleYieldTermStructureID);
+ /* *** YieldTermStructure *** */
+ boost::shared_ptr<QuantLib::YieldTermStructure> DISCOUNT_LOGLINEAR_PiecewiseYieldCurve(
+ const long &nDays,
+ const QuantLib::Calendar &calendar,
+ const std::vector<boost::shared_ptr<QuantLib::RateHelper> > &rateHelpers,
+ const QuantLib::DayCounter &dayCounter);
}
Index: typefactory.hpp
===================================================================
RCS file: /cvsroot/quantlibaddin/QuantLibAddin/qlo/typefactory.hpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** typefactory.hpp 4 Jul 2006 08:42:52 -0000 1.15
--- typefactory.hpp 4 Jul 2006 17:07:56 -0000 1.16
***************
*** 25,48 ****
#include <ql/Math/matrix.hpp>
#include <ql/Math/interpolation2D.hpp>
- #include <oh/exception.hpp>
#include <ql/Indexes/euribor.hpp>
namespace QuantLibAddin {
template<typename T, typename RegistryClass>
class RegistryManager {
protected:
! template<typename ConstructorSignature>
! ConstructorSignature getType(const std::string& id) {
! TypeMapPtr type_map = getTypeMap();
! std::string idUpper = QuantLib::uppercase(id);
! for (TypeMap::iterator i = type_map->begin(); i != type_map->end(); i++)
! if (QuantLib::uppercase(i->first) == idUpper)
return static_cast<ConstructorSignature>(i->second);
! QL_FAIL("Unknown id for Type: " + id);
}
bool checkType(const std::string& id) {
! TypeMapPtr type_map;
! AllTypeMap::const_iterator i =
RegistryClass::instance().getAllTypesMap().find(typeid(T).name());
if (i == RegistryClass::instance().getAllTypesMap().end()) {
--- 25,72 ----
#include <ql/Math/matrix.hpp>
#include <ql/Math/interpolation2D.hpp>
#include <ql/Indexes/euribor.hpp>
+ #include <ql/TermStructures/ratehelpers.hpp>
+ #include <oh/exception.hpp>
namespace QuantLibAddin {
+ inline std::string uppercase(const std::string &s) {
+ return QuantLib::uppercase(s);
+ }
+
+ inline KeyPair uppercase(const KeyPair &s) {
+ return KeyPair(QuantLib::uppercase(s.first), QuantLib::uppercase(s.second));
+ }
+
+ inline std::ostream& operator<<(std::ostream& left, const KeyPair &right) {
+ left << right.first << ":" << right.second;
+ return left;
+ }
+
template<typename T, typename RegistryClass>
class RegistryManager {
protected:
! //template<typename ConstructorSignature>
! //ConstructorSignature getType(const std::string& id) {
! // typename RegistryClass::TypeMapPtr type_map = getTypeMap();
! // std::string idUpper = QuantLib::uppercase(id);
! // for (typename RegistryClass::TypeMap::iterator i = type_map->begin(); i != type_map->end(); i++)
! // if (QuantLib::uppercase(i->first) == idUpper)
! // return static_cast<ConstructorSignature>(i->second);
! // QL_FAIL("Unknown id for Type: " << id);
! //}
! template<typename KeyClass, typename ConstructorSignature>
! ConstructorSignature getType(const KeyClass& id) {
! typename RegistryClass::TypeMapPtr type_map = getTypeMap();
! KeyClass idUpper = uppercase(id);
! for (typename RegistryClass::TypeMap::iterator i = type_map->begin(); i != type_map->end(); i++)
! if (uppercase(i->first) == idUpper)
return static_cast<ConstructorSignature>(i->second);
! QL_FAIL("Unknown id for Type: " << id);
}
+
bool checkType(const std::string& id) {
! typename RegistryClass::TypeMapPtr type_map;
! typename RegistryClass::AllTypeMap::const_iterator i =
RegistryClass::instance().getAllTypesMap().find(typeid(T).name());
if (i == RegistryClass::instance().getAllTypesMap().end()) {
***************
*** 52,56 ****
}
std::string idUpper = QuantLib::uppercase(id);
! for (TypeMap::iterator i = type_map->begin(); i != type_map->end(); i++)
if (QuantLib::uppercase(i->first) == idUpper)
return true;
--- 76,80 ----
}
std::string idUpper = QuantLib::uppercase(id);
! for (typename RegistryClass::TypeMap::iterator i = type_map->begin(); i != type_map->end(); i++)
if (QuantLib::uppercase(i->first) == idUpper)
return true;
***************
*** 58,65 ****
}
private:
! const TypeMapPtr &getTypeMap() {
! static TypeMapPtr type_map;
if(!type_map) {
! AllTypeMap::const_iterator i =
RegistryClass::instance().getAllTypesMap().find(typeid(T).name());
QL_REQUIRE(i != RegistryClass::instance().getAllTypesMap().end(),
--- 82,89 ----
}
private:
! const typename RegistryClass::TypeMapPtr &getTypeMap() {
! static typename RegistryClass::TypeMapPtr type_map;
if(!type_map) {
! typename RegistryClass::AllTypeMap::const_iterator i =
RegistryClass::instance().getAllTypesMap().find(typeid(T).name());
QL_REQUIRE(i != RegistryClass::instance().getAllTypesMap().end(),
***************
*** 77,81 ****
public:
T operator()(const std::string& id) {
! return *(getType<T*>(id));
}
using RegistryManager<T, EnumTypeRegistry>::checkType;
--- 101,105 ----
public:
T operator()(const std::string& id) {
! return *(getType<std::string, T*>(id));
}
using RegistryManager<T, EnumTypeRegistry>::checkType;
***************
*** 99,103 ****
const double& strike) {
StrikedTypePayoffConstructor1 strikedTypePayoffConstructor =
! getType<StrikedTypePayoffConstructor1>(payoffID);
return strikedTypePayoffConstructor(optionType, strike);
}
--- 123,127 ----
const double& strike) {
StrikedTypePayoffConstructor1 strikedTypePayoffConstructor =
! getType<std::string, StrikedTypePayoffConstructor1>(payoffID);
return strikedTypePayoffConstructor(optionType, strike);
}
***************
*** 108,112 ****
const double& strikeIncrement) {
StrikedTypePayoffConstructor2 strikedTypePayoffConstructor =
! getType<StrikedTypePayoffConstructor2>(payoffID);
return strikedTypePayoffConstructor(optionType, strike, strikeIncrement);
}
--- 132,136 ----
const double& strikeIncrement) {
StrikedTypePayoffConstructor2 strikedTypePayoffConstructor =
! getType<std::string, StrikedTypePayoffConstructor2>(payoffID);
return strikedTypePayoffConstructor(optionType, strike, strikeIncrement);
}
***************
*** 124,128 ****
boost::shared_ptr<QuantLib::PricingEngine> operator()(const std::string& engineID) {
PricingEngineConstructor1 pricingEngineConstructor =
! getType<PricingEngineConstructor1>(engineID);
return pricingEngineConstructor();
}
--- 148,152 ----
boost::shared_ptr<QuantLib::PricingEngine> operator()(const std::string& engineID) {
PricingEngineConstructor1 pricingEngineConstructor =
! getType<std::string, PricingEngineConstructor1>(engineID);
return pricingEngineConstructor();
}
***************
*** 131,135 ****
QL_REQUIRE(timeSteps>0, "timeSteps must be positive"); // FIXME move this validation into QL
PricingEngineConstructor2 pricingEngineConstructor =
! getType<PricingEngineConstructor2>(engineID);
return pricingEngineConstructor(timeSteps);
}
--- 155,159 ----
QL_REQUIRE(timeSteps>0, "timeSteps must be positive"); // FIXME move this validation into QL
PricingEngineConstructor2 pricingEngineConstructor =
! getType<std::string, PricingEngineConstructor2>(engineID);
return pricingEngineConstructor(timeSteps);
}
***************
*** 149,153 ****
dbl_itr& xBegin, dbl_itr& xEnd, dbl_itr& yBegin) {
InterpolationConstructor interpolationConstructor =
! getType<InterpolationConstructor>(interpolationID);
return interpolationConstructor(xBegin, xEnd, yBegin);
}
--- 173,177 ----
dbl_itr& xBegin, dbl_itr& xEnd, dbl_itr& yBegin) {
InterpolationConstructor interpolationConstructor =
! getType<std::string, InterpolationConstructor>(interpolationID);
return interpolationConstructor(xBegin, xEnd, yBegin);
}
***************
*** 167,176 ****
const QuantLib::Matrix& zData) {
Interpolation2DConstructor interpolation2DConstructor =
! getType<Interpolation2DConstructor>(interpolationID);
return interpolation2DConstructor(xBegin, xEnd, yBegin, yEnd, zData);
}
};
! /* *** EURIBOR *** */
typedef boost::shared_ptr<QuantLib::Euribor>(*EuriborConstructor)(
const std::string& handleYieldTermStructureID);
--- 191,200 ----
const QuantLib::Matrix& zData) {
Interpolation2DConstructor interpolation2DConstructor =
! getType<std::string, Interpolation2DConstructor>(interpolationID);
return interpolation2DConstructor(xBegin, xEnd, yBegin, yEnd, zData);
}
};
! /* *** Euribor *** */
typedef boost::shared_ptr<QuantLib::Euribor>(*EuriborConstructor)(
const std::string& handleYieldTermStructureID);
***************
*** 184,188 ****
const std::string& handleYieldTermStructureID = "") {
EuriborConstructor euriborConstructor =
! getType<EuriborConstructor>(euriborID);
return euriborConstructor(handleYieldTermStructureID);
}
--- 208,212 ----
const std::string& handleYieldTermStructureID = "") {
EuriborConstructor euriborConstructor =
! getType<std::string, EuriborConstructor>(euriborID);
return euriborConstructor(handleYieldTermStructureID);
}
***************
*** 190,193 ****
--- 214,244 ----
};
+
+
+ /* *** YieldTermStructure *** */
+ typedef boost::shared_ptr<QuantLib::YieldTermStructure>(*YieldTermStructureConstructor)(
+ const long &nDays,
+ const QuantLib::Calendar &calendar,
+ const std::vector<boost::shared_ptr<QuantLib::RateHelper> > &rateHelpers,
+ const QuantLib::DayCounter &dayCounter);
+
+ template<>
+ class Create<boost::shared_ptr<QuantLib::YieldTermStructure> > :
+ private RegistryManager<QuantLib::YieldTermStructure, EnumCurveRegistry> {
+ public:
+ boost::shared_ptr<QuantLib::YieldTermStructure> operator() (
+ const std::string& traitsID,
+ const std::string& interpolatorID,
+ const long &nDays,
+ const QuantLib::Calendar &calendar,
+ const std::vector<boost::shared_ptr<QuantLib::RateHelper> > &rateHelpers,
+ const QuantLib::DayCounter &dayCounter) {
+ KeyPair key(traitsID, interpolatorID);
+ YieldTermStructureConstructor yieldTermStructureConstructor =
+ getType<KeyPair, YieldTermStructureConstructor>(key);
+ return yieldTermStructureConstructor(nDays, calendar, rateHelpers, dayCounter);
+ }
+ };
+
}
|