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

Composite Trade class. More...

#include <ored/portfolio/compositetrade.hpp>

+ Inheritance diagram for CompositeTrade:
+ Collaboration diagram for CompositeTrade:

Public Types

enum class  NotionalCalculation {
  Sum , Mean , First , Last ,
  Min , Max , Override
}
 This enum decalres how the notional of the CompositeTrade should be calculated. More...
 

Public Member Functions

 CompositeTrade (const Envelope &env=Envelope(), const TradeActions &ta=TradeActions())
 Constructor requires a trade factory so that subtrades can be built. More...
 
 CompositeTrade (const string currency, const vector< QuantLib::ext::shared_ptr< Trade > > &trades, const string notionalCalculation="", const Real notionalOverride=0.0, const Envelope &env=Envelope(), const TradeActions &ta=TradeActions())
 Fully-specified Constructor. More...
 
virtual void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Build QuantLib/QuantExt instrument, link pricing engine. More...
 
QuantLib::Real notional () const override
 Return the current notional in npvCurrency. See individual sub-classes for the precise definition. More...
 
Inspectors
const string & currency () const
 
const string & portfolioId () const
 
const boolportfolioBasket () const
 
const string & notionalCalculation () const
 
const vector< QuantLib::ext::shared_ptr< Trade > > & trades () const
 
Utility functions
Size size () const
 returns the number of subtrades in the strategy More...
 
Real calculateNotional (const vector< Real > &tradeNotionals) const
 calculates the CompositeTrade notional, when supplied with the notionals of the subtrades More...
 
Serialisation
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 
- Public Member Functions inherited from Trade
 Trade ()
 Default constructor. More...
 
 Trade (const string &tradeType, const Envelope &env=Envelope(), const TradeActions &ta=TradeActions())
 Base class constructor. More...
 
virtual ~Trade ()
 Default destructor. More...
 
virtual void build (const QuantLib::ext::shared_ptr< EngineFactory > &)=0
 
virtual std::map< std::string, RequiredFixings::FixingDatesfixings (const QuantLib::Date &settlementDate=QuantLib::Date()) const
 
const RequiredFixingsrequiredFixings () const
 
virtual std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const
 
void reset ()
 Reset trade, clear all base class data. This does not reset accumulated timings for this trade. More...
 
void resetPricingStats (const std::size_t numberOfPricings=0, const boost::timer::nanosecond_type cumulativePricingTime=0)
 Reset accumulated timings to given values. More...
 
string & id ()
 Set the trade id. More...
 
void setEnvelope (const Envelope &envelope)
 Set the envelope with counterparty and portfolio info. More...
 
void setAdditionalData (const std::map< std::string, boost::any > &additionalData)
 
TradeActionstradeActions ()
 Set the trade actions. More...
 
const string & id () const
 
const string & tradeType () const
 
const Envelopeenvelope () const
 
const set< string > & portfolioIds () const
 
const TradeActionstradeActions () const
 
const QuantLib::ext::shared_ptr< InstrumentWrapper > & instrument () const
 
const std::vector< QuantLib::Leg > & legs () const
 
const std::vector< string > & legCurrencies () const
 
const std::vector< bool > & legPayers () const
 
const string & npvCurrency () const
 
virtual string notionalCurrency () const
 
const Date & maturity () const
 
virtual bool isExpired (const Date &d)
 
const string & issuer () const
 
template<typename T >
additionalDatum (const std::string &tag) const
 returns any additional datum. More...
 
const std::string & sensitivityTemplate () const
 
void validate () const
 Utility to validate that everything that needs to be set in this base class is actually set. More...
 
virtual bool hasCashflows () const
 
boost::timer::nanosecond_type getCumulativePricingTime () const
 Get cumulative timing spent on pricing. More...
 
std::size_t getNumberOfPricings () const
 Get number of pricings. More...
 
- 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...
 

trade overrides

string currency_
 
Real notionalOverride_
 
