Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
basecorrelationcurveconfig.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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
22#include <ql/errors.hpp>
23
25
26namespace ore {
27namespace data {
28
30 : settlementDays_(0), businessDayConvention_(Following), extrapolate_(true), adjustForLosses_(true) {}
31
33 const string& curveDescription,
34 const vector<string>& detachmentPoints,
35 const vector<string>& terms,
36 Size settlementDays,
37 const Calendar& calendar,
38 BusinessDayConvention businessDayConvention,
39 DayCounter dayCounter,
40 bool extrapolate,
41 const string& quoteName,
42 const Date& startDate,
43 const Period& indexTerm,
44 boost::optional<DateGeneration::Rule> rule,
45 bool adjustForLosses)
46 : CurveConfig(curveID, curveDescription),
47 detachmentPoints_(detachmentPoints),
48 terms_(terms),
49 settlementDays_(settlementDays),
50 calendar_(calendar),
51 businessDayConvention_(businessDayConvention),
52 dayCounter_(dayCounter),
53 extrapolate_(extrapolate),
54 quoteName_(quoteName.empty() ? curveID : quoteName),
55 startDate_(startDate),
56 indexTerm_(indexTerm),
57 rule_(rule),
58 adjustForLosses_(adjustForLosses) {}
59
60const vector<string>& BaseCorrelationCurveConfig::quotes() {
61 if (quotes_.size() == 0) {
62 string base = "CDS_INDEX/BASE_CORRELATION/" + quoteName_ + "/";
63 for (auto t : terms_) {
64 for (auto dp : detachmentPoints_) {
65 quotes_.push_back(base + t + "/" + dp);
66 }
67 }
68 }
69 return quotes_;
70}
71
73 XMLUtils::checkNode(node, "BaseCorrelation");
74
75 curveID_ = XMLUtils::getChildValue(node, "CurveId", true);
76 curveDescription_ = XMLUtils::getChildValue(node, "CurveDescription", true);
77 terms_ = XMLUtils::getChildrenValuesAsStrings(node, "Terms", true);
78 detachmentPoints_ = XMLUtils::getChildrenValuesAsStrings(node, "DetachmentPoints", true);
79 settlementDays_ = parseInteger(XMLUtils::getChildValue(node, "SettlementDays", true));
80 calendar_ = parseCalendar(XMLUtils::getChildValue(node, "Calendar", true));
82 dayCounter_ = parseDayCounter(XMLUtils::getChildValue(node, "DayCounter", true));
83 extrapolate_ = parseBool(XMLUtils::getChildValue(node, "Extrapolate", true));
84 quoteName_ = XMLUtils::getChildValue(node, "QuoteName", false);
85 if (quoteName_.empty())
87
88 startDate_ = Date();
89 if (auto n = XMLUtils::getChildNode(node, "StartDate"))
91
92 string t = XMLUtils::getChildValue(node, "IndexTerm", false);
93 indexTerm_ = t.empty() ? 0 * Days : parsePeriod(t);
94
95 if (auto n = XMLUtils::getChildNode(node, "Rule"))
97
98 adjustForLosses_ = true;
99 if (auto n = XMLUtils::getChildNode(node, "AdjustForLosses"))
101}
102
104 XMLNode* node = doc.allocNode("BaseCorrelation");
105
106 XMLUtils::addChild(doc, node, "CurveId", curveID_);
107 XMLUtils::addChild(doc, node, "CurveDescription", curveDescription_);
108 XMLUtils::addGenericChildAsList(doc, node, "Terms", terms_);
109 XMLUtils::addGenericChildAsList(doc, node, "DetachmentPoints", detachmentPoints_);
110 XMLUtils::addChild(doc, node, "SettlementDays", int(settlementDays_));
111 XMLUtils::addChild(doc, node, "Calendar", to_string(calendar_));
112 XMLUtils::addChild(doc, node, "BusinessDayConvention", to_string(businessDayConvention_));
113 XMLUtils::addChild(doc, node, "DayCounter", to_string(dayCounter_));
114 XMLUtils::addChild(doc, node, "Extrapolate", extrapolate_);
115 XMLUtils::addChild(doc, node, "QuoteName", quoteName_);
116
117 if (startDate_ != Date())
118 XMLUtils::addChild(doc, node, "StartDate", to_string(startDate_));
119
120 if (rule_)
121 XMLUtils::addChild(doc, node, "Rule", to_string(*rule_));
122
123 if (indexTerm_ != 0 * Days) {
124 XMLUtils::addChild(doc, node, "IndexTerm", indexTerm_);
125 }
126
127 XMLUtils::addChild(doc, node, "AdjustForLosses", adjustForLosses_);
128
129 return node;
130}
131} // namespace data
132} // namespace ore
Base Correlation curve configuration classes.
XMLNode * toXML(XMLDocument &doc) const override
const vector< string > & quotes() override
Return all the market quotes required for this config.
boost::optional< QuantLib::DateGeneration::Rule > rule_
Base curve configuration.
Definition: curveconfig.hpp:41
vector< string > quotes_
Definition: curveconfig.hpp:74
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
XML Utilities Class.
Definition: xmlutils.hpp:119
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 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
DateGeneration::Rule parseDateGenerationRule(const string &s)
Convert text to QuantLib::DateGeneration::Rule.
Definition: parsers.cpp:328
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
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
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
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
@ 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