Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
infdkdata.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
23using std::vector;
24
25namespace ore {
26namespace data {
27
29
31 const vector<CalibrationBasket>& calibrationBaskets,
32 const std::string& currency,
33 const std::string& index,
34 const ReversionParameter& reversion,
35 const VolatilityParameter& volatility,
36 const LgmReversionTransformation& reversionTransformation,
37 const bool ignoreDuplicateCalibrationExpiryTimes)
38 : InflationModelData(calibrationType, calibrationBaskets, currency, index, ignoreDuplicateCalibrationExpiryTimes),
39 reversion_(reversion),
40 volatility_(volatility),
41 reversionTransformation_(reversionTransformation) {}
42
44 return reversion_;
45}
46
48 return volatility_;
49}
50
53}
54
56
57 // Check the node is not null and that name is LGM or DodgsonKainth. LGM is for backward compatibility.
58 QL_REQUIRE(node, "XML Node should not be null");
59 QL_REQUIRE(XMLUtils::getNodeName(node) == "LGM" || XMLUtils::getNodeName(node) == "DodgsonKainth", "Expected " <<
60 "node name to be either LGM or DodgsonKainth");
61
63 reversion_.fromXML(XMLUtils::getChildNode(node, "Reversion"));
64 volatility_.fromXML(XMLUtils::getChildNode(node, "Volatility"));
65
66 // Read in calibration instruments to create calibration baskets. We support the legacy XML interface which was
67 // a single CalibrationCapFloors node and the new interface which is a vector of serialisable CalibrationBasket
68 // objects.
69 if (XMLNode* n = XMLUtils::getChildNode(node, "CalibrationCapFloors")) {
70 // Check that we have not already populated the calibration baskets.
71 QL_REQUIRE(calibrationBaskets_.empty(), "Calibration baskets have already been populated.");
72 // Legacy interface.
74 }
75
76 if (XMLNode* n = XMLUtils::getChildNode(node, "ParameterTransformation")) {
78 }
79}
80
82
83 XMLNode* node = doc.allocNode("DodgsonKainth");
88
89 return node;
90}
91
93
94 // Get the values from the XML
95 auto type = parseCapFloorType(XMLUtils::getChildValue(node, "CapFloor", true));
96 auto maturities = XMLUtils::getChildrenValuesAsStrings(node, "Expiries", true);
97 auto strikes = XMLUtils::getChildrenValuesAsStrings(node, "Strikes", true);
98
99 if (!strikes.empty()) {
100
101 QL_REQUIRE(strikes.size() == maturities.size(), "Number of maturities and strikes for inflation index " <<
102 index() << " should match but got " << strikes.size() << " strikes and " << maturities.size() <<
103 " maturities.");
104
105 // If any of the strikes are ATM, relabel to ATM/AtmFwd so that parseBaseStrike works below.
106 for (string& s : strikes) {
107 if (s == "ATM")
108 s = "ATM/AtmFwd";
109 }
110 } else {
111 // Default to ATM if no strikes provided.
112 strikes.resize(maturities.size(), "ATM/AtmFwd");
113 }
114
115 // Create a vector of CPI cap floor calibration instruments.
116 vector<QuantLib::ext::shared_ptr<CalibrationInstrument>> instruments;
117 for (Size i = 0; i < maturities.size(); ++i) {
118 auto p = parseDateOrPeriod(maturities[i]);
119 QuantLib::ext::shared_ptr<BaseStrike> s = parseBaseStrike(strikes[i]);
120 instruments.push_back(QuantLib::ext::make_shared<CpiCapFloor>(type, p, s));
121 }
122
123 // Populate the calibrationBaskets_ member.
124 calibrationBaskets_ = { CalibrationBasket(instruments) };
125}
126
127}
128}
LgmReversionTransformation reversionTransformation_
Definition: infdkdata.hpp:75
ReversionParameter reversion_
Definition: infdkdata.hpp:73
InfDkData()
Default constructor.
Definition: infdkdata.cpp:28
const VolatilityParameter & volatility() const
Definition: infdkdata.cpp:47
VolatilityParameter volatility_
Definition: infdkdata.hpp:74
void fromXML(XMLNode *node) override
Definition: infdkdata.cpp:55
XMLNode * toXML(XMLDocument &doc) const override
Definition: infdkdata.cpp:81
const ReversionParameter & reversion() const
Definition: infdkdata.cpp:43
const LgmReversionTransformation & reversionTransformation() const
Definition: infdkdata.cpp:51
void populateCalibrationBaskets(XMLNode *node)
Support legacy XML interface for reading calibration instruments.
Definition: infdkdata.cpp:92
void append(XMLDocument &doc, XMLNode *node) const override
Method used by toXML in derived classes to add the members here to a node.
const std::string & index() const
void fromXML(XMLNode *node) override
void fromXML(XMLNode *node) override
Definition: lgmdata.cpp:260
XMLNode * toXML(XMLDocument &doc) const override
Definition: lgmdata.cpp:266
std::vector< CalibrationBasket > calibrationBaskets_
Definition: modeldata.hpp:66
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
static string getNodeName(XMLNode *n)
Get and set a node's name.
Definition: xmlutils.cpp:473
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 vector< string > getChildrenValuesAsStrings(XMLNode *node, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:342
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
boost::variant< QuantLib::Date, QuantLib::Period > parseDateOrPeriod(const string &s)
Convert text to QuantLib::Period or QuantLib::Date.
Definition: parsers.cpp:493
CapFloor::Type parseCapFloorType(const string &s)
Definition: parsers.cpp:815
Dodgson Kainth inflation model component data for the cross asset model.
@ data
Definition: log.hpp:77
class for holding details of a zero coupon CPI cap floor calibration instrument.
CalibrationType
Supported calibration types.
Definition: irmodeldata.hpp:46
QuantLib::ext::shared_ptr< BaseStrike > parseBaseStrike(const string &strStrike)
Parse a Strike from its string representation, strStrike.
Definition: strike.cpp:262
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
vector< Real > strikes