string notionalCalculation_
 
vector< QuantLib::ext::shared_ptr< Trade > > trades_
 
vector< Handle< Quote > > fxRates_
 
vector< Handle< Quote > > fxRatesNotional_
 
string portfolioId_
 
bool portfolioBasket_
 
std::map< std::string, RequiredFixings::FixingDatesfixings (const QuantLib::Date &settlementDate) const override
 
std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager) const override
 
const std::map< std::string, boost::any > & additionalData () const override
 returns all additional data returned by the trade once built More...
 
void populateFromReferenceData (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager)
 
void getTradesFromReferenceData (const QuantLib::ext::shared_ptr< PortfolioBasketReferenceDatum > &ptfReferenceDatum)
 

Additional Inherited Members

- Protected Member Functions inherited from Trade
Date addPremiums (std::vector< QuantLib::ext::shared_ptr< Instrument > > &instruments, std::vector< Real > &multipliers, const Real tradeMultiplier, const PremiumData &premiumData, const Real premiumMultiplier, const Currency &tradeCurrency, const QuantLib::ext::shared_ptr< EngineFactory > &factory, const string &configuration)
 
void setLegBasedAdditionalData (const Size legNo, Size resultLegId=Null< Size >()) const
 
void setSensitivityTemplate (const EngineBuilder &builder)
 
void setSensitivityTemplate (const std::string &id)
 
- Protected Attributes inherited from Trade
string tradeType_
 
QuantLib::ext::shared_ptr< InstrumentWrapperinstrument_
 
std::vector< QuantLib::Leg > legs_
 
std::vector< string > legCurrencies_
 
std::vector< boollegPayers_
 
string npvCurrency_
 
QuantLib::Real notional_
 
string notionalCurrency_
 
Date maturity_
 
string issuer_
 
string sensitivityTemplate_
 
bool sensitivityTemplateSet_ = false
 
std::size_t savedNumberOfPricings_ = 0
 
boost::timer::nanosecond_type savedCumulativePricingTime_ = 0
 
RequiredFixings requiredFixings_
 
std::map< std::string, boost::any > additionalData_
 

Detailed Description

Composite Trade class.

CompositeTrades are single currency strategies consisting of independent financial instruments but regarded as a single position n the portfolio. Examples include straddles, butterflies, iron condors. The class can also be used to create representations of single contracts which can be replicated by linear combinations of other positions. E.g. Bond

Definition at line 41 of file compositetrade.hpp.

Member Enumeration Documentation

◆ NotionalCalculation

enum class NotionalCalculation
strong

This enum decalres how the notional of the CompositeTrade should be calculated.

Enumerator
Sum 

The notional is calculated as the sum of notionals of subtrades.

Mean 

The notional is calculated as the average of notionals of subtrades.

First 

The notional is taken as the first subtrade notional.

Last 

The notional is taken as the last subtrade notional.

Min 

The notional is taken as the minimum subtrade notional.

Max 

The notional is taken as the maximum subtrade notional.

Override 

The notional is explicitly overridden.

Definition at line 44 of file compositetrade.hpp.

44 {
45 Sum, ///< The notional is calculated as the sum of notionals of subtrades
46 Mean, ///< The notional is calculated as the average of notionals of subtrades
47 First, ///< The notional is taken as the first subtrade notional
48 Last, ///< The notional is taken as the last subtrade notional
49 Min, ///< The notional is taken as the minimum subtrade notional
50 Max, ///< The notional is taken as the maximum subtrade notional
51 Override ///< The notional is explicitly overridden
52 };
@ Mean
The notional is calculated as the average of notionals of subtrades.
@ Max
The notional is taken as the maximum subtrade notional.
@ Override
The notional is explicitly overridden.
@ Min
The notional is taken as the minimum subtrade notional.
@ First
The notional is taken as the first subtrade notional.
@ Sum
The notional is calculated as the sum of notionals of subtrades.
@ Last
The notional is taken as the last subtrade notional.

