Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
HwModelData Class Reference

Hull White Model Parameters. More...

#include <ored/model/irhwmodeldata.hpp>

+ Inheritance diagram for HwModelData:
+ Collaboration diagram for HwModelData:

Public Member Functions

 HwModelData ()
 Default constructor. More...
 
 HwModelData (std::string qualifier, CalibrationType calibrationType, bool calibrateKappa, ParamType kappaType, std::vector< Time > kappaTimes, std::vector< QuantLib::Array > kappaValues, bool calibrateSigma, ParamType sigmaType, std::vector< Time > sigmaTimes, std::vector< QuantLib::Matrix > sigmaValues, std::vector< std::string > optionExpiries=std::vector< std::string >(), std::vector< std::string > optionTerms=std::vector< std::string >(), std::vector< std::string > optionStrikes=std::vector< std::string >())
 Detailed constructor. More...
 
void clear () override
 Clear list of calibration instruments. More...
 
void reset () override
 Reset member variables to defaults. More...
 
Serialisation
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 
Setters/Getters
boolcalibrateKappa ()
 
ParamTypekappaType ()
 
std::vector< Time > & kappaTimes ()
 
std::vector< Array > & kappaValues ()
 
boolcalibrateSigma ()
 
ParamTypesigmaType ()
 
std::vector< Time > & sigmaTimes ()
 
std::vector< QuantLib::Matrix > & sigmaValues ()
 
std::vector< std::string > & optionExpiries ()
 
std::vector< std::string > & optionTerms ()
 
std::vector< std::string > & optionStrikes ()
 
- Public Member Functions inherited from IrModelData
 IrModelData (const std::string &name)
 minimal constructor More...
 
 IrModelData (const std::string &name, const std::string &qualifier, CalibrationType calibrationType)
 Detailed constructor. More...
 
virtual void clear ()
 Clear list of calibration instruments. More...
 
virtual void reset ()
 Reset member variables to defaults. More...
 
const std::string & name ()
 
std::string & qualifier ()
 
CalibrationTypecalibrationType ()
 
virtual std::string ccy () const
 
- Public Member Functions inherited from XMLSerializable
virtual ~XMLSerializable ()
 
virtual void fromXML (XMLNode *node)=0
 
virtual XMLNodetoXML (XMLDocument &doc) const =0
 
void fromFile (const std::string &filename)
 
void toFile (const std::string &filename) const
 
void fromXMLString (const std::string &xml)
 Parse from XML string. More...
 
std::string toXMLString () const
 Parse from XML string. More...
 

Operators

bool calibrateKappa_
 
ParamType kappaType_
 
std::vector< Time > kappaTimes_
 
std::vector< QuantLib::Array > kappaValues_
 
bool calibrateSigma_
 
ParamType sigmaType_
 
std::vector< Time > sigmaTimes_
 
std::vector< QuantLib::Matrix > sigmaValues_
 
std::vector< std::string > optionExpiries_
 
std::vector< std::string > optionTerms_
 
std::vector< std::string > optionStrikes_
 
bool operator== (const HwModelData &rhs)
 
bool operator!= (const HwModelData &rhs)
 

Additional Inherited Members

- Protected Attributes inherited from IrModelData
std::string name_
 
std::string qualifier_
 
CalibrationType calibrationType_
 

Detailed Description

Hull White Model Parameters.

This class contains the description of a Hull White interest rate model and instructions for how to calibrate it.

Definition at line 48 of file irhwmodeldata.hpp.

Constructor & Destructor Documentation

◆ HwModelData() [1/2]

Default constructor.

Definition at line 51 of file irhwmodeldata.hpp.

◆ HwModelData() [2/2]

HwModelData ( std::string  qualifier,
CalibrationType  calibrationType,
bool  calibrateKappa,
ParamType  kappaType,
std::vector< Time >  kappaTimes,
std::vector< QuantLib::Array >  kappaValues,
bool  calibrateSigma,
ParamType  sigmaType,
std::vector< Time >  sigmaTimes,
std::vector< QuantLib::Matrix >  sigmaValues,
std::vector< std::string >  optionExpiries = std::vector<std::string>(),
std::vector< std::string >  optionTerms = std::vector<std::string>(),
std::vector< std::string >  optionStrikes = std::vector<std::string>() 
)

Detailed constructor.

Definition at line 56 of file irhwmodeldata.hpp.

