25#include <ql/errors.hpp>
27#include <boost/algorithm/string.hpp>
28#include <boost/assign.hpp>
29#include <boost/bimap.hpp>
31using boost::assign::list_of;
32using QuantLib::BusinessDayConvention;
34using QuantLib::DayCounter;
35using QuantLib::Natural;
44typedef boost::bimap<string, CapFloorVolatilityCurveConfig::VolatilityType>
BmType;
52const set<string>
validInterps = {
"Linear",
"LinearFlat",
"BackwardFlat",
"Cubic",
"CubicFlat"};
55 const string& curveID,
const string& curveDescription,
const VolatilityType&
volatilityType,
bool extrapolate,
56 bool flatExtrapolation,
bool inlcudeAtm,
const vector<string>& tenors,
const vector<string>& strikes,
57 const DayCounter& dayCounter, Natural settleDays,
const Calendar&
calendar,
58 const BusinessDayConvention& businessDayConvention,
const std::string& index,
59 const QuantLib::Period& rateComputationPeriod,
const Size onCapSettlementDays,
const string& discountCurve,
60 const string& interpolationMethod,
const string& interpolateOn,
const string& timeInterpolation,
61 const string& strikeInterpolation,
const vector<string>& atmTenors,
const BootstrapConfig& bootstrapConfig,
62 const string& inputType,
const boost::optional<ParametricSmileConfiguration>& parametricSmileConfiguration)
64 flatExtrapolation_(flatExtrapolation), includeAtm_(inlcudeAtm), tenors_(tenors), strikes_(
strikes),
65 dayCounter_(dayCounter), settleDays_(settleDays), calendar_(
calendar),
66 businessDayConvention_(businessDayConvention), index_(index), rateComputationPeriod_(rateComputationPeriod),
67 onCapSettlementDays_(onCapSettlementDays), discountCurve_(discountCurve),
68 interpolationMethod_(interpolationMethod), interpolateOn_(interpolateOn), timeInterpolation_(timeInterpolation),
69 strikeInterpolation_(strikeInterpolation), atmTenors_(atmTenors), bootstrapConfig_(bootstrapConfig),
70 inputType_(inputType), parametricSmileConfiguration_(parametricSmileConfiguration) {
73 extrapolation_ = !extrapolate_ ?
"None" : (flatExtrapolation_ ?
"Flat" :
"Linear");
82 populateRequiredCurveIds();
89 const std::string& curveID,
const std::string& curveDescription,
const std::string& proxySourceCurveId,
90 const std::string& proxySourceIndex,
const std::string& proxyTargetIndex,
91 const QuantLib::Period& proxySourceRateComputationPeriod,
const QuantLib::Period& proxyTargetRateComputationPeriod)
92 :
CurveConfig(curveID, curveDescription), proxySourceCurveId_(proxySourceCurveId),
93 proxySourceIndex_(proxySourceIndex), proxyTargetIndex_(proxyTargetIndex),
94 proxySourceRateComputationPeriod_(proxySourceRateComputationPeriod),
95 proxyTargetRateComputationPeriod_(proxyTargetRateComputationPeriod) {
109 QL_REQUIRE(source !=
nullptr,
110 "CapFloorVolatilityCurveConfig (" <<
curveID_ <<
"): ProxyConfig requires child node 'Source'");
117 QL_REQUIRE(target !=
nullptr,
118 "CapFloorVolatilityCurveConfig (" <<
curveID_ <<
"): ProxyConfig requires child node 'Target'");
144 <<
"): The IborIndex node is deprecated, use Index instead.");
149 QL_FAIL(
"CapFloorVOlatilityCurveConfig (" <<
curveID_
150 <<
"): Index node (or the deprecated IborIndex node) expected");
170 QL_REQUIRE(d >= 0,
"SettlementDays (" << d <<
") must be non-negative");
209 QL_REQUIRE(!
tenors_.empty() || !
atmTenors_.empty(),
"Tenors and AtmTenors cannot both be empty");
304 return QuantExt::CapFloorTermVolSurfaceExact::InterpolationMethod::BicubicSpline;
306 return QuantExt::CapFloorTermVolSurfaceExact::InterpolationMethod::Bilinear;
314 "Volatility type (" <<
static_cast<int>(
type) <<
") is not valid");
343 return index->currency().code();
356 string stem =
"CAPFLOOR/" +
to_string(qType) +
"/" + ccy +
"/";
358 stem +=
index() +
"/";
361 for (
const string& t :
tenors_) {
363 quotes_.push_back(stem + t +
"/" + tenor +
"/0/0/" + s);
370 quotes_.push_back(stem + t +
"/" + tenor +
"/1/1/0");
383 QL_REQUIRE(extrapolation ==
"Linear" || extrapolation ==
"Flat" || extrapolation ==
"None",
384 "Extrapolation must be one of Linear, Flat or None");
397 else if (
inputType_ ==
"OptionletVolatilities")
400 QL_FAIL(
"InputType " <<
inputType_ <<
" not supported");
405 "InterpolateOn (" <<
interpolateOn_ <<
") must be TermVolatilities or OptionletVolatilities");
408 QuantExt::SabrParametricVolatility::ModelVariant dummySabrVariant;
411 std::function<QuantExt::SabrParametricVolatility::ModelVariant(
const std::string&)>(
414 QL_REQUIRE(
strikeInterpolation_ !=
"BackwardFlat",
"BackwardFlat StrikeInterpolation is not allowed");
416 QL_REQUIRE(!
tenors_.empty(),
"Tenors must be given for a surface (strikes are given)");
429 QL_FAIL(
"Unknown VolatilityType (" <<
static_cast<int>(
volatilityType_) <<
")");
437 return ShiftedLognormal;
441 QL_FAIL(
"Unknown VolatilityType (" <<
static_cast<int>(type) <<
")");
Cap floor volatility curve configuration class.
void fromXML(ore::data::XMLNode *node) override
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
QuantLib::Period proxyTargetRateComputationPeriod_
MarketDatum::QuoteType quoteType() const
void populateRequiredCurveIds()
Populate required curve ids.
ReportConfig reportConfig_
std::string interpolationMethod_
const std::string & index() const
const string & currency() const
void configureVolatilityType(const std::string &type)
Set the value of volatilityType_ based on the value of type.
void populateQuotes()
Populate the quotes vector.
@ OptionletSurfaceWithAtm
std::string proxySourceIndex_
QuantLib::Period rateComputationPeriod_
std::string proxyTargetIndex_
bool quoteIncludesIndexName_
std::vector< std::string > strikes_
QuantLib::Natural settleDays_
bool quoteIncludesIndexName() const
void configureType()
Set the value of type_ i.e. the type of cap floor structure that is configured.
std::vector< std::string > tenors_
void fromXML(XMLNode *node) override
BootstrapConfig bootstrapConfig_
std::vector< std::string > atmTenors_
XMLNode * toXML(XMLDocument &doc) const override
const std::string & discountCurve() const
VolatilityType
The type of volatility quotes that have been configured.
QuantLib::Calendar calendar_
std::string discountCurve_
std::string interpolateOn_
QuantLib::BusinessDayConvention businessDayConvention_
std::string timeInterpolation_
std::string proxySourceCurveId_
void configureExtrapolation(const std::string &extrapolation)
void validate() const
Validate the configuration.
string indexTenor() const
std::string extrapolation_
QuantExt::CapFloorTermVolSurfaceExact::InterpolationMethod interpolationMethod() const
CapFloorVolatilityCurveConfig()
Default constructor.
QuantLib::Period proxySourceRateComputationPeriod_
QuantLib::DayCounter dayCounter_
QuantLib::Size onCapSettlementDays_
std::string strikeInterpolation_
boost::optional< ParametricSmileConfiguration > parametricSmileConfiguration_
std::string toString(VolatilityType type) const
Convert VolatilityType type to string.
VolatilityType volatilityType_
Base curve configuration.
map< CurveSpec::CurveType, set< string > > requiredCurveIds_
QuoteType
Supported market quote types.
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
static void addGenericChildAsList(XMLDocument &doc, XMLNode *n, const string &name, const vector< T > &values, const string &attrName="", const string &attr="")
static void checkNode(XMLNode *n, const string &expectedName)
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
static bool getChildValueAsBool(XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static string getNodeValue(XMLNode *node)
Get a node's value.
static vector< string > getChildrenValuesAsStrings(XMLNode *node, const string &name, bool mandatory=false)
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
static void appendNode(XMLNode *parent, XMLNode *child)
QuantLib::ext::shared_ptr< CurveSpec > parseCurveSpec(const string &s)
function to convert a string into a curve spec
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
QuantLib::ext::shared_ptr< IborIndex > parseIborIndex(const string &s, const Handle< YieldTermStructure > &h)
Convert std::string to QuantLib::IborIndex.
bool tryParse(const std::string &str, T &obj, std::function< T(const std::string &)> parser)
SabrParametricVolatility::ModelVariant parseSabrParametricVolatilityModelVariant(const std::string &s)
Parse SabrParametricVolatility::ModelVariant.
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
Period parsePeriod(const string &s)
Convert text to QuantLib::Period.
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
DayCounter parseDayCounter(const string &s)
Convert text to QuantLib::DayCounter.
Map text representations to QuantLib/QuantExt types.
#define WLOG(text)
Logging Macro (Level = Warning)
boost::bimap< string, CapFloorVolatilityCurveConfig::VolatilityType > BmType
VolatilityType volatilityType(CapFloorVolatilityCurveConfig::VolatilityType type)
Imply QuantLib::VolatilityType from CapFloorVolatilityCurveConfig::VolatilityType.
std::string to_string(const LocationInfo &l)
const set< string > validInterps
const BmType volatilityTypeMap
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.
string conversion utilities