Constructor & Destructor Documentation

◆ CompositeTrade() [1/2]

CompositeTrade ( const Envelope env = Envelope(),
const TradeActions ta = TradeActions() 
)

Constructor requires a trade factory so that subtrades can be built.

Definition at line 55 of file compositetrade.hpp.

56 : Trade("CompositeTrade", env, ta) {
57 reset();
58 }
void reset()
Reset trade, clear all base class data. This does not reset accumulated timings for this trade.
Definition: trade.cpp:130
Trade()
Default constructor.
Definition: trade.hpp:59
+ Here is the call graph for this function:

◆ CompositeTrade() [2/2]

CompositeTrade ( const string  currency,
const vector< QuantLib::ext::shared_ptr< Trade > > &  trades,
const string  notionalCalculation = "",
const Real  notionalOverride = 0.0,
const Envelope env = Envelope(),
const TradeActions ta = TradeActions() 
)

Fully-specified Constructor.

Definition at line 61 of file compositetrade.hpp.

64 : Trade("CompositeTrade", env, ta), currency_(currency), notionalOverride_(notionalOverride),
const string & currency() const
const vector< QuantLib::ext::shared_ptr< Trade > > & trades() const
vector< QuantLib::ext::shared_ptr< Trade > > trades_
const string & notionalCalculation() const

Member Function Documentation

◆ build()

void build ( const QuantLib::ext::shared_ptr< EngineFactory > &  engineFactory)
overridevirtual

Build QuantLib/QuantExt instrument, link pricing engine.

Implements Trade.

Definition at line 33 of file compositetrade.cpp.

33 {
34 DLOG("Building Composite Trade: " << id());
36 QuantLib::ext::shared_ptr<MultiCcyCompositeInstrument> compositeInstrument =
37 QuantLib::ext::make_shared<MultiCcyCompositeInstrument>();
38 fxRates_.clear();
39 fxRatesNotional_.clear();
40 legs_.clear();
41
42 populateFromReferenceData(engineFactory->referenceData());
43
44
45 for (const QuantLib::ext::shared_ptr<Trade>& trade : trades_) {
46
47 trade->reset();
48 trade->build(engineFactory);
49 trade->validate();
50
51 if (sensitivityTemplate_.empty())
52 setSensitivityTemplate(trade->sensitivityTemplate());
53
54 Handle<Quote> fx = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.0));
55 if (trade->npvCurrency() != npvCurrency_)
56 fx = engineFactory->market()->fxRate(trade->npvCurrency() + npvCurrency_);
57 fxRates_.push_back(fx);
58
59 Handle<Quote> fxNotional = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.0));
60 if (trade->notionalCurrency().empty()) {
61 // trade is not guaranteed to provide a non-null notional, but if it does we require a notional currency
62 if (trade->notional() != Null<Real>()) {
63 StructuredTradeErrorMessage(
64 trade, "Error building composite trade '" + id() + "'",
65 "Component trade '" + trade->id() + "' does not provide notional currency for notional " +
66 std::to_string(trade->notional()) + ". Assuming " + npvCurrency_ + ".")
67 .log();
68 }
69 } else if (trade->notionalCurrency() != npvCurrency_)
70 fxNotional = engineFactory->market()->fxRate(trade->notionalCurrency() + npvCurrency_);
71 fxRatesNotional_.push_back(fxNotional);
72
73 QuantLib::ext::shared_ptr<InstrumentWrapper> instrumentWrapper = trade->instrument();
74 Real effectiveMultiplier = instrumentWrapper->multiplier();
75 if (auto optionWrapper = QuantLib::ext::dynamic_pointer_cast<ore::data::OptionWrapper>(instrumentWrapper)) {
76 effectiveMultiplier *= optionWrapper->isLong() ? 1.0 : -1.0;
77 }
78
79 compositeInstrument->add(instrumentWrapper->qlInstrument(), effectiveMultiplier, fx);
80 for (Size i = 0; i < instrumentWrapper->additionalInstruments().size(); ++i) {
81 compositeInstrument->add(instrumentWrapper->additionalInstruments()[i],
82 instrumentWrapper->additionalMultipliers()[i]);
83 }
84
85 bool isDuplicate = false;
86 try {
87 if (instrumentWrapper->additionalResults().find("cashFlowResults") != trade->instrument()->additionalResults().end())
88 isDuplicate = true;
89 } catch (...) {}
90 if (!isDuplicate) {
91 // For cashflows
92 legs_.insert(legs_.end(), trade->legs().begin(), trade->legs().end());
93 legPayers_.insert(legPayers_.end(), trade->legPayers().begin(), trade->legPayers().end());
94 legCurrencies_.insert(legCurrencies_.end(), trade->legCurrencies().begin(), trade->legCurrencies().end());
95 }
96
97 maturity_ = std::max(maturity_, trade->maturity());
98 }
99 instrument_ = QuantLib::ext::shared_ptr<InstrumentWrapper>(new VanillaInstrument(compositeInstrument));
100
102
103 // set required fixings
104 for (auto const& t : trades_)
105 requiredFixings_.addData(t->requiredFixings());
106}
vector< Handle< Quote > > fxRatesNotional_
vector< Handle< Quote > > fxRates_
void populateFromReferenceData(const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager)
Size size() const
returns the number of subtrades in the strategy
void addData(const RequiredFixings &requiredFixings)
string npvCurrency_
Definition: trade.hpp:201
std::vector< bool > legPayers_
Definition: trade.hpp:200
string sensitivityTemplate_
Definition: trade.hpp:206
std::vector< string > legCurrencies_
Definition: trade.hpp:199
std::vector< QuantLib::Leg > legs_
Definition: trade.hpp:198
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
RequiredFixings requiredFixings_
Definition: trade.hpp:223
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
string notionalCurrency_
Definition: trade.hpp:203
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
+ Here is the call graph for this function:

◆ notional()

QuantLib::Real notional ( ) const
overridevirtual

Return the current notional in npvCurrency. See individual sub-classes for the precise definition.

Reimplemented from Trade.

Definition at line 108 of file compositetrade.cpp.

108 {
109 vector<Real> notionals;
110 vector<Handle<Quote>> fxRates;
111 // trade is not guaranteed to provide a non-null notional
112 for (const QuantLib::ext::shared_ptr<Trade>& trade : trades_)
113 notionals.push_back(trade->notional() != Null<Real>() ? trade->notional() : 0.0);
114
115 // need to convert the component notionals to the composite currency.
116 auto notionalConverter = [](const Real ntnl, const Handle<Quote>& fx) { return (ntnl * fx->value()); };
117 std::transform(begin(notionals), end(notionals), begin(fxRates_), begin(notionals), notionalConverter);
118 return calculateNotional(notionals);
119}
Real calculateNotional(const vector< Real > &tradeNotionals) const
calculates the CompositeTrade notional, when supplied with the notionals of the subtrades
+ Here is the call graph for this function:

◆ currency()

const string & currency ( ) const

Definition at line 73 of file compositetrade.hpp.

73{ return currency_; }
+ Here is the caller graph for this function:

◆ portfolioId()

const string & portfolioId ( ) const

Definition at line 74 of file compositetrade.hpp.

◆ portfolioBasket()

const bool & portfolioBasket ( ) const

Definition at line 75 of file compositetrade.hpp.

◆ notionalCalculation()

const string & notionalCalculation ( ) const

Definition at line 76 of file compositetrade.hpp.

76{ return notionalCalculation_; }
+ Here is the caller graph for this function:

◆ trades()

const vector< QuantLib::ext::shared_ptr< Trade > > & trades ( ) const

Definition at line 77 of file compositetrade.hpp.

77{ return trades_; }
+ Here is the caller graph for this function:

◆ size()

Size size ( ) const

returns the number of subtrades in the strategy

Definition at line 83 of file compositetrade.hpp.

83{ return trades_.size(); }
+ Here is the caller graph for this function:

◆ calculateNotional()

Real calculateNotional ( const vector< Real > &  tradeNotionals) const

calculates the CompositeTrade notional, when supplied with the notionals of the subtrades

Definition at line 218 of file compositetrade.cpp.

218 {
219 if (notionalCalculation_ == "Sum" || notionalCalculation_ == "")
220 return std::accumulate(notionals.begin(), notionals.end(), 0.0);
221 else if (notionalCalculation_ == "Mean" || notionalCalculation_ == "Average")
222 return std::accumulate(notionals.begin(), notionals.end(), 0.0) / notionals.size();
223 else if (notionalCalculation_ == "First")
224 return notionals[0];
225 else if (notionalCalculation_ == "Last")
226 return notionals.back();
227 else if (notionalCalculation_ == "Min")
228 return *std::min_element(notionals.begin(), notionals.end());
229 else if (notionalCalculation_ == "Max")
230 return *std::min_element(notionals.begin(), notionals.end());
231 else if (notionalCalculation_ == "Override")
232 return notionalOverride_;
233 else
234 QL_FAIL("Unsupported notional calculation type.");
235}
+ Here is the caller graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 121 of file compositetrade.cpp.

121 {
122 QL_REQUIRE("CompositeTrade" == XMLUtils::getChildValue(node, "TradeType", true),
123 "Wrong trade type in composite trade builder.");
124 Trade::fromXML(node);
125 this->id() = XMLUtils::getAttribute(node, "id");
126 // We read the data particular to composite trades
127 XMLNode* compNode = XMLUtils::getChildNode(node, "CompositeTradeData");
128 QL_REQUIRE(compNode, "Could not find CompositeTradeData node.");
129 currency_ = XMLUtils::getChildValue(compNode, "Currency", true);
130 // The notional logic is as follows:
131 // If the notional override is specified then it is used, regardless of the "NotionalCalculation" field
132 // Otherwise we calculate the notional as per the calculation specified
133 if (XMLUtils::getChildNode(compNode, "NotionalOverride") != nullptr) {
134 notionalOverride_ = XMLUtils::getChildValueAsDouble(compNode, "NotionalOverride");
135 QL_REQUIRE(notionalOverride_ >= 0, "Non-negative notional expected.");
136 DLOG("Using override notional of " << notionalOverride_);
137 notionalCalculation_ = "Override";
138 } else {
139 // Convert everything to proper case to match xml schema
140 notionalCalculation_ = boost::to_lower_copy(XMLUtils::getChildValue(compNode, "NotionalCalculation"));
142 QL_REQUIRE(notionalCalculation_ != "Override", "Notional override value has not been provided.");
143 }
144
145 if (XMLUtils::getChildNode(compNode, "PortfolioBasket")) {
146 portfolioBasket_ = XMLUtils::getChildValueAsBool(node, "PortfolioBasket", false);
147 } else {
148 portfolioBasket_ = false;
149 }
150
151 portfolioId_ = XMLUtils::getChildValue(compNode, "BasketName", false);
152
153 XMLNode* tradesNode = XMLUtils::getChildNode(compNode, "Components");
154 if (portfolioBasket_ && portfolioId_.empty()) {
155 QL_REQUIRE(tradesNode, "Required a Portfolio Id or a Components Node.");
156 }
157 if ((portfolioBasket_ && portfolioId_.empty()) || (!portfolioBasket_)) {
158
159 vector<XMLNode*> nodes = XMLUtils::getChildrenNodes(tradesNode, "Trade");
160 for (Size i = 0; i < nodes.size(); i++) {
161 string tradeType = XMLUtils::getChildValue(nodes[i], "TradeType", true);
162 string id = XMLUtils::getAttribute(nodes[i], "id");
163 if (id == "") {
164 WLOG("Empty component trade id being overwritten in composite trade " << this->id() << ".");
165 }
166 id = this->id() + "_" + std::to_string(i);
167 DLOG("Parsing composite trade " << this->id() << " node " << i << " with id: " << id);
168
169 QuantLib::ext::shared_ptr<Trade> trade;
170 try {
171 trade = TradeFactory::instance().build(tradeType);
172 trade->id() = id;
173 Envelope componentEnvelope;
174 if (XMLNode* envNode = XMLUtils::getChildNode(nodes[i], "Envelope")) {
175 componentEnvelope.fromXML(envNode);
176 }
177 Envelope env = this->envelope();
178 // the component trade's envelope is the main trade's envelope with possibly overwritten add fields
179 for (auto const& [k, v] : componentEnvelope.fullAdditionalFields()) {
180 env.setAdditionalField(k,v);
181 }
182
183 trade->setEnvelope(env);
184 trade->fromXML(nodes[i]);
185 trades_.push_back(trade);
186 DLOG("Added Trade " << id << " (" << trade->id() << ")"
187 << " type:" << tradeType << " to composite trade " << this->id() << ".");
188 } catch (const std::exception& e) {
189 StructuredTradeErrorMessage(
190 id, this->tradeType(),
191 "Failed to build subtrade with id '" + id + "' inside composite trade: ", e.what())
192 .log();
193 }
194 }
195 LOG("Finished Parsing XML doc");
196 }
197}
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
string & id()
Set the trade id.
Definition: trade.hpp:118
const Envelope & envelope() const
Definition: trade.hpp:135
const string & tradeType() const
Definition: trade.hpp:133
static string getAttribute(XMLNode *node, const string &attrName)
Definition: xmlutils.cpp:419
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
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
#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
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Reimplemented from Trade.