std::vector< QuantLib::Matrix > & sigmaValues()
std::vector< QuantLib::Array > kappaValues_
std::vector< std::string > & optionStrikes()
std::vector< Array > & kappaValues()
std::vector< std::string > optionTerms_
std::vector< std::string > optionExpiries_
std::vector< QuantLib::Matrix > sigmaValues_
std::vector< Time > kappaTimes_
std::vector< std::string > & optionTerms()
std::vector< Time > sigmaTimes_
std::vector< std::string > & optionExpiries()
std::vector< Time > & sigmaTimes()
std::vector< std::string > optionStrikes_
std::vector< Time > & kappaTimes()
CalibrationType & calibrationType()
std::string & qualifier()

Member Function Documentation

◆ clear()

void clear ( )
overridevirtual

Clear list of calibration instruments.

Reimplemented from IrModelData.

Definition at line 47 of file irhwmodeldata.cpp.

47 {
48 optionExpiries_.clear();
49 optionTerms_.clear();
50 optionStrikes_.clear();
51}

◆ reset()

void reset ( )
overridevirtual

Reset member variables to defaults.

Reimplemented from IrModelData.

Definition at line 53 of file irhwmodeldata.cpp.

53 {
56 calibrateKappa_ = false;
58 kappaTimes_ = {};
59 kappaValues_ = {Array(1, 0.01)};
60 calibrateSigma_ = false;
62 sigmaTimes_ = {};
63 sigmaValues_ = {Matrix(1, 1, 0.03)};
64}
CalibrationType calibrationType_
virtual void reset()
Reset member variables to defaults.
+ Here is the call graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from IrModelData.

Definition at line 66 of file irhwmodeldata.cpp.

