Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
inflationcapfloorvolcurveconfig.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
24
25#include <ql/errors.hpp>
26
27#include <boost/algorithm/string.hpp>
28
29namespace ore {
30namespace data {
31
33 switch (t) {
35 return out << "RATE_LNVOL";
37 return out << "RATE_NVOL";
39 return out << "RATE_SLNVOL";
40 default:
41 QL_FAIL("unknown VolatilityType(" << Integer(t) << ")");
42 }
43}
44
46 switch (t) {
48 return out << "PRICE";
50 return out << "VOLATILITY";
51 default:
52 QL_FAIL("unknown QuoteType(" << Integer(t) << ")");
53 }
54}
55
57 const string& curveID, const string& curveDescription, const Type type, const QuoteType& quoteType,
58 const VolatilityType& volatilityType, const bool extrapolate, const vector<string>& tenors,
59 const vector<string>& capStrikes, const vector<string>& floorStrikes, const vector<string>& strikes,
60 const DayCounter& dayCounter, Natural settleDays, const Calendar& calendar,
61 const BusinessDayConvention& businessDayConvention, const string& index, const string& indexCurve,
62 const string& yieldTermStructure, const Period& observationLag, const string& quoteIndex, const string& conventions,
63 const bool useLastAvailableFixingDate)
64 : CurveConfig(curveID, curveDescription), type_(type), quoteType_(quoteType), volatilityType_(volatilityType),
65 extrapolate_(extrapolate), tenors_(tenors), capStrikes_(capStrikes), floorStrikes_(floorStrikes),
66 strikes_(strikes), dayCounter_(dayCounter), settleDays_(settleDays), calendar_(calendar),
67 businessDayConvention_(businessDayConvention), index_(index), indexCurve_(indexCurve),
68 yieldTermStructure_(yieldTermStructure), observationLag_(observationLag), quoteIndex_(quoteIndex),
69 conventions_(conventions), useLastAvailableFixingDate_(useLastAvailableFixingDate) {
71}
72
74 if (!yieldTermStructure().empty())
76 if (!indexCurve().empty())
78}
79
81 if (quotes_.size() == 0) {
82
83 string type;
84 if (type_ == Type::ZC)
85 type = "ZC";
86 else if (type_ == Type::YY)
87 type = "YY";
88
89 // Determine the index string to use for the quotes.
90 string index = quoteIndex_.empty() ? index_ : quoteIndex_;
91
92 std::stringstream ssBase;
94 ssBase << type << "_INFLATIONCAPFLOOR/PRICE/" << index << "/";
95 else
96 ssBase << type << "_INFLATIONCAPFLOOR/" << volatilityType_ << "/" << index << "/";
97 string base = ssBase.str();
98
99 // TODO: how to tell if atmFlag or relative flag should be true
100 for (auto t : tenors_) {
102 for (auto s : capStrikes_) {
103 quotes_.push_back(base + t + "/C/" + s);
104 }
105 for (auto s : floorStrikes_) {
106 quotes_.push_back(base + t + "/F/" + s);
107 }
108 } else {
109 for (auto s : strikes_) {
110 quotes_.push_back(base + t + "/F/" + s);
111 }
112 }
113 }
114
116 for (auto t : tenors_) {
117 std::stringstream ss;
118 quotes_.push_back(type + "_INFLATIONCAPFLOOR/SHIFT/" + index + "/" + t);
119 }
120 }
121 }
122 return quotes_;
123}
124
126 XMLUtils::checkNode(node, "InflationCapFloorVolatility");
127
128 curveID_ = XMLUtils::getChildValue(node, "CurveId", true);
129 curveDescription_ = XMLUtils::getChildValue(node, "CurveDescription", true);
130
131 string type = XMLUtils::getChildValue(node, "Type", true);
132 if (type == "ZC") {
133 type_ = Type::ZC;
134 } else if (type == "YY") {
135 type_ = Type::YY;
136 } else
137 QL_FAIL("Type " << type << " not recognized");
138
139 // Get the quote type
140 string quoteType = XMLUtils::getChildValue(node, "QuoteType", true);
141 if (quoteType == "Price") {
143 } else if (quoteType == "Volatility") {
145 } else {
146 QL_FAIL("Quote type, " << quoteType << ", not recognized");
147 }
148
149 // Get the volatility type
150 string volType = XMLUtils::getChildValue(node, "VolatilityType", true);
151 if (volType == "Normal") {
153 } else if (volType == "Lognormal") {
155 } else if (volType == "ShiftedLognormal") {
157 } else {
158 QL_FAIL("Volatility type, " << volType << ", not recognized");
159 }
160 extrapolate_ = XMLUtils::getChildValueAsBool(node, "Extrapolation", true);
161 tenors_ = XMLUtils::getChildrenValuesAsStrings(node, "Tenors", true);
162
163 // We are requiring explicit strikes so there should be at least one strike
165 capStrikes_ = XMLUtils::getChildrenValuesAsStrings(node, "CapStrikes", true);
166 floorStrikes_ = XMLUtils::getChildrenValuesAsStrings(node, "FloorStrikes", true);
167 QL_REQUIRE(!capStrikes_.empty() || !floorStrikes_.empty(),
168 "CapStrikes or FloorStrikes node should not be empty");
169 // Set strikes to the sorted union of cap and floor strikes
170 std::set<Real> strikeSet;
171 for (Size i = 0; i < capStrikes_.size(); ++i)
172 strikeSet.insert(parseReal(capStrikes_[i]));
173 for (Size i = 0; i < floorStrikes_.size(); ++i)
174 strikeSet.insert(parseReal(floorStrikes_[i]));
175 strikes_.clear();
176 for (auto s : strikeSet)
177 strikes_.push_back(to_string(s));
178 for (Size i = 0; i < strikes_.size(); ++i)
179 DLOG("ZC Inflation Cap/Floor Strike " << i << " = " << strikes_[i]);
180 } else {
181 strikes_ = XMLUtils::getChildrenValuesAsStrings(node, "Strikes", true);
182 QL_REQUIRE(!strikes_.empty(), "Strikes node should not be empty");
183 }
184 settleDays_ = 0; // optional
185 if (XMLNode* n = XMLUtils::getChildNode(node, "SettlementDays")) {
186 Integer d = parseInteger(XMLUtils::getNodeValue(n));
187 QL_REQUIRE(d >= 0, "SettlementDays (" << d << ") must be non-negative");
188 settleDays_ = static_cast<Natural>(d);
189 }
190 calendar_ = parseCalendar(XMLUtils::getChildValue(node, "Calendar", true));
191 dayCounter_ = parseDayCounter(XMLUtils::getChildValue(node, "DayCounter", true));
192 businessDayConvention_ = parseBusinessDayConvention(XMLUtils::getChildValue(node, "BusinessDayConvention", true));
193 index_ = XMLUtils::getChildValue(node, "Index", true);
194 indexCurve_ = XMLUtils::getChildValue(node, "IndexCurve", true);
195 yieldTermStructure_ = XMLUtils::getChildValue(node, "YieldTermStructure", true);
196 observationLag_ = parsePeriod(XMLUtils::getChildValue(node, "ObservationLag", true));
197 quoteIndex_ = XMLUtils::getChildValue(node, "QuoteIndex", false);
198 conventions_ = XMLUtils::getChildValue(node, "Conventions", false, "");
200 XMLUtils::getChildValueAsBool(node, "UseLastFixingDate", false, false);
202}
203
205 XMLNode* node = doc.allocNode("InflationCapFloorVolatility");
206
207 XMLUtils::addChild(doc, node, "CurveId", curveID_);
208 XMLUtils::addChild(doc, node, "CurveDescription", curveDescription_);
209
210 if (type_ == Type::ZC) {
211 XMLUtils::addChild(doc, node, "Type", "ZC");
212 } else if (type_ == Type::YY) {
213 XMLUtils::addChild(doc, node, "Type", "YY");
214 } else
215 QL_FAIL("Unknown Type in InflationCapFloorVolatilityCurveConfig::toXML()");
216
218 XMLUtils::addChild(doc, node, "QuoteType", "Price");
219 } else if (quoteType_ == QuoteType::Volatility) {
220 XMLUtils::addChild(doc, node, "QuoteType", "Volatility");
221 } else {
222 QL_FAIL("Unknown QuoteType in InflationCapFloorVolatilityCurveConfig::toXML()");
223 }
224
226 XMLUtils::addChild(doc, node, "VolatilityType", "Normal");
228 XMLUtils::addChild(doc, node, "VolatilityType", "Lognormal");
230 XMLUtils::addChild(doc, node, "VolatilityType", "ShiftedLognormal");
231 } else {
232 QL_FAIL("Unknown VolatilityType in InflationCapFloorVolatilityCurveConfig::toXML()");
233 }
234
235 XMLUtils::addChild(doc, node, "Extrapolation", extrapolate_);
236 XMLUtils::addGenericChildAsList(doc, node, "Tenors", tenors_);
237 XMLUtils::addChild(doc, node, "SettlementDays", static_cast<int>(settleDays_));
238 XMLUtils::addGenericChildAsList(doc, node, "CapStrikes", capStrikes_);
239 XMLUtils::addGenericChildAsList(doc, node, "FloorStrikes", floorStrikes_);
240 XMLUtils::addGenericChildAsList(doc, node, "Strikes", strikes_);
241 XMLUtils::addChild(doc, node, "Calendar", to_string(calendar_));
242 XMLUtils::addChild(doc, node, "DayCounter", to_string(dayCounter_));
243 XMLUtils::addChild(doc, node, "BusinessDayConvention", to_string(businessDayConvention_));
244 XMLUtils::addChild(doc, node, "Index", index_);
245 XMLUtils::addChild(doc, node, "IndexCurve", indexCurve_);
246 XMLUtils::addChild(doc, node, "ObservationLag", to_string(observationLag_));
247 XMLUtils::addChild(doc, node, "YieldTermStructure", yieldTermStructure_);
248 if (!quoteIndex_.empty())
249 XMLUtils::addChild(doc, node, "QuoteIndex", quoteIndex_);
250 if (!conventions_.empty())
251 XMLUtils::addChild(doc, node, "Conventions", conventions_);
253 XMLUtils::addChild(doc, node, "UseLastFixingDate", useLastAvailableFixingDate_);
254 return node;
255}
256} // namespace data
257} // namespace ore
Base curve configuration.
Definition: curveconfig.hpp:41
vector< string > quotes_
Definition: curveconfig.hpp:74
map< CurveSpec::CurveType, set< string > > requiredCurveIds_
Definition: curveconfig.hpp:75
const vector< string > & quotes() override
Return all the market quotes required for this config.
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
static void addGenericChildAsList(XMLDocument &doc, XMLNode *n, const string &name, const vector< T > &values, const string &attrName="", const string &attr="")
Definition: xmlutils.hpp:144
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static bool getChildValueAsBool(XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
Definition: xmlutils.cpp:296
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static string getNodeValue(XMLNode *node)
Get a node's value.
Definition: xmlutils.cpp:489
static vector< string > getChildrenValuesAsStrings(XMLNode *node, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:342
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
CurveSpec parser.
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.
Definition: parsers.cpp:157
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
Definition: parsers.cpp:173
Period parsePeriod(const string &s)
Convert text to QuantLib::Period.
Definition: parsers.cpp:171
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
DayCounter parseDayCounter(const string &s)
Convert text to QuantLib::DayCounter.
Definition: parsers.cpp:209
Map text representations to QuantLib/QuantExt types.
Inflation CapFloor volatility curve configuration class.
@ data
Definition: log.hpp:77
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
Calendar calendar
Definition: utilities.cpp:441
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
VolatilityType volatilityType(CapFloorVolatilityCurveConfig::VolatilityType type)
Imply QuantLib::VolatilityType from CapFloorVolatilityCurveConfig::VolatilityType.
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
vector< Real > strikes
string conversion utilities