Definition at line 199 of file compositetrade.cpp.

199 {
200 XMLNode* node = Trade::toXML(doc);
201 XMLNode* compNode = doc.allocNode("CompositeTradeData");
202 XMLUtils::appendNode(node, compNode);
203
204 XMLUtils::addChild(doc, compNode, "Currency", currency_);
205 if (notionalCalculation_ == "Override")
206 XMLUtils::addChild(doc, compNode, "NotionalOverride", notionalOverride_);
207 XMLUtils::addChild(doc, compNode, "NotionalCalculation", notionalCalculation_);
208
209 XMLNode* tradesNode = doc.allocNode("Components");
210 XMLUtils::appendNode(compNode, tradesNode);
211 for (auto trade : trades_) {
212 XMLNode* subTradeNode = trade->toXML(doc);
213 XMLUtils::appendNode(tradesNode, subTradeNode);
214 }
215 return node;
216}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
+ Here is the call graph for this function:

◆ fixings()

map< string, RequiredFixings::FixingDates > fixings ( const QuantLib::Date &  settlementDate) const
overridevirtual

Return the fixings that will be requested in order to price this Trade given the settlementDate.

If the settlementDate is not provided, the current evaluation date is taken as the settlement date. If a Trade does not have any fixings, this method will return an empty map. The map key is the ORE name of the index and the map value is the set of fixing dates.

Warning:
This method will return an empty map if the Trade has not been built.

Reimplemented from Trade.

Definition at line 237 of file compositetrade.cpp.

237 {
238
239 map<string, RequiredFixings::FixingDates> result;
240 for (const auto& t : trades_) {
241 auto fixings = t->fixings(settlementDate);
242 for (const auto& [indexName, fixingDates] : fixings) {
243 result[indexName].addDates(fixingDates);
244 }
245 }
246 return result;
247}
std::map< std::string, RequiredFixings::FixingDates > fixings(const QuantLib::Date &settlementDate) const override
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ underlyingIndices()

std::map< AssetClass, std::set< std::string > > underlyingIndices ( const QuantLib::ext::shared_ptr< ReferenceDataManager > &  referenceDataManager) const
overridevirtual