66 {
67
69 if (qualifier_.empty()) {
70 std::string ccy = XMLUtils::getAttribute(node, "ccy");
71 if (!ccy.empty()) {
73 WLOG("HwModelData: attribute ccy is deprecated, use key instead.");
74 }
75 }
76 LOG("HwModelData with attribute (key) = " << qualifier_);
77
78 // Mean reversion config
79
80 XMLNode* reversionNode = XMLUtils::getChildNode(node, "Reversion");
81
82 calibrateKappa_ = XMLUtils::getChildValueAsBool(reversionNode, "Calibrate", true);
83 LOG("Hull White mean reversion calibrate = " << calibrateKappa_);
84 QL_REQUIRE(!calibrateKappa_, "Calibration of kappa not supported yet");
85
86 std::string kappaCalibrationString = XMLUtils::getChildValue(reversionNode, "ParamType", true);
87 kappaType_ = parseParamType(kappaCalibrationString);
88 LOG("Hull White Kappa param type = " << kappaCalibrationString);
89 QL_REQUIRE(kappaType_ == ParamType::Constant, "Only constant mean reversion supported at the moment");
90
91 kappaTimes_ = XMLUtils::getChildrenValuesAsDoublesCompact(reversionNode, "TimeGrid", true);
92 LOG("Hull White Reversion time grid size = " << kappaTimes_.size());
93
94 XMLNode* initialValuesNode = XMLUtils::getChildNode(reversionNode, "InitialValue");
95 for (XMLNode* child = XMLUtils::getChildNode(initialValuesNode, "Kappa"); child;
96 child = XMLUtils::getNextSibling(child, "Kappa")) {
97 auto kappa_t = XMLUtils::getNodeValueAsDoublesCompact(child);
98 kappaValues_.push_back(Array(kappa_t.begin(), kappa_t.end()));
99 }
100
101 QL_REQUIRE(!kappaValues_.empty(), "No initial mean reversion values given");
102 size_t nFactors = kappaValues_.front().size();
103 for (size_t i = 1; i < kappaValues_.size(); ++i) {
104 QL_REQUIRE(nFactors == kappaValues_[i].size(), "expect " << nFactors << " factors but got "
105 << kappaValues_[i].size() << " at time "
106 << kappaTimes_[i]);
107 }
108
109 // Volatility config
110
111 XMLNode* volatilityNode = XMLUtils::getChildNode(node, "Volatility");
112
113 calibrateSigma_ = XMLUtils::getChildValueAsBool(volatilityNode, "Calibrate", true);
114 LOG("Hull White volatility calibrate = " << calibrateSigma_);
115 QL_REQUIRE(!calibrateSigma_, "Calibration of kappa not supported yet");
116
117 std::string sigmaParameterTypeString = XMLUtils::getChildValue(volatilityNode, "ParamType", true);
118 sigmaType_ = parseParamType(sigmaParameterTypeString);
119 LOG("Hull White Volatility param type = " << sigmaParameterTypeString);
120 QL_REQUIRE(sigmaType_ == ParamType::Constant, "Only constant constant supported at the moment");
121
122 sigmaTimes_ = XMLUtils::getChildrenValuesAsDoublesCompact(volatilityNode, "TimeGrid", true);
123 LOG("Hull White volatility time grid size = " << sigmaTimes_.size());
124
125 XMLNode* initialSigmasNode = XMLUtils::getChildNode(volatilityNode, "InitialValue");
126 for (XMLNode* sigmaNode = XMLUtils::getChildNode(initialSigmasNode, "Sigma"); sigmaNode;
127 sigmaNode = XMLUtils::getNextSibling(sigmaNode, "Sigma")) {
128 std::vector<std::vector<double>> matrix;
129 for (XMLNode* rowNode = XMLUtils::getChildNode(sigmaNode, "Row"); rowNode;
130 rowNode = XMLUtils::getNextSibling(rowNode, "Row")) {
131 matrix.push_back(XMLUtils::getNodeValueAsDoublesCompact(rowNode));
132 QL_REQUIRE(matrix.back().size() == nFactors, "Mismatch between kappa and sigma");
133 }
134 QL_REQUIRE(!matrix.empty(), "Sigma not provided");
135 QL_REQUIRE(!matrix.front().empty(), "Sigma not provided");
136 Matrix sigma(matrix.size(), matrix.front().size(), 0.0);
137 for (size_t i = 0; i < matrix.size(); ++i) {
138 for (size_t j = 0; j < nFactors; ++j)
139 sigma[i][j] = matrix[i][j];
140 }
141 sigmaValues_.push_back(sigma);
142 }
143
144 QL_REQUIRE(!sigmaValues_.empty(), "need at least one sigma matrix");
145 size_t m_brownians = sigmaValues_.front().rows();
146 for (size_t i = 0; i < sigmaValues_.size(); ++i) {
147 QL_REQUIRE(sigmaValues_[i].rows() == m_brownians, "all sigma matrixes need to have the same row dimension");
148 }
149
151 LOG("HwModelData done");
152}
virtual std::string ccy() const
virtual void fromXML(XMLNode *node) override
static string getAttribute(XMLNode *node, const string &attrName)
Definition: xmlutils.cpp:419
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 XMLNode * getNextSibling(XMLNode *node, const string &name="")
Get a node's next sibling node.
Definition: xmlutils.cpp:484
static vector< Real > getChildrenValuesAsDoublesCompact(XMLNode *node, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:327
static vector< Real > getNodeValueAsDoublesCompact(XMLNode *node)
Get a node's compact values as vector of doubles.
Definition: xmlutils.cpp:332
#define LOG(text)
Logging Macro (Level = Notice)
Definition: log.hpp:552
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
ParamType parseParamType(const string &s)
Convert parameter type string into enumerated class value.
Definition: irmodeldata.cpp:38
Size size(const ValueType &v)
Definition: value.cpp:145
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Reimplemented from IrModelData.

Definition at line 154 of file irhwmodeldata.cpp.

154 {
155
156 XMLNode* hwModelNode = IrModelData::toXML(doc);
157 // reversion
158 XMLNode* reversionNode = XMLUtils::addChild(doc, hwModelNode, "Reversion");
159 XMLUtils::addChild(doc, reversionNode, "Calibrate", calibrateKappa_);
160 XMLUtils::addGenericChild(doc, reversionNode, "ParamType", kappaType_);
161 XMLUtils::addGenericChildAsList(doc, reversionNode, "TimeGrid", kappaTimes_);
162
163 auto kappaNode = XMLUtils::addChild(doc, reversionNode, "InitialValue");
164 for (const auto& kappa : kappaValues_) {
165 std::ostringstream oss;
166 if (kappa.size() == 0) {
167 oss << "";
168 } else {
169 oss << kappa[0];
170 for (Size i = 1; i < kappa.size(); i++) {
171 oss << ", " << kappa[i];
172 }
173 }
174 XMLUtils::addChild(doc, kappaNode, "Kappa", oss.str());
175 }
176 // volatility
177 XMLNode* volatilityNode = XMLUtils::addChild(doc, hwModelNode, "Volatility");
178 XMLUtils::addChild(doc, volatilityNode, "Calibrate", calibrateSigma_);
179
180 XMLUtils::addGenericChild(doc, volatilityNode, "ParamType", sigmaType_);
181 XMLUtils::addGenericChildAsList(doc, volatilityNode, "TimeGrid", sigmaTimes_);
182
183 auto sigmaValues = XMLUtils::addChild(doc, reversionNode, "InitialValue");
184 for (const auto& sigma : sigmaValues_) {
185 auto sigmaNode = XMLUtils::addChild(doc, sigmaValues, "Sigma");
186 for (size_t row = 0; row < sigma.rows(); ++row) {
187 std::ostringstream oss;
188 if (sigma.columns() == 0) {
189 oss << "";
190 } else {
191 oss << sigma[row][0];
192 for (Size col = 0; col < sigma.columns(); col++) {
193 oss << ", " << sigma[row][col];
194 }
195 }
196 XMLUtils::addChild(doc, sigmaNode, "Row", oss.str());
197 }
198 }
199 return hwModelNode;
200}
virtual XMLNode * toXML(XMLDocument &doc) const override
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 XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
+ Here is the call graph for this function:

◆ calibrateKappa()

bool & calibrateKappa ( )

Definition at line 81 of file irhwmodeldata.hpp.

81{ return calibrateKappa_; }

◆ kappaType()

ParamType & kappaType ( )

Definition at line 82 of file irhwmodeldata.hpp.

82{ return kappaType_; }

◆ kappaTimes()

std::vector< Time > & kappaTimes ( )

Definition at line 83 of file irhwmodeldata.hpp.

83{ return kappaTimes_; }

◆ kappaValues()

std::vector< Array > & kappaValues ( )

Definition at line 84 of file irhwmodeldata.hpp.

84{ return kappaValues_; }

◆ calibrateSigma()

bool & calibrateSigma ( )

Definition at line 85 of file irhwmodeldata.hpp.

85{ return calibrateSigma_; }

◆ sigmaType()

ParamType & sigmaType ( )

Definition at line 86 of file irhwmodeldata.hpp.

86{ return sigmaType_; }

◆ sigmaTimes()

std::vector< Time > & sigmaTimes ( )

Definition at line 87 of file irhwmodeldata.hpp.

87{ return sigmaTimes_; }

◆ sigmaValues()

std::vector< QuantLib::Matrix > & sigmaValues ( )

Definition at line 88 of file irhwmodeldata.hpp.

88{ return sigmaValues_; }
+ Here is the caller graph for this function:

◆ optionExpiries()

std::vector< std::string > & optionExpiries ( )

Definition at line 89 of file irhwmodeldata.hpp.

89{ return optionExpiries_; }

◆ optionTerms()

std::vector< std::string > & optionTerms ( )

Definition at line 90 of file irhwmodeldata.hpp.

90{ return optionTerms_; }

◆ optionStrikes()

std::vector< std::string > & optionStrikes ( )

Definition at line 91 of file irhwmodeldata.hpp.

91{ return optionStrikes_; }

◆ operator==()

bool operator== ( const HwModelData rhs)

Definition at line 34 of file irhwmodeldata.cpp.

34 {
35
36 if (qualifier_ != rhs.qualifier_ || calibrationType_ != rhs.calibrationType_ ||
37 calibrateKappa_ != rhs.calibrateKappa_ || kappaType_ != rhs.kappaType_ || kappaTimes_ != rhs.kappaTimes_ ||
38 kappaValues_ != rhs.kappaValues_ || calibrateSigma_ != rhs.calibrateSigma_ || sigmaType_ != rhs.sigmaType_ ||
39 sigmaTimes_ != rhs.sigmaTimes_ || sigmaValues_ != rhs.sigmaValues_) {
40 return false;
41 }
42 return true;
43}

◆ operator!=()

bool operator!= ( const HwModelData rhs)

Definition at line 45 of file irhwmodeldata.cpp.

45{ return !(*this == rhs); }

Member Data Documentation

◆ calibrateKappa_

bool calibrateKappa_
private

Definition at line 101 of file irhwmodeldata.hpp.

◆ kappaType_

ParamType kappaType_
private

Definition at line 102 of file irhwmodeldata.hpp.

◆ kappaTimes_

std::vector<Time> kappaTimes_
private

Definition at line 103 of file irhwmodeldata.hpp.

◆ kappaValues_

std::vector<QuantLib::Array> kappaValues_
private

Definition at line 104 of file irhwmodeldata.hpp.

◆ calibrateSigma_

bool calibrateSigma_
private

Definition at line 106 of file irhwmodeldata.hpp.

◆ sigmaType_

ParamType sigmaType_
private

Definition at line 107 of file irhwmodeldata.hpp.

◆ sigmaTimes_

std::vector<Time> sigmaTimes_
private

Definition at line 108 of file irhwmodeldata.hpp.

◆ sigmaValues_

std::vector<QuantLib::Matrix> sigmaValues_
private

Definition at line 109 of file irhwmodeldata.hpp.

◆ optionExpiries_

std::vector<std::string> optionExpiries_
private

Definition at line 110 of file irhwmodeldata.hpp.

◆ optionTerms_

std::vector<std::string> optionTerms_
private

Definition at line 111 of file irhwmodeldata.hpp.

◆ optionStrikes_

std::vector<std::string> optionStrikes_
private

Definition at line 112 of file irhwmodeldata.hpp.