Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crcirdata.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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
21
22namespace ore {
23namespace data {
24
26
27 if (name_ != rhs.name_ || currency_ != rhs.currency_ ||
29 startValue_ != rhs.startValue_ ||
35 return false;
36 }
37 return true;
38}
39
40bool CrCirData::operator!=(const CrCirData& rhs) { return !(*this == rhs); }
41
43 if (s == "None")
45 else if (s == "CurveAndFlatVol")
47 else {
48 QL_FAIL("CrCirData::CalibrationStrategy " << s << " not recognised.");
49 }
50}
51
52std::ostream& operator<<(std::ostream& oss, const CrCirData::CalibrationStrategy& s) {
54 oss << "None";
56 oss << "CurveAndFlatVol";
57 else
58 QL_FAIL("CIR Calibration strategy(" << ((int)s) << ") not covered");
59 return oss;
60}
61
63
64 name_ = XMLUtils::getAttribute(node, "name");
65 LOG("CIR with attribute (name) = " << name_);
66
67 currency_ = XMLUtils::getChildValue(node, "Currency", true);
68 LOG("CIR currency = " << currency_);
69
70 std::string calibTypeString = XMLUtils::getChildValue(node, "CalibrationType", true);
71 calibrationType_ = parseCalibrationType(calibTypeString);
72 LOG("CIR calibration type = " << calibTypeString);
73
74 std::string calibStratString = XMLUtils::getChildValue(node, "CalibrationStrategy", true);
76 LOG("CIR calibration strategy = " << calibStratString);
77
78 startValue_ = XMLUtils::getChildValueAsDouble(node, "StartValue", true);
79 LOG("CIR start value_ = " << startValue_);
80
81 reversionValue_ = XMLUtils::getChildValueAsDouble(node, "ReversionValue", true);
82 LOG("CIR reversion value = " << reversionValue_);
83
84 longTermValue_ = XMLUtils::getChildValueAsDouble(node, "LongTermValue", true);
85 LOG("CIR long term value = " << longTermValue_);
86
87 volatility_ = XMLUtils::getChildValueAsDouble(node, "Volatility", true);
88 LOG("CIR volatility = " << volatility_);
89
90 relaxedFeller_ = XMLUtils::getChildValueAsBool(node, "RelaxedFeller", true);
91 LOG("CIR relaxed feller = " << relaxedFeller_);
92
93 fellerFactor_ = XMLUtils::getChildValueAsDouble(node, "FellerFactor", true);
94 LOG("CIR feller factor = " << fellerFactor_);
95
96 tolerance_ = XMLUtils::getChildValueAsDouble(node, "Tolerance", true);
97 LOG("CIR tolerance = " << tolerance_);
98
99 // Calibration Swaptions
100
101 XMLNode* optionsNode = XMLUtils::getChildNode(node, "CalibrationCdsOptions");
102
103 if (optionsNode) {
104
105 optionExpiries() = XMLUtils::getChildrenValuesAsStrings(optionsNode, "Expiries", false);
106 optionTerms() = XMLUtils::getChildrenValuesAsStrings(optionsNode, "Terms", false);
107 QL_REQUIRE(optionExpiries().size() == optionTerms().size(),
108 "vector size mismatch in cds option expiries/terms for name " << name_);
109 optionStrikes() = XMLUtils::getChildrenValuesAsStrings(optionsNode, "Strikes", false);
110 if (optionStrikes().size() > 0) {
111 QL_REQUIRE(optionStrikes().size() == optionExpiries().size(),
112 "vector size mismatch in cds option expiries/strikes for name " << name_);
113 } else // Default: ATM
114 optionStrikes().resize(optionExpiries().size(), "ATM");
115
116 for (Size i = 0; i < optionExpiries().size(); i++) {
117 LOG("CrCir calibration cds option " << optionExpiries()[i] << " x " << optionTerms()[i] << " "
118 << optionStrikes()[i]);
119 }
120 }
121
122 LOG("CrCirData done");
123}
124
126
127 XMLNode* cirNode = doc.allocNode("CIR");
128 XMLUtils::addAttribute(doc, cirNode, "name", name_);
129
130 XMLUtils::addChild(doc, cirNode, "Currency", currency_);
131
132 XMLUtils::addGenericChild(doc, cirNode, "CalibrationType", calibrationType_);
133 XMLUtils::addGenericChild(doc, cirNode, "CalibrationStrategy", calibrationStrategy_);
134
135 XMLUtils::addChild(doc, cirNode, "StartValue", startValue_);
136 XMLUtils::addChild(doc, cirNode, "ReversionValue", reversionValue_);
137 XMLUtils::addChild(doc, cirNode, "LongTermValue", longTermValue_);
138 XMLUtils::addChild(doc, cirNode, "Volatility", volatility_);
139
140 XMLUtils::addChild(doc, cirNode, "RelaxedFeller", relaxedFeller_);
141 XMLUtils::addChild(doc, cirNode, "FellerFactor", fellerFactor_);
142 XMLUtils::addChild(doc, cirNode, "Tolerance", tolerance_);
143
144 // swaption calibration
145 XMLNode* calibrationSwaptionsNode = XMLUtils::addChild(doc, cirNode, "CalibrationCdsOptions");
146 XMLUtils::addGenericChildAsList(doc, calibrationSwaptionsNode, "Expiries", optionExpiries_);
147 XMLUtils::addGenericChildAsList(doc, calibrationSwaptionsNode, "Terms", optionTerms_);
148 XMLUtils::addGenericChildAsList(doc, calibrationSwaptionsNode, "Strikes", optionStrikes_);
149
150 return cirNode;
151}
152
153} // namespace data
154} // namespace ore
std::string currency_
Definition: crcirdata.hpp:93
std::vector< std::string > & optionStrikes()
Definition: crcirdata.hpp:79
CalibrationType calibrationType_
Definition: crcirdata.hpp:94
CalibrationStrategy calibrationStrategy_
Definition: crcirdata.hpp:95
std::string name_
Definition: crcirdata.hpp:92
std::vector< std::string > optionTerms_
Definition: crcirdata.hpp:101
std::vector< std::string > optionExpiries_
Definition: crcirdata.hpp:100
void fromXML(XMLNode *node) override
Definition: crcirdata.cpp:62
XMLNode * toXML(XMLDocument &doc) const override
Definition: crcirdata.cpp:125
std::vector< std::string > & optionTerms()
Definition: crcirdata.hpp:78
bool operator==(const CrCirData &rhs)
Definition: crcirdata.cpp:25
std::vector< std::string > & optionExpiries()
Definition: crcirdata.hpp:77
bool operator!=(const CrCirData &rhs)
Definition: crcirdata.cpp:40
std::vector< std::string > optionStrikes_
Definition: crcirdata.hpp:102
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 addAttribute(XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
Definition: xmlutils.cpp:412
static string getAttribute(XMLNode *node, const string &attrName)
Definition: xmlutils.cpp:419
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 addGenericChild(XMLDocument &doc, XMLNode *n, const char *name, const T &value)
Adds <Name>p1,p2,p3</Name>
Definition: xmlutils.hpp:137
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
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 > 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
CIR credit model data.
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
#define LOG(text)
Logging Macro (Level = Notice)
Definition: log.hpp:552
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
CalibrationType parseCalibrationType(const string &s)
Convert calibration type string into enumerated class value.
Definition: irmodeldata.cpp:47
CrCirData::CalibrationStrategy parseCirCalibrationStrategy(const string &s)
Definition: crcirdata.cpp:42
Size size(const ValueType &v)
Definition: value.cpp:145
Serializable Credit Default Swap.
Definition: namespaces.docs:23