Reimplemented from Trade.

Definition at line 250 of file compositetrade.cpp.

250 {
251
252 map<AssetClass, std::set<std::string>> result;
253 for (const auto& t : trades_) {
254 auto underlyings = t->underlyingIndices(referenceDataManager);
255 for (const auto& kv : underlyings) {
256 result[kv.first].insert(kv.second.begin(), kv.second.end());
257 }
258 }
259 return result;
260}

◆ additionalData()

const std::map< std::string, boost::any > & additionalData ( ) const
overridevirtual

returns all additional data returned by the trade once built

Reimplemented from Trade.

Definition at line 262 of file compositetrade.cpp.

262 {
263 additionalData_.clear();
264 Size counter = 0;
265 for (auto const& t : trades_) {
266 for (auto const& d : t->additionalData()) {
267 additionalData_[d.first + "_" + std::to_string(counter)] = d.second;
268 }
269 ++counter;
270 }
271 return additionalData_;
272}
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224

◆ populateFromReferenceData()

void populateFromReferenceData ( const QuantLib::ext::shared_ptr< ReferenceDataManager > &  referenceDataManager)
private

Definition at line 274 of file compositetrade.cpp.

274 {
275
276 if (!portfolioId_.empty() && referenceData != nullptr &&
277 (referenceData->hasData(PortfolioBasketReferenceDatum::TYPE, portfolioId_))) {
278 auto ptfRefData = QuantLib::ext::dynamic_pointer_cast<PortfolioBasketReferenceDatum>(
279 referenceData->getData(PortfolioBasketReferenceDatum::TYPE, portfolioId_));
280 QL_REQUIRE(ptfRefData, "could not cast to PortfolioBasketReferenceDatum, this is unexpected");
281 getTradesFromReferenceData(ptfRefData);
282 } else {
283 DLOG("Could not get PortfolioBasketReferenceDatum for Id " << portfolioId_ << " leave data in trade unchanged");
284 }
285
286}
void getTradesFromReferenceData(const QuantLib::ext::shared_ptr< PortfolioBasketReferenceDatum > &ptfReferenceDatum)
static constexpr const char * TYPE
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTradesFromReferenceData()

void getTradesFromReferenceData ( const QuantLib::ext::shared_ptr< PortfolioBasketReferenceDatum > &  ptfReferenceDatum)
private

Definition at line 288 of file compositetrade.cpp.

289 {
290
291 DLOG("populating portfolio basket data from reference data");
292 QL_REQUIRE(ptfReferenceDatum, "populateFromReferenceData(): empty cbo reference datum given");
293
294 auto refData = ptfReferenceDatum->getTrades();
295 trades_.clear();
296 for (Size i = 0; i < refData.size(); i++) {
297 trades_.push_back(refData[i]);
298 }
299 LOG("Finished Parsing XML doc");
300
301}
+ Here is the caller graph for this function:

Member Data Documentation

◆ currency_

string currency_
private

Definition at line 107 of file compositetrade.hpp.

◆ notionalOverride_

Real notionalOverride_
private

Definition at line 108 of file compositetrade.hpp.

◆ notionalCalculation_

string notionalCalculation_
private

Definition at line 109 of file compositetrade.hpp.

◆ trades_

vector<QuantLib::ext::shared_ptr<Trade> > trades_
private

Definition at line 110 of file compositetrade.hpp.

◆ fxRates_

vector<Handle<Quote> > fxRates_
private

Definition at line 111 of file compositetrade.hpp.

◆ fxRatesNotional_

vector<Handle<Quote> > fxRatesNotional_
private

Definition at line 111 of file compositetrade.hpp.

◆ portfolioId_

string portfolioId_
private

Definition at line 112 of file compositetrade.hpp.

◆ portfolioBasket_

bool portfolioBasket_
private

Definition at line 113 of file compositetrade.hpp.