Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
inflationcurveconfig.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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
23
24#include <ql/errors.hpp>
25
26using namespace ore::data;
27
28namespace ore {
29namespace data {
30
32 const string& curveID, const string& curveDescription, const string& nominalTermStructure, const Type type,
33 const vector<string>& swapQuotes, const string& conventions, const bool extrapolate, const Calendar& calendar,
34 const DayCounter& dayCounter, const Period& lag, const Frequency& frequency, const Real baseRate,
35 const Real tolerance, const bool useLastAvailableFixingAsBaseDate, const Date& seasonalityBaseDate,
36 const Frequency& seasonalityFrequency,
37 const vector<string>& seasonalityFactors, const vector<double>& overrideSeasonalityFactors)
38 : CurveConfig(curveID, curveDescription), swapQuotes_(swapQuotes), nominalTermStructure_(nominalTermStructure),
39 type_(type), conventions_(conventions), extrapolate_(extrapolate), calendar_(calendar), dayCounter_(dayCounter),
40 lag_(lag), frequency_(frequency), baseRate_(baseRate), tolerance_(tolerance),
41 useLastAvailableFixingAsBaseDate_(useLastAvailableFixingAsBaseDate),
42 seasonalityBaseDate_(seasonalityBaseDate), seasonalityFrequency_(seasonalityFrequency),
43 seasonalityFactors_(seasonalityFactors), overrideSeasonalityFactors_(overrideSeasonalityFactors) {
45 quotes_.insert(quotes_.end(), seasonalityFactors.begin(), seasonalityFactors.end());
47}
48
50 if (!nominalTermStructure().empty())
52}
53
55 XMLUtils::checkNode(node, "InflationCurve");
56
57 curveID_ = XMLUtils::getChildValue(node, "CurveId", true);
58 curveDescription_ = XMLUtils::getChildValue(node, "CurveDescription", true);
59 nominalTermStructure_ = XMLUtils::getChildValue(node, "NominalTermStructure", true);
60
61 string type = XMLUtils::getChildValue(node, "Type", true);
62 if (type == "ZC") {
64 } else if (type == "YY") {
66 } else
67 QL_FAIL("Type " << type << " not recognized");
68
69 swapQuotes_ = XMLUtils::getChildrenValues(node, "Quotes", "Quote", true);
70
71 conventions_ = XMLUtils::getChildValue(node, "Conventions", true);
72 extrapolate_ = XMLUtils::getChildValueAsBool(node, "Extrapolation", false);
73
74 string cal = XMLUtils::getChildValue(node, "Calendar", true);
76
77 string dc = XMLUtils::getChildValue(node, "DayCounter", true);
79
80 string lag = XMLUtils::getChildValue(node, "Lag", true);
82
83 string freq = XMLUtils::getChildValue(node, "Frequency", true);
85
86 baseRate_ = QuantLib::Null<Real>();
87 string baseZr = XMLUtils::getChildValue(node, "BaseRate", false);
88 if (baseZr != "")
89 baseRate_ = parseReal(baseZr);
90
91 string tol = XMLUtils::getChildValue(node, "Tolerance", true);
92 tolerance_ = parseReal(tol);
93
94 useLastAvailableFixingAsBaseDate_ = XMLUtils::getChildValueAsBool(node, "UseLastFixingDate", false, false);
95
96 XMLNode* seasonalityNode = XMLUtils::getChildNode(node, "Seasonality");
97 seasonalityBaseDate_ = QuantLib::Null<Date>();
98 seasonalityFrequency_ = QuantLib::NoFrequency;
99 seasonalityFactors_.clear();
101 if (seasonalityNode != nullptr) {
102 seasonalityBaseDate_ = parseDate(XMLUtils::getChildValue(seasonalityNode, "BaseDate", true));
103 seasonalityFrequency_ = parseFrequency(XMLUtils::getChildValue(seasonalityNode, "Frequency", true));
104 seasonalityFactors_ = XMLUtils::getChildrenValues(seasonalityNode, "Factors", "Factor", false);
105 quotes_.insert(quotes_.end(), seasonalityFactors_.begin(), seasonalityFactors_.end());
106 std::string overrideFctStr = XMLUtils::getChildValue(seasonalityNode, "OverrideFactors", false);
107 overrideSeasonalityFactors_ = parseListOfValues<Real>(overrideFctStr, &parseReal);
108 }
110}
111
113 XMLNode* node = doc.allocNode("InflationCurve");
114
115 XMLUtils::addChild(doc, node, "CurveId", curveID_);
116 XMLUtils::addChild(doc, node, "CurveDescription", curveDescription_);
117 XMLUtils::addChild(doc, node, "NominalTermStructure", nominalTermStructure_);
118
119 if (type_ == Type::ZC) {
120 XMLUtils::addChild(doc, node, "Type", "ZC");
121 } else if (type_ == Type::YY) {
122 XMLUtils::addChild(doc, node, "Type", "YY");
123 } else
124 QL_FAIL("Unknown Type in InflationCurveConfig::toXML()");
125
126 XMLUtils::addChildren(doc, node, "Quotes", "Quote", swapQuotes_);
127 XMLUtils::addChild(doc, node, "Conventions", conventions_);
128 string extrap = (extrapolate_ ? "true" : "false");
129 XMLUtils::addChild(doc, node, "Extrapolation", extrap);
130
131 string baseRateStr;
132 if (baseRate_ != QuantLib::Null<Real>())
133 baseRateStr = to_string(baseRate_);
134 else
135 baseRateStr = "";
136
137 XMLUtils::addChild(doc, node, "Calendar", to_string(calendar_));
138 XMLUtils::addChild(doc, node, "DayCounter", to_string(dayCounter_));
139 XMLUtils::addChild(doc, node, "Lag", to_string(lag_));
140 XMLUtils::addChild(doc, node, "Frequency", to_string(frequency_));
141 XMLUtils::addChild(doc, node, "BaseRate", baseRateStr);
142 XMLUtils::addChild(doc, node, "Tolerance", tolerance_);
143
145 XMLUtils::addChild(doc, node, "UseLastFixingDate", to_string(useLastAvailableFixingAsBaseDate_));
146
147 if (seasonalityBaseDate_ != QuantLib::Null<Date>()) {
148 XMLNode* seasonalityNode = XMLUtils::addChild(doc, node, "Seasonality");
149 std::ostringstream dateStr, sFreq;
150 dateStr << QuantLib::io::iso_date(seasonalityBaseDate_);
151 sFreq << seasonalityFrequency_;
152 XMLUtils::addChild(doc, seasonalityNode, "BaseDate", dateStr.str());
153 XMLUtils::addChild(doc, seasonalityNode, "Frequency", sFreq.str());
154 if (!seasonalityFactors_.empty())
155 XMLUtils::addChildren(doc, seasonalityNode, "Factors", "Factor", seasonalityFactors_);
156 if (!overrideSeasonalityFactors_.empty())
157 XMLUtils::addChild(doc, seasonalityNode, "OverrideFactors", overrideSeasonalityFactors_);
158 }
159
160 return node;
161}
162} // namespace data
163} // 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 string & nominalTermStructure() const
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
const vector< string > & seasonalityFactors() const
const vector< string > & swapQuotes()
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 addChildren(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values)
Definition: xmlutils.cpp:502
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 vector< string > getChildrenValues(XMLNode *node, const string &names, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:306
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
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
Period parsePeriod(const string &s)
Convert text to QuantLib::Period.
Definition: parsers.cpp:171
Frequency parseFrequency(const string &s)
Convert text to QuantLib::Frequency.
Definition: parsers.cpp:348
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
DayCounter parseDayCounter(const string &s)
Convert text to QuantLib::DayCounter.
Definition: parsers.cpp:209
Inflation curve config.
@ data
Definition: log.hpp:77
Calendar calendar
Definition: utilities.cpp:441
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.
string conversion utilities