Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
modelparameter.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
22using QuantLib::Real;
23using QuantLib::Time;
24using std::vector;
25
26namespace ore {
27namespace data {
28
30 : calibrate_(false), type_(ParamType::Constant) {}
31
32ModelParameter::ModelParameter(bool calibrate, ParamType type, vector<Time> times, vector<Real> values)
33 : calibrate_(calibrate), type_(type), times_(std::move(times)), values_(std::move(values)) {
34 check();
35}
36
38 return calibrate_;
39}
40
42 return type_;
43}
44
45const vector<Time>& ModelParameter::times() const {
46 return times_;
47}
48
49const vector<Real>& ModelParameter::values() const {
50 return values_;
51}
52
53void ModelParameter::setTimes(std::vector<Real> times) { times_ = std::move(times); }
54
55void ModelParameter::setValues(std::vector<Real> values) { values_ = std::move(values); }
56
57void ModelParameter::mult(const Real f) {
58 std::transform(values_.begin(), values_.end(), values_.begin(), [&f](const Real v) { return f * v; });
59}
60
61void ModelParameter::setCalibrate(const bool b) { calibrate_ = b; }
62
64 calibrate_ = XMLUtils::getChildValueAsBool(node, "Calibrate", true);
65 type_ = parseParamType(XMLUtils::getChildValue(node, "ParamType", true));
66 values_ = XMLUtils::getChildrenValuesAsDoublesCompact(node, "InitialValue", true);
69 }
70 check();
71}
72
74 XMLUtils::addChild(doc, node, "Calibrate", calibrate_);
75 XMLUtils::addGenericChild(doc, node, "ParamType", type_);
76 XMLUtils::addGenericChildAsList(doc, node, "TimeGrid", times_);
77 XMLUtils::addGenericChildAsList(doc, node, "InitialValue", values_);
78}
79
82 QL_REQUIRE(values_.size() == 1, "Parameter type is Constant so expecting a single InitialValue.");
83 QL_REQUIRE(times_.empty(), "Parameter type is Constant so expecting an empty time vector.");
84 } else if (type_ == ParamType::Piecewise) {
85 QL_REQUIRE(values_.size() == times_.size() + 1, "Parameter type is Piecewise so expecting the size of the " <<
86 "InitialValue vector (" << values_.size() << ") to be one greater than size of time vector (" <<
87 times_.size() << ").");
88 }
89}
90
92 : volatilityType_(LgmData::VolatilityType::Hagan) {}
93
95 vector<Time> times, vector<Real> values)
96 : ModelParameter(calibrate, type, times, values), volatilityType_(volatilityType) {}
97
99 : ModelParameter(calibrate, ParamType::Constant, {}, {value}), volatilityType_(volatilityType) {}
100
101VolatilityParameter::VolatilityParameter(bool calibrate, ParamType type, vector<Time> times, vector<Real> values)
102 : ModelParameter(calibrate, type, times, values) {}
103
104VolatilityParameter::VolatilityParameter(bool calibrate, QuantLib::Real value)
105 : ModelParameter(calibrate, ParamType::Constant, {}, {value}) {}
106
107const boost::optional<LgmData::VolatilityType>& VolatilityParameter::volatilityType() const {
108 return volatilityType_;
109}
110
112 XMLUtils::checkNode(node, "Volatility");
113 if (XMLNode* n = XMLUtils::getChildNode(node, "VolatilityType")) {
115 }
117}
118
120 XMLNode* node = doc.allocNode("Volatility");
121 if (volatilityType_)
122 XMLUtils::addChild(doc, node, "VolatilityType", to_string(*volatilityType_));
123 ModelParameter::append(doc, node);
124 return node;
125}
126
128 : reversionType_(LgmData::ReversionType::HullWhite) {}
129
131 vector<Time> times, vector<Real> values)
132 : ModelParameter(calibrate, type, times, values), reversionType_(reversionType) {}
133
135 bool calibrate,
136 Real value)
137 : ModelParameter(calibrate, ParamType::Constant, {}, { value }),
138 reversionType_(reversionType) {}
139
141 return reversionType_;
142}
143
145 XMLUtils::checkNode(node, "Reversion");
146 reversionType_ = parseReversionType(XMLUtils::getChildValue(node, "ReversionType", true));
148}
149
151 XMLNode* node = doc.allocNode("Reversion");
152 XMLUtils::addChild(doc, node, "ReversionType", to_string(reversionType_));
153 ModelParameter::append(doc, node);
154 return node;
155}
156
157}
158}
Linear Gauss Markov Model Parameters.
Definition: lgmdata.hpp:53
ReversionType
Supported mean reversion types.
Definition: lgmdata.hpp:56
VolatilityType
Supported volatility types.
Definition: lgmdata.hpp:67
const std::vector< QuantLib::Time > & times() const
virtual void check() const
Perform some checks on the parameters.
void setValues(std::vector< Real > values)
void mult(const Real f)
std::vector< QuantLib::Real > values_
void append(XMLDocument &doc, XMLNode *node) const
Method used by toXML in derived classes to add the members here to a node.
ModelParameter()
Default constructor.
void fromXML(XMLNode *node) override
void setTimes(std::vector< Real > times)
std::vector< QuantLib::Time > times_
const std::vector< QuantLib::Real > & values() const
void setCalibrate(const bool b)
LgmData::ReversionType reversionType_
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
LgmData::ReversionType reversionType() const
ReversionParameter()
Default constructor.
const boost::optional< LgmData::VolatilityType > & volatilityType() const
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
VolatilityParameter()
Default constructor.
boost::optional< LgmData::VolatilityType > volatilityType_
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 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 void addGenericChild(XMLDocument &doc, XMLNode *n, const char *name, const T &value)
Adds <Name>p1,p2,p3</Name>
Definition: xmlutils.hpp:137
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 string getNodeValue(XMLNode *node)
Get a node's value.
Definition: xmlutils.cpp:489
static vector< Real > getChildrenValuesAsDoublesCompact(XMLNode *node, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:327
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
SafeStack< ValueType > value
@ data
Definition: log.hpp:77
class for holding model parameter data
ParamType
Supported calibration parameter type.
Definition: irmodeldata.hpp:35
ParamType parseParamType(const string &s)
Convert parameter type string into enumerated class value.
Definition: irmodeldata.cpp:38
VolatilityType volatilityType(CapFloorVolatilityCurveConfig::VolatilityType type)
Imply QuantLib::VolatilityType from CapFloorVolatilityCurveConfig::VolatilityType.
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
LgmData::ReversionType parseReversionType(const string &s)
Enum parsers.
Definition: lgmdata.cpp:62
LgmData::VolatilityType parseVolatilityType(const string &s)
Definition: lgmdata.cpp:81
Serializable Credit Default Swap.
Definition: namespaces.docs:23
string conversion utilities