Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
trswrapper.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/trswrapper.hpp
20 \brief generic wrapper for trs (bond, convertible bond, equity, ...)
21*/
22
23#pragma once
24
26
28
30
31namespace ore {
32namespace data {
33
34//! TRS Instrument Wrapper
35class TRSWrapper : public QuantLib::Instrument {
36public:
37 class arguments;
38 class results;
39 class engine;
40
41 /* To compute the return,
42
43 - the underlyingIndex fixing at the last relevant past valuation date and
44 - the underlying->NPV()
45
46 is used (for each underlying if several are given). The index fixing of each underyling is multiplied by the
47 underlyingMultiplier, while it is assumed that the underlying->NPV() already contains this scaling. Note that the
48 underlyingIndex is only queried for past fixings < today.
49
50 The initial price is also multiplied by the underlyingMultiplier, if the number of underlyings is one. If there
51 is more than one underlying, the initial price must be given as an absolute "dollar" amount.
52
53 If includeUnderlyingCashflowsInReturn = true, the cashflows in the underlying legs between the last relevant
54 valuation date and today multiplied with the underlyingMultiplier are assumed to correctly represent the
55 flows of the underlying. If the underlyingIndex is an EquityIndex or CompositeIndex, dividends stored in this
56 index are also taken into account as flows.
57
58 The fx indices are used to convert the asset (return) currency to the funding currency. If no conversion is
59 required, the respective index should be a nullptr. The fx indices can be given in any direction, i.e. this
60 wrapper will figure out whether to apply the fixing or the inverse fixing.
61 */
62 TRSWrapper(const std::vector<QuantLib::ext::shared_ptr<ore::data::Trade>>& underlying,
63 const std::vector<QuantLib::ext::shared_ptr<QuantLib::Index>>& underlyingIndex,
64 const std::vector<QuantLib::Real> underlyingMultiplier, const bool includeUnderlyingCashflowsInReturn,
65 const QuantLib::Real initialPrice, const QuantLib::Currency& initialPriceCurrency,
66 const std::vector<QuantLib::Currency>& assetCurrency, const QuantLib::Currency& returnCurrency,
67 const std::vector<QuantLib::Date>& valuationSchedule, const std::vector<QuantLib::Date>& paymentSchedule,
68 const std::vector<QuantLib::Leg>& fundingLegs,
69 const std::vector<TRS::FundingData::NotionalType>& fundingNotionalTypes,
70 const QuantLib::Currency& fundingCurrency, const QuantLib::Size fundingResetGracePeriod,
71 const bool paysAsset, const bool paysFunding, const QuantLib::Leg& additionalCashflowLeg,
72 const bool additionalCashflowLegPayer, const QuantLib::Currency& additionalCashflowCurrency,
73 const std::vector<QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& fxIndexAsset,
74 const QuantLib::ext::shared_ptr<QuantExt::FxIndex>& fxIndexReturn,
75 const QuantLib::ext::shared_ptr<QuantExt::FxIndex>& fxIndexAdditionalCashflows,
76 const std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>>& addFxindices);
77
78 //! \name Instrument interface
79 //@{
80 bool isExpired() const override;
82 void fetchResults(const QuantLib::PricingEngine::results*) const override;
83 //@}
84
85private:
86 std::vector<QuantLib::ext::shared_ptr<ore::data::Trade>> underlying_;
87 std::vector<QuantLib::ext::shared_ptr<QuantLib::Index>> underlyingIndex_;
88 std::vector<QuantLib::Real> underlyingMultiplier_;
90 QuantLib::Real initialPrice_;
91 const QuantLib::Currency initialPriceCurrency_;
92 const std::vector<QuantLib::Currency> assetCurrency_;
93 const QuantLib::Currency returnCurrency_;
94 std::vector<QuantLib::Date> valuationSchedule_, paymentSchedule_;
95 std::vector<QuantLib::Leg> fundingLegs_;
96 std::vector<TRS::FundingData::NotionalType> fundingNotionalTypes_;
97 const QuantLib::Currency fundingCurrency_;
98 const QuantLib::Size fundingResetGracePeriod_;
102 const QuantLib::Currency additionalCashflowCurrency_;
103 std::vector<QuantLib::ext::shared_ptr<QuantExt::FxIndex>> fxIndexAsset_;
104 QuantLib::ext::shared_ptr<QuantExt::FxIndex> fxIndexReturn_, fxIndexAdditionalCashflows_;
105 std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>> addFxIndices_;
106
108};
109
111public:
112 // direct copy from the instrument
113 std::vector<QuantLib::ext::shared_ptr<ore::data::Trade>> underlying_;
114 std::vector<QuantLib::ext::shared_ptr<QuantLib::Index>> underlyingIndex_;
115 std::vector<QuantLib::Real> underlyingMultiplier_;
117 QuantLib::Real initialPrice_;
118 QuantLib::Currency initialPriceCurrency_;
119 std::vector<QuantLib::Currency> assetCurrency_;
120 QuantLib::Currency returnCurrency_;
121 std::vector<QuantLib::Date> valuationSchedule_, paymentSchedule_;
122 std::vector<QuantLib::Leg> fundingLegs_;
123 std::vector<TRS::FundingData::NotionalType> fundingNotionalTypes_;
124 QuantLib::Currency fundingCurrency_;
129 QuantLib::Currency additionalCashflowCurrency_;
130 std::vector<QuantLib::ext::shared_ptr<QuantExt::FxIndex>> fxIndexAsset_;
131 QuantLib::ext::shared_ptr<QuantExt::FxIndex> fxIndexReturn_, fxIndexAdditionalCashflows_;
132 std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex>> addFxIndices_;
133
134 void validate() const override;
135};
136
137class TRSWrapper::results : public Instrument::results {
138public:
139 void reset() override {}
140};
141
142class TRSWrapper::engine : public QuantLib::GenericEngine<TRSWrapper::arguments, TRSWrapper::results> {};
143
145public:
146 void calculate() const override;
147
148private:
149 /* Computes underlying value, fx conversion for each underlying and the start date of the nth current
150 valuation period. Notice there might be more than one "current" valuation period, if a payment lag
151 is present and nth refers to the nth such period in order the associated valuation periods are
152 given. Consider e.g. the situation
153 v0 < v1 < today < p0 < p1
154 where [v0,v1] and [v1,v2] are two valuation periods and p0 and p1 are the associated payment dates
155
156 The endDate will be set to the valuation end date of the valuation period if that is <= today, i.e.
157 the period return is already determined, but not yet paid. Otherwise endDate is set to null.
158
159 For nth = 0 this functions always returns true.
160 For nth > 0 the function returns true if there is a nth current period to consider */
161 bool computeStartValue(std::vector<QuantLib::Real>& underlyingStartValue,
162 std::vector<QuantLib::Real>& fxConversionFactor, QuantLib::Date& startDate,
163 QuantLib::Date& endDate, bool& usingInitialPrice, const Size nth) const;
164 // return conversion rate from source to target on date, today's fixing projection is enforced
165 QuantLib::Real getFxConversionRate(const QuantLib::Date& date, const QuantLib::Currency& source,
166 const QuantLib::Currency& target, const bool enforceProjection) const;
167
168 // return underlying #i fixing on date < today
169 Real getUnderlyingFixing(const Size i, const QuantLib::Date& date, const bool enforceProjection) const;
170
171 // additional inspectors
172 QuantLib::Real currentNotional() const;
173};
174
175} // namespace data
176} // namespace ore
std::vector< TRS::FundingData::NotionalType > fundingNotionalTypes_
Definition: trswrapper.hpp:123
std::vector< QuantLib::Date > paymentSchedule_
Definition: trswrapper.hpp:121
std::vector< QuantLib::ext::shared_ptr< QuantLib::Index > > underlyingIndex_
Definition: trswrapper.hpp:114
std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > addFxIndices_
Definition: trswrapper.hpp:132
std::vector< QuantLib::Date > valuationSchedule_
Definition: trswrapper.hpp:121
QuantLib::Currency returnCurrency_
Definition: trswrapper.hpp:120
std::vector< QuantLib::Real > underlyingMultiplier_
Definition: trswrapper.hpp:115
std::vector< QuantLib::Leg > fundingLegs_
Definition: trswrapper.hpp:122
std::vector< QuantLib::ext::shared_ptr< ore::data::Trade > > underlying_
Definition: trswrapper.hpp:113
QuantLib::Currency fundingCurrency_
Definition: trswrapper.hpp:124
std::vector< QuantLib::Currency > assetCurrency_
Definition: trswrapper.hpp:119
QuantLib::Size fundingResetGracePeriod_
Definition: trswrapper.hpp:125
QuantLib::Currency initialPriceCurrency_
Definition: trswrapper.hpp:118
QuantLib::ext::shared_ptr< QuantExt::FxIndex > fxIndexReturn_
Definition: trswrapper.hpp:131
QuantLib::ext::shared_ptr< QuantExt::FxIndex > fxIndexAdditionalCashflows_
Definition: trswrapper.hpp:131
QuantLib::Currency additionalCashflowCurrency_
Definition: trswrapper.hpp:129
void validate() const override
Definition: trswrapper.cpp:164
std::vector< QuantLib::ext::shared_ptr< QuantExt::FxIndex > > fxIndexAsset_
Definition: trswrapper.hpp:130
QuantLib::Real getFxConversionRate(const QuantLib::Date &date, const QuantLib::Currency &source, const QuantLib::Currency &target, const bool enforceProjection) const
Definition: trswrapper.cpp:293
void calculate() const override
Definition: trswrapper.cpp:377
QuantLib::Real currentNotional() const
bool computeStartValue(std::vector< QuantLib::Real > &underlyingStartValue, std::vector< QuantLib::Real > &fxConversionFactor, QuantLib::Date &startDate, QuantLib::Date &endDate, bool &usingInitialPrice, const Size nth) const
Definition: trswrapper.cpp:174
Real getUnderlyingFixing(const Size i, const QuantLib::Date &date, const bool enforceProjection) const
Definition: trswrapper.cpp:358
TRS Instrument Wrapper.
Definition: trswrapper.hpp:35
const QuantLib::Currency additionalCashflowCurrency_
Definition: trswrapper.hpp:102
void fetchResults(const QuantLib::PricingEngine::results *) const override
Definition: trswrapper.cpp:172
std::vector< TRS::FundingData::NotionalType > fundingNotionalTypes_
Definition: trswrapper.hpp:96
std::vector< QuantLib::Date > paymentSchedule_
Definition: trswrapper.hpp:94
std::vector< QuantLib::ext::shared_ptr< QuantLib::Index > > underlyingIndex_
Definition: trswrapper.hpp:87
const QuantLib::Currency fundingCurrency_
Definition: trswrapper.hpp:97
const QuantLib::Currency returnCurrency_
Definition: trswrapper.hpp:93
std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > addFxIndices_
Definition: trswrapper.hpp:105
std::vector< QuantLib::Date > valuationSchedule_
Definition: trswrapper.hpp:94
bool isExpired() const override
Definition: trswrapper.cpp:134
const QuantLib::Currency initialPriceCurrency_
Definition: trswrapper.hpp:91
QuantLib::Real initialPrice_
Definition: trswrapper.hpp:90
std::vector< QuantLib::Real > underlyingMultiplier_
Definition: trswrapper.hpp:88
std::vector< QuantLib::Leg > fundingLegs_
Definition: trswrapper.hpp:95
std::vector< QuantLib::ext::shared_ptr< ore::data::Trade > > underlying_
Definition: trswrapper.hpp:86
const QuantLib::Size fundingResetGracePeriod_
Definition: trswrapper.hpp:98
QuantLib::ext::shared_ptr< QuantExt::FxIndex > fxIndexReturn_
Definition: trswrapper.hpp:104
QuantLib::ext::shared_ptr< QuantExt::FxIndex > fxIndexAdditionalCashflows_
Definition: trswrapper.hpp:104
QuantLib::Leg additionalCashflowLeg_
Definition: trswrapper.hpp:100
bool includeUnderlyingCashflowsInReturn_
Definition: trswrapper.hpp:89
void setupArguments(QuantLib::PricingEngine::arguments *) const override
Definition: trswrapper.cpp:136
std::vector< QuantLib::ext::shared_ptr< QuantExt::FxIndex > > fxIndexAsset_
Definition: trswrapper.hpp:103
const std::vector< QuantLib::Currency > assetCurrency_
Definition: trswrapper.hpp:92
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
base trade data model and serialization