Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
underlying.hpp
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
19/*! \file ored/portfolio/underlying.hpp
20 \brief underlying data model
21 \ingroup portfolio
22*/
23
24#pragma once
25
27#include <ql/cashflows/cpicoupon.hpp>
28
29namespace ore {
30namespace data {
31
32//! Class to hold Underlyings
33/*!
34 \ingroup portfolio
35*/
36
38public:
39 //! Default Constructor
40 Underlying() : nodeName_("Underlying"), basicUnderlyingNodeName_("Name"){};
41
42 //! Constructor with type, name, weight
43 Underlying(const std::string& type, const std::string& name,
44 const QuantLib::Real weight = QuantLib::Null<QuantLib::Real>());
45
46 //! \name Serialisation
47 //@{
48 virtual void fromXML(ore::data::XMLNode* node) override;
49 virtual ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
50 //@}
51
52 //! \name Setters
53 void setType(const string& type) { type_ = type; }
54 void setName(const string& name) { name_ = name; }
55 void setWeight(const QuantLib::Real weight) { weight_ = weight; }
56 void setNodeName(const string& nodeName) { nodeName_ = nodeName; }
57 void setBasicUnderlyingNodeName(const string& basicUnderlyingNodeName) {
58 basicUnderlyingNodeName_ = basicUnderlyingNodeName;
59 }
60
61 //! \name Inspectors
62 //@{
63 const std::string& type() const { return type_; }
64 virtual const std::string& name() const { return name_; }
65 Real weight() const { return weight_; }
66 //@}
67
68protected:
69 std::string type_, name_;
70 Real weight_ = QuantLib::Null<QuantLib::Real>();
72 bool isBasic_ = false;
73};
74
76public:
77 //! Default Constructor
79 setType("Basic");
80 isBasic_ = true;
81 };
82
83 //! Constructor with identifier
84 explicit BasicUnderlying(const std::string& name) : Underlying("Basic", name) { isBasic_ = true; }
85
86 //! \name Serialisation
87 //@{
88 void fromXML(XMLNode* node) override;
89 XMLNode* toXML(XMLDocument& doc) const override;
90 //@}
91};
92
94public:
95 //! Default constructor
96 EquityUnderlying() : Underlying() { setType("Equity"); }
97
98 //! Constructor with equity name
99 explicit EquityUnderlying(const std::string& equityName) : Underlying("Equity", equityName) { isBasic_ = true; };
100
101 //! Constructor with identifier information
102 EquityUnderlying(const std::string& name, const std::string& identifierType, const std::string& currency,
103 const std::string& exchange, const QuantLib::Real weight)
107 };
108
109 const std::string& name() const override { return equityName_.empty() ? name_ : equityName_; };
110 const std::string& identifierType() const { return identifierType_; }
111 const std::string& currency() const { return currency_; }
112 const std::string& exchange() const { return exchange_; };
113
114 //! set name of equity
115 void setEquityName();
116
117 //! \name Serialisation
118 //@{
119 void fromXML(XMLNode* node) override;
120 XMLNode* toXML(XMLDocument& doc) const override;
121 //@}
122
123private:
125};
126
128public:
129 //! Default Constructor
130 CommodityUnderlying() : Underlying() { setType("Commodity"); }
131
132 //! Constructor with identifier information
133 CommodityUnderlying(const std::string& name, const QuantLib::Real weight, const std::string& priceType,
134 const QuantLib::Size futureMonthOffset, const QuantLib::Size deliveryRollDays,
135 const std::string& deliveryRollCalendar)
138
139 const std::string& priceType() const { return priceType_; }
140 QuantLib::Size futureMonthOffset() const { return futureMonthOffset_; }
141 QuantLib::Size deliveryRollDays() const { return deliveryRollDays_; }
142 const std::string& deliveryRollCalendar() const { return deliveryRollCalendar_; }
143 const std::string& futureContractMonth() const { return futureContractMonth_; }
144 const std::string& futureExpiryDate() const { return futureExpiryDate_; }
145 //! \name Serialisation
146 //@{
147 void fromXML(XMLNode* node) override;
148 XMLNode* toXML(XMLDocument& doc) const override;
149 //@}
150
151private:
152 std::string priceType_;
153 QuantLib::Size futureMonthOffset_ = QuantLib::Null<QuantLib::Size>();
154 QuantLib::Size deliveryRollDays_ = QuantLib::Null<QuantLib::Size>();
157 std::string futureExpiryDate_;
158};
159
160class FXUnderlying : public Underlying {
161public:
162 //! Default Constructor
163 explicit FXUnderlying() : Underlying() { setType("FX"); };
164
165 //! Constructor with identifier information
166 FXUnderlying(const std::string& type, const std::string& name, const QuantLib::Real weight)
167 : Underlying(type, name, weight){};
168
169 //! \name Serialisation
170 //@{
171 void fromXML(XMLNode* node) override;
172 XMLNode* toXML(XMLDocument& doc) const override;
173 //@}
174};
175
177public:
178 //! Default Constructor
179 explicit InterestRateUnderlying() : Underlying() { setType("InterestRate"); };
180
181 //! Constructor with identifier information
182 InterestRateUnderlying(const std::string& type, const std::string& name, const QuantLib::Real weight)
183 : Underlying(type, name, weight){};
184
185 //! \name Serialisation
186 //@{
187 void fromXML(XMLNode* node) override;
188 XMLNode* toXML(XMLDocument& doc) const override;
189 //@}
190};
191
193public:
194 //! Default Constructor
195 explicit InflationUnderlying() : Underlying() { setType("Inflation"); };
196
197 //! Constructor with identifier information
198 InflationUnderlying(const std::string& type, const std::string& name, const QuantLib::Real weight,
199 const QuantLib::CPI::InterpolationType& interpolation = QuantLib::CPI::InterpolationType::Flat)
201 const QuantLib::CPI::InterpolationType& interpolation() const { return interpolation_; }
202
203 //! \name Serialisation
204 //@{
205 void fromXML(XMLNode* node) override;
206 XMLNode* toXML(XMLDocument& doc) const override;
207 //@}
208private:
209 QuantLib::CPI::InterpolationType interpolation_;
210};
211
213public:
214 //! Default Constructor
215 explicit CreditUnderlying() : Underlying() { setType("Credit"); };
216
217 //! Constructor with identifier information
218 CreditUnderlying(const std::string& type, const std::string& name, const QuantLib::Real weight)
219 : Underlying(type, name, weight){};
220
221 //! \name Serialisation
222 //@{
223 void fromXML(XMLNode* node) override;
224 XMLNode* toXML(XMLDocument& doc) const override;
225 //@}
226};
227
229public:
230 //! Default constructor
232
233 //! Constructor with full bond name (e.g. ISIN:DE00001142867)
234 explicit BondUnderlying(const std::string& name) : Underlying("Bond", name) { isBasic_ = true; };
235
236 //! Constructor with identifer infomation (e.g. identifier = DE00001142867, identifierType = ISIN)
237 BondUnderlying(const std::string& identifier, const std::string& identifierType, const QuantLib::Real weight)
238 : Underlying("Bond", identifier, weight), identifierType_(identifierType){};
239
240 const std::string& name() const override { return bondName_.empty() ? name_ : bondName_; };
241 const std::string& identifierType() const { return identifierType_; }
242 double bidAskAdjustment() const { return bidAskAdjustment_; }
243
244 //! set name of bond
245 void setBondName();
246
247 //! \name Serialisation
248 //@{
249 void fromXML(XMLNode* node) override;
250 XMLNode* toXML(XMLDocument& doc) const override;
251 //@}
252
253private:
255 double bidAskAdjustment_ = 0.0;
256};
257
259public:
260 explicit UnderlyingBuilder(const std::string& nodeName = "Underlying",
261 const std::string& basicUnderlyingNodeName = "Name")
262 : nodeName_(nodeName), basicUnderlyingNodeName_(basicUnderlyingNodeName) {}
263 void fromXML(XMLNode* node) override;
264 XMLNode* toXML(ore::data::XMLDocument& doc) const override;
265
266 const QuantLib::ext::shared_ptr<Underlying>& underlying() { return underlying_; };
267
268private:
270 QuantLib::ext::shared_ptr<Underlying> underlying_;
271};
272
273} // namespace data
274} // namespace ore
BasicUnderlying(const std::string &name)
Constructor with identifier.
Definition: underlying.hpp:84
void fromXML(XMLNode *node) override
Definition: underlying.cpp:50
XMLNode * toXML(XMLDocument &doc) const override
Definition: underlying.cpp:60
BasicUnderlying()
Default Constructor.
Definition: underlying.hpp:78
void setBondName()
set name of bond
Definition: underlying.cpp:267
const std::string & identifierType() const
Definition: underlying.hpp:241
BondUnderlying(const std::string &identifier, const std::string &identifierType, const QuantLib::Real weight)
Constructor with identifer infomation (e.g. identifier = DE00001142867, identifierType = ISIN)
Definition: underlying.hpp:237
double bidAskAdjustment() const
Definition: underlying.hpp:242
void fromXML(XMLNode *node) override
Definition: underlying.cpp:276
XMLNode * toXML(XMLDocument &doc) const override
Definition: underlying.cpp:293
const std::string & name() const override
Definition: underlying.hpp:240
BondUnderlying(const std::string &name)
Constructor with full bond name (e.g. ISIN:DE00001142867)
Definition: underlying.hpp:234
BondUnderlying()
Default constructor.
Definition: underlying.hpp:231
QuantLib::Size deliveryRollDays() const
Definition: underlying.hpp:141
const std::string & deliveryRollCalendar() const
Definition: underlying.hpp:142
const std::string & priceType() const
Definition: underlying.hpp:139
CommodityUnderlying()
Default Constructor.
Definition: underlying.hpp:130
const std::string & futureExpiryDate() const
Definition: underlying.hpp:144
void fromXML(XMLNode *node) override
Definition: underlying.cpp:118
XMLNode * toXML(XMLDocument &doc) const override
Definition: underlying.cpp:146
const std::string & futureContractMonth() const
Definition: underlying.hpp:143
QuantLib::Size futureMonthOffset() const
Definition: underlying.hpp:140
CommodityUnderlying(const std::string &name, const QuantLib::Real weight, const std::string &priceType, const QuantLib::Size futureMonthOffset, const QuantLib::Size deliveryRollDays, const std::string &deliveryRollCalendar)
Constructor with identifier information.
Definition: underlying.hpp:133
CreditUnderlying(const std::string &type, const std::string &name, const QuantLib::Real weight)
Constructor with identifier information.
Definition: underlying.hpp:218
void fromXML(XMLNode *node) override
Definition: underlying.cpp:214
XMLNode * toXML(XMLDocument &doc) const override
Definition: underlying.cpp:227
CreditUnderlying()
Default Constructor.
Definition: underlying.hpp:215
void setEquityName()
set name of equity
Definition: underlying.cpp:65
const std::string & currency() const
Definition: underlying.hpp:111
const std::string & identifierType() const
Definition: underlying.hpp:110
EquityUnderlying(const std::string &equityName)
Constructor with equity name.
Definition: underlying.hpp:99
void fromXML(XMLNode *node) override
Definition: underlying.cpp:81
XMLNode * toXML(XMLDocument &doc) const override
Definition: underlying.cpp:102
const std::string & name() const override
Definition: underlying.hpp:109
EquityUnderlying()
Default constructor.
Definition: underlying.hpp:96
EquityUnderlying(const std::string &name, const std::string &identifierType, const std::string &currency, const std::string &exchange, const QuantLib::Real weight)
Constructor with identifier information.
Definition: underlying.hpp:102
const std::string & exchange() const
Definition: underlying.hpp:112
void fromXML(XMLNode *node) override
Definition: underlying.cpp:168
XMLNode * toXML(XMLDocument &doc) const override
Definition: underlying.cpp:181
FXUnderlying()
Default Constructor.
Definition: underlying.hpp:163
FXUnderlying(const std::string &type, const std::string &name, const QuantLib::Real weight)
Constructor with identifier information.
Definition: underlying.hpp:166
QuantLib::CPI::InterpolationType interpolation_
Definition: underlying.hpp:209
const QuantLib::CPI::InterpolationType & interpolation() const
Definition: underlying.hpp:201
void fromXML(XMLNode *node) override
Definition: underlying.cpp:237
XMLNode * toXML(XMLDocument &doc) const override
Definition: underlying.cpp:256
InflationUnderlying()
Default Constructor.
Definition: underlying.hpp:195
InflationUnderlying(const std::string &type, const std::string &name, const QuantLib::Real weight, const QuantLib::CPI::InterpolationType &interpolation=QuantLib::CPI::InterpolationType::Flat)
Constructor with identifier information.
Definition: underlying.hpp:198
InterestRateUnderlying()
Default Constructor.
Definition: underlying.hpp:179
void fromXML(XMLNode *node) override
Definition: underlying.cpp:191
XMLNode * toXML(XMLDocument &doc) const override
Definition: underlying.cpp:204
InterestRateUnderlying(const std::string &type, const std::string &name, const QuantLib::Real weight)
Constructor with identifier information.
Definition: underlying.hpp:182
const QuantLib::ext::shared_ptr< Underlying > & underlying()
Definition: underlying.hpp:266
void fromXML(XMLNode *node) override
Definition: underlying.cpp:305
QuantLib::ext::shared_ptr< Underlying > underlying_
Definition: underlying.hpp:270
UnderlyingBuilder(const std::string &nodeName="Underlying", const std::string &basicUnderlyingNodeName="Name")
Definition: underlying.hpp:260
XMLNode * toXML(ore::data::XMLDocument &doc) const override
Definition: underlying.cpp:336
const std::string nodeName_
Definition: underlying.hpp:269
const std::string basicUnderlyingNodeName_
Definition: underlying.hpp:269
Class to hold Underlyings.
Definition: underlying.hpp:37
std::string basicUnderlyingNodeName_
Definition: underlying.hpp:71
void setNodeName(const string &nodeName)
Definition: underlying.hpp:56
const std::string & type() const
Definition: underlying.hpp:63
Real weight() const
Definition: underlying.hpp:65
std::string nodeName_
Definition: underlying.hpp:71
virtual void fromXML(ore::data::XMLNode *node) override
Definition: underlying.cpp:33
void setName(const string &name)
Definition: underlying.hpp:54
virtual const std::string & name() const
Definition: underlying.hpp:64
Underlying()
Default Constructor.
Definition: underlying.hpp:40
void setWeight(const QuantLib::Real weight)
Definition: underlying.hpp:55
virtual ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
Definition: underlying.cpp:42
void setBasicUnderlyingNodeName(const string &basicUnderlyingNodeName)
Definition: underlying.hpp:57
void setType(const string &type)
Definition: underlying.hpp:53
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
Base class for all serializable classes.
Definition: xmlutils.hpp:101
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
trade schedule data model and serialization