Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
trs.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/trs.hpp
20 \brief trs
21*/
22
23#pragma once
24
26
29
30#include <boost/optional.hpp>
31
32namespace ore {
33namespace data {
34
35/*! TRS trade class */
36class TRS : public Trade {
37public:
38 class ReturnData : public XMLSerializable {
39 public:
41 ReturnData(const bool payer, const std::string& currency, const ScheduleData& scheduleData,
42 const std::string& observationLag, const std::string& observationConvention,
43 const std::string& observationCalendar, const std::string& paymentLag,
44 const std::string& paymentConvention, const std::string& paymentCalendar,
45 const std::vector<std::string>& paymentDates, const Real initialPrice,
46 const std::string& initialPriceCurrency, const std::vector<std::string>& fxTerms,
47 const boost::optional<bool> payUnderlyingCashFlowsImmediately)
53
54 bool payer() const { return payer_; }
55 const std::string& currency() const { return currency_; }
56 const ScheduleData& scheduleData() const { return scheduleData_; }
57 const std::string& observationLag() const { return observationLag_; }
58 const std::string& observationConvention() const { return observationConvention_; }
59 const std::string& observationCalendar() const { return observationCalendar_; }
60 const std::string& paymentLag() const { return paymentLag_; }
61 const std::string& paymentConvention() const { return paymentConvention_; }
62 const std::string& paymentCalendar() const { return paymentCalendar_; }
63 const std::vector<std::string>& paymentDates() const { return paymentDates_; }
64 Real initialPrice() const { return initialPrice_; }
65 const std::string& initialPriceCurrency() const { return initialPriceCurrency_; }
66 const std::vector<std::string>& fxTerms() const { return fxTerms_; }
68
69 void fromXML(XMLNode* node) override;
70 XMLNode* toXML(XMLDocument& doc) const override;
71
72 private:
73 bool payer_;
74 std::string currency_;
78 std::vector<std::string> paymentDates_;
81 std::vector<std::string> fxTerms_; // FX index strings
83 };
84
86 public:
89 explicit FundingData(const std::vector<LegData>& legData, const std::vector<NotionalType>& notionalType = {},
90 const Size fundingResetGracePeriod = 0)
92
93 const std::vector<LegData>& legData() const { return legData_; }
94 std::vector<LegData>& legData() { return legData_; }
95 const std::vector<NotionalType>& notionalType() const { return notionalType_; }
96 std::vector<NotionalType>& notionalType() { return notionalType_; }
97 QuantLib::Size fundingResetGracePeriod() const { return fundingResetGracePeriod_; }
99
100 void fromXML(XMLNode* node) override;
101 XMLNode* toXML(XMLDocument& doc) const override;
102
103 private:
104 std::vector<LegData> legData_;
105 std::vector<NotionalType> notionalType_;
106 QuantLib::Size fundingResetGracePeriod_ = 0;
107 };
108
110 public:
113
114 const LegData& legData() const { return legData_; }
115 LegData& legData() { return legData_; }
116
117 void fromXML(XMLNode* node) override;
118 XMLNode* toXML(XMLDocument& doc) const override;
119
120 private:
122 };
123
124 TRS() : Trade("TotalReturnSwap") {}
125
126 TRS(const Envelope& env, const std::vector<QuantLib::ext::shared_ptr<Trade>>& underlying,
127 const std::vector<std::string>& underlyingDerivativeId, const ReturnData& returnData,
129 : Trade("TotalReturnSwap", env), underlying_(underlying), underlyingDerivativeId_(underlyingDerivativeId),
131 QL_REQUIRE(underlying_.size() == underlyingDerivativeId_.size(),
132 "TRS: underlying size (" << underlying_.size() << ") must match underlying derivative id size ("
133 << underlyingDerivativeId_.size() << ")");
134 }
135
136 void build(const QuantLib::ext::shared_ptr<EngineFactory>&) override;
137
138 //! Inspectors
139 //@{
140 const std::vector<QuantLib::ext::shared_ptr<Trade>>& underlying() const { return underlying_; }
141 const ReturnData& returnData() const { return returnData_; }
142 const FundingData& fundingData() const { return fundingData_; }
144 const std::string& creditRiskCurrency() const { return creditRiskCurrency_; }
145 const std::map<std::string, SimmCreditQualifierMapping>& creditQualifierMapping() const {
147 }
148 //@}
149
150 //! Interface
151 //@{
152 std::map<AssetClass, std::set<std::string>>
153 underlyingIndices(const QuantLib::ext::shared_ptr<ReferenceDataManager>& referenceDataManager = nullptr) const override;
154 QuantLib::Real notional() const override;
155 void fromXML(XMLNode* node) override;
156 XMLNode* toXML(XMLDocument& doc) const override;
157 //@}
158
159protected:
160 QuantLib::ext::shared_ptr<QuantExt::FxIndex>
161 getFxIndex(const QuantLib::ext::shared_ptr<Market> market, const std::string& configuration, const std::string& domestic,
162 const std::string& foreign, std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndices,
163 std::set<std::string>& missingFxIndexPairs) const;
164
165 mutable std::vector<QuantLib::ext::shared_ptr<Trade>> underlying_;
166 // empty if underlying is not from a Derivative subnode of UnderlyingData
167 mutable std::vector<std::string> underlyingDerivativeId_;
171
173 std::map<std::string, SimmCreditQualifierMapping> creditQualifierMapping_;
174};
175
177std::ostream& operator<<(std::ostream& os, const TRS::FundingData::NotionalType t);
178
179/*! just an Alias */
180class CFD : public TRS {
181public:
182 CFD() : TRS() { tradeType_ = "ContractForDifference"; }
183 CFD(const Envelope& env, const std::vector<QuantLib::ext::shared_ptr<Trade>>& underlying,
184 const std::vector<std::string>& underlyingDerivativeId, const ReturnData& returnData,
186 : TRS(env, underlying, underlyingDerivativeId, returnData, fundingData, additionalCashflowData) {
187 tradeType_ = "ContractForDifference";
188 }
189};
190
191} // namespace data
192} // namespace ore
CFD(const Envelope &env, const std::vector< QuantLib::ext::shared_ptr< Trade > > &underlying, const std::vector< std::string > &underlyingDerivativeId, const ReturnData &returnData, const FundingData &fundingData, const AdditionalCashflowData &additionalCashflowData)
Definition: trs.hpp:183
Serializable object holding generic trade data, reporting dimensions.
Definition: envelope.hpp:51
Serializable object holding leg data.
Definition: legdata.hpp:844
Serializable schedule data.
Definition: schedule.hpp:202
AdditionalCashflowData(const LegData &legData)
Definition: trs.hpp:112
void fromXML(XMLNode *node) override
Definition: trs.cpp:134
XMLNode * toXML(XMLDocument &doc) const override
Definition: trs.cpp:143
const LegData & legData() const
Definition: trs.hpp:114
FundingData(const std::vector< LegData > &legData, const std::vector< NotionalType > &notionalType={}, const Size fundingResetGracePeriod=0)
Definition: trs.hpp:89
const std::vector< NotionalType > & notionalType() const
Definition: trs.hpp:95
std::vector< LegData > legData_
Definition: trs.hpp:104
void fromXML(XMLNode *node) override
Definition: trs.cpp:105
std::vector< NotionalType > & notionalType()
Definition: trs.hpp:96
XMLNode * toXML(XMLDocument &doc) const override
Definition: trs.cpp:120
QuantLib::Size fundingResetGracePeriod_
Definition: trs.hpp:106
const std::vector< LegData > & legData() const
Definition: trs.hpp:93
std::vector< LegData > & legData()
Definition: trs.hpp:94
QuantLib::Size & fundingResetGracePeriod()
Definition: trs.hpp:98
std::vector< NotionalType > notionalType_
Definition: trs.hpp:105
QuantLib::Size fundingResetGracePeriod() const
Definition: trs.hpp:97
boost::optional< bool > payUnderlyingCashFlowsImmediately_
Definition: trs.hpp:82
std::string observationConvention_
Definition: trs.hpp:76
const std::string & observationConvention() const
Definition: trs.hpp:58
std::vector< std::string > fxTerms_
Definition: trs.hpp:81
std::string paymentLag_
Definition: trs.hpp:76
const std::vector< std::string > & paymentDates() const
Definition: trs.hpp:63
const std::string & currency() const
Definition: trs.hpp:55
const std::vector< std::string > & fxTerms() const
Definition: trs.hpp:66
std::string currency_
Definition: trs.hpp:74
const ScheduleData & scheduleData() const
Definition: trs.hpp:56
const std::string & initialPriceCurrency() const
Definition: trs.hpp:65
std::vector< std::string > paymentDates_
Definition: trs.hpp:78
boost::optional< bool > payUnderlyingCashFlowsImmediately() const
Definition: trs.hpp:67
const std::string & observationCalendar() const
Definition: trs.hpp:59
void fromXML(XMLNode *node) override
Definition: trs.cpp:51
XMLNode * toXML(XMLDocument &doc) const override
Definition: trs.cpp:75
const std::string & paymentCalendar() const
Definition: trs.hpp:62
std::string initialPriceCurrency_
Definition: trs.hpp:80
const std::string & observationLag() const
Definition: trs.hpp:57
std::string observationLag_
Definition: trs.hpp:76
ScheduleData scheduleData_
Definition: trs.hpp:75
std::string paymentCalendar_
Definition: trs.hpp:77
const std::string & paymentLag() const
Definition: trs.hpp:60
std::string observationCalendar_
Definition: trs.hpp:76
const std::string & paymentConvention() const
Definition: trs.hpp:61
ReturnData(const bool payer, const std::string &currency, const ScheduleData &scheduleData, const std::string &observationLag, const std::string &observationConvention, const std::string &observationCalendar, const std::string &paymentLag, const std::string &paymentConvention, const std::string &paymentCalendar, const std::vector< std::string > &paymentDates, const Real initialPrice, const std::string &initialPriceCurrency, const std::vector< std::string > &fxTerms, const boost::optional< bool > payUnderlyingCashFlowsImmediately)
Definition: trs.hpp:41
Real initialPrice() const
Definition: trs.hpp:64
std::string paymentConvention_
Definition: trs.hpp:76
bool payer() const
Definition: trs.hpp:54
const std::string & creditRiskCurrency() const
Definition: trs.hpp:144
std::map< std::string, SimmCreditQualifierMapping > creditQualifierMapping_
Definition: trs.hpp:173
QuantLib::ext::shared_ptr< QuantExt::FxIndex > getFxIndex(const QuantLib::ext::shared_ptr< Market > market, const std::string &configuration, const std::string &domestic, const std::string &foreign, std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > &fxIndices, std::set< std::string > &missingFxIndexPairs) const
Definition: trs.cpp:262
AdditionalCashflowData additionalCashflowData_
Definition: trs.hpp:170
const std::vector< QuantLib::ext::shared_ptr< Trade > > & underlying() const
Inspectors.
Definition: trs.hpp:140
std::map< AssetClass, std::set< std::string > > underlyingIndices(const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
Interface.
Definition: trs.cpp:151
std::vector< QuantLib::ext::shared_ptr< Trade > > underlying_
Definition: trs.hpp:165
std::vector< std::string > underlyingDerivativeId_
Definition: trs.hpp:167
TRS(const Envelope &env, const std::vector< QuantLib::ext::shared_ptr< Trade > > &underlying, const std::vector< std::string > &underlyingDerivativeId, const ReturnData &returnData, const FundingData &fundingData, const AdditionalCashflowData &additionalCashflowData)
Definition: trs.hpp:126
QuantLib::Real notional() const override
Return the current notional in npvCurrency. See individual sub-classes for the precise definition.
Definition: trs.cpp:769
FundingData fundingData_
Definition: trs.hpp:169
void fromXML(XMLNode *node) override
Definition: trs.cpp:167
XMLNode * toXML(XMLDocument &doc) const override
Definition: trs.cpp:234
const AdditionalCashflowData & additionalCashflowData() const
Definition: trs.hpp:143
const FundingData & fundingData() const
Definition: trs.hpp:142
const ReturnData & returnData() const
Definition: trs.hpp:141
ReturnData returnData_
Definition: trs.hpp:168
const std::map< std::string, SimmCreditQualifierMapping > & creditQualifierMapping() const
Definition: trs.hpp:145
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Definition: trs.cpp:292
std::string creditRiskCurrency_
Definition: trs.hpp:172
Trade base class.
Definition: trade.hpp:55
string tradeType_
Definition: trade.hpp:196
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
Base class for all serializable classes.
Definition: xmlutils.hpp:101
@ data
Definition: log.hpp:77
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
TRS::FundingData::NotionalType parseTrsFundingNotionalType(const std::string &s)
Definition: trs.cpp:789
Serializable Credit Default Swap.
Definition: namespaces.docs:23
mapping of SIMM credit qualifiers
base trade data model and serialization
Trade Factory.