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

#include <ored/portfolio/commodityswap.hpp>

+ Inheritance diagram for CommoditySwap:
+ Collaboration diagram for CommoditySwap:

Public Member Functions

 CommoditySwap ()
 
 CommoditySwap (const ore::data::Envelope &env, const std::vector< ore::data::LegData > &legs)
 
void build (const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &) override
 
QuantLib::Real notional () const override
 Return the current notional in npvCurrency. See individual sub-classes for the precise definition. More...
 
std::map< ore::data::AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ore::data::ReferenceDataManager > &referenceDataManager=nullptr) const override
 Add underlying Commodity names. More...
 
Inspectors
const std::vector< ore::data::LegData > & legData () const
 
- 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...
 

Serialisation

std::vector< ore::data::LegDatalegData_
 
virtual void fromXML (ore::data::XMLNode *node) override
 
virtual ore::data::XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
const std::map< std::string, boost::any > & additionalData () const override
 returns all additional data returned by the trade once built More...
 
QuantLib::ext::shared_ptr< ore::data::LegDatacreateLegData () const
 
void check () const
 
void buildLeg (const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &ef, const ore::data::LegData &legDatum, const std::string &configuration)
 

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

Serializable Commodity Swap

Definition at line 38 of file commodityswap.hpp.

Constructor & Destructor Documentation

◆ CommoditySwap() [1/2]

Definition at line 40 of file commodityswap.hpp.

40: ore::data::Trade("CommoditySwap") {}
Trade base class.
Definition: trade.hpp:55

◆ CommoditySwap() [2/2]

CommoditySwap ( const ore::data::Envelope env,
const std::vector< ore::data::LegData > &  legs 
)

Definition at line 42 of file commodityswap.hpp.

43 : Trade("CommoditySwap", env), legData_(legs) {}
std::vector< ore::data::LegData > legData_
const std::vector< QuantLib::Leg > & legs() const
Definition: trade.hpp:143
Trade()
Default constructor.
Definition: trade.hpp:59

Member Function Documentation

◆ build()

void build ( const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &  )
override

Definition at line 43 of file commodityswap.cpp.

43 {
44
45 reset();
46
47 LOG("CommoditySwap::build() called for trade " << id());
48
49 // ISDA taxonomy, assuming Commodity follows the Equity template
50 additionalData_["isdaAssetClass"] = string("Commodity");
51 additionalData_["isdaBaseProduct"] = string("Swap");
52 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
53 // skip the transaction level mapping for now
54 additionalData_["isdaTransaction"] = string("");
55
56 check();
57
58 // Arbitrarily choose NPV currency from 1st leg. Already checked that both leg currencies equal.
59 npvCurrency_ = legData_[0].currency();
60
61 // Set notional to N/A for now, but reset this for a commodity fixed respectively floating leg below.
62 notional_ = Null<Real>();
63 notionalCurrency_ = legData_[0].currency();
64
65 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
66 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder("CommoditySwap");
67 QuantLib::ext::shared_ptr<CommoditySwapEngineBuilder> engineBuilder =
68 QuantLib::ext::dynamic_pointer_cast<CommoditySwapEngineBuilder>(builder);
69 const string& configuration = builder->configuration(MarketContext::pricing);
70
71 // Build the commodity swap legs
72
73 // Build the floating legs first in case we need the quantities to build the fixed legs.
74 // Store the floating legs in the map with their "Tag" as key. This allows the fixed leg to find the floating leg
75 // with the matching "Tag" when retrieving the quantities if it needs them. Note the if all the tags are empty,
76 // the map entry gets overwritten and the fixed leg with empty tag matches a random floating leg with empty tag.
77 // This is by design i.e. use tags if you want to link specific legs.
78 map<string, Leg> floatingLegs;
79 vector<Size> legsIdx;
80 for (Size t = 0; t < legData_.size(); t++) {
81 const auto& legDatum = legData_.at(t);
82
83 const string& type = legDatum.legType();
84 if (type == "CommodityFixed")
85 continue;
86
87 // Build the leg and add it to legs_
88 buildLeg(engineFactory, legDatum, configuration);
89 legsIdx.push_back(t);
90
91 // Only add to map if CommodityFloatingLegData
92 if (auto cfld = QuantLib::ext::dynamic_pointer_cast<CommodityFloatingLegData>(legDatum.concreteLegData())) {
93 floatingLegs[cfld->tag()] = legs_.back();
94 }
95 }
96
97 // Build any fixed legs skipped above.
98 for (Size t = 0; t < legData_.size(); t++) {
99 const auto& legDatum = legData_.at(t);
100
101 // take a copy, since we might modify the leg datum below
102 auto effLegDatum = legDatum;
103
104 const string& type = effLegDatum.legType();
105 if (type != "CommodityFixed")
106 continue;
107
108 // Update the commodity fixed leg quantities if necessary.
109 auto cfld = QuantLib::ext::dynamic_pointer_cast<CommodityFixedLegData>(effLegDatum.concreteLegData());
110 QL_REQUIRE(cfld, "CommodityFixed leg should have valid CommodityFixedLegData");
111 if (cfld->quantities().empty()) {
112
113 auto it = floatingLegs.find(cfld->tag());
114 QL_REQUIRE(it != floatingLegs.end(), "Did not find a commodity floating leg corresponding to the" <<
115 " fixed leg with tag '" << cfld->tag() << "' from which to take the quantities.");
116
117 const Leg& leg = it->second;
118 vector<Real> quantities;
119 quantities.reserve(leg.size());
120 for (const auto& cf : leg) {
121 // If more options arise here, may think of visitor to get the commodity notional.
122 auto ucf = unpackIndexWrappedCashFlow(cf);
123 if (auto cicf = QuantLib::ext::dynamic_pointer_cast<CommodityIndexedCashFlow>(ucf)) {
124 quantities.push_back(cicf->periodQuantity());
125 } else if (auto ciacf = QuantLib::ext::dynamic_pointer_cast<CommodityIndexedAverageCashFlow>(ucf)) {
126 quantities.push_back(ciacf->periodQuantity());
127 } else {
128 QL_FAIL("Expected a commodity indexed cashflow while building commodity fixed" <<
129 " leg quantities for trade " << id() << ".");
130 }
131 }
132
133 cfld->setQuantities(quantities);
134 }
135 // overwrite payment dates if pay relative to future expiry of floating leg is specified
136 if (effLegDatum.paymentDates().empty() &&
137 cfld->commodityPayRelativeTo() == CommodityPayRelativeTo::FutureExpiryDate) {
138 auto it = floatingLegs.find(cfld->tag());
139 QL_REQUIRE(it != floatingLegs.end(),
140 "Did not find a commodity floating leg correpsonding to the fixed leg with tag '"
141 << cfld->tag() << "' from which to take the payment dates.");
142 vector<string> tmp;
143 for(auto const& cf: it->second) {
144 tmp.push_back(ore::data::to_string(cf->date()));
145 }
146 effLegDatum.paymentDates() = tmp;
147 }
148
149 // Build the leg and add it to legs_
150 buildLeg(engineFactory, effLegDatum, configuration);
151 legsIdx.push_back(t);
152 }
153
154 // Reposition the leg-based data to match the original order according to legData_
155 vector<Leg> legsTmp;
156 vector<bool> legPayersTmp;
157 vector<string> legCurrenciesTmp;
158 for (const Size idx : legsIdx) {
159 legsTmp.push_back(legs_.at(idx));
160 legPayersTmp.push_back(legPayers_.at(idx));
161 legCurrenciesTmp.push_back(legCurrencies_.at(idx));
162 }
163 legs_ = legsTmp;
164 legPayers_ = legPayersTmp;
165 legCurrencies_ = legCurrenciesTmp;
166
167 // Create the QuantLib swap instrument and assign pricing engine
168 auto swap = QuantLib::ext::make_shared<QuantLib::Swap>(legs_, legPayers_);
169 QuantLib::ext::shared_ptr<PricingEngine> engine = engineBuilder->engine(parseCurrency(npvCurrency_));
170 swap->setPricingEngine(engine);
171 setSensitivityTemplate(*engineBuilder);
172 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(swap);
173}
void buildLeg(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &ef, const ore::data::LegData &legDatum, const std::string &configuration)
string npvCurrency_
Definition: trade.hpp:201
std::vector< bool > legPayers_
Definition: trade.hpp:200
std::vector< string > legCurrencies_
Definition: trade.hpp:199
std::vector< QuantLib::Leg > legs_
Definition: trade.hpp:198
QuantLib::Real notional_
Definition: trade.hpp:202
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
void reset()
Reset trade, clear all base class data. This does not reset accumulated timings for this trade.
Definition: trade.cpp:130
string notionalCurrency_
Definition: trade.hpp:203
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:290
#define LOG(text)
Logging Macro (Level = Notice)
Definition: log.hpp:552
boost::shared_ptr< CashFlow > unpackIndexWrappedCashFlow(const boost::shared_ptr< CashFlow > &c)
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ 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 290 of file commodityswap.cpp.

290 {
291 Date asof = Settings::instance().evaluationDate();
292 Real currentAmount = Null<Real>();
293 // Get maximum current cash flow amount (quantity * strike, quantity * spot/forward price) across legs
294 // include gearings and spreads; note that the swap is in a single currency.
295 for (Size i = 0; i < legs_.size(); ++i) {
296 for (Size j = 0; j < legs_[i].size(); ++j) {
297 QuantLib::ext::shared_ptr<CashFlow> flow = legs_[i][j];
298 // pick flow with earliest payment date on this leg
299 if (flow->date() > asof) {
300 if (currentAmount == Null<Real>())
301 currentAmount = flow->amount();
302 else // set on a previous leg already, set to maximum
303 currentAmount = std::max(currentAmount, flow->amount());
304 break; // move on to the next leg
305 }
306 }
307 }
308
309 if (currentAmount != Null<Real>()) {
310 return currentAmount;
311 } else {
312 ALOG("Error retrieving current notional for commodity swap " << id() << " as of " << io::iso_date(asof));
313 return Null<Real>();
314 }
315}
#define ALOG(text)
Logging Macro (Level = Alert)
Definition: log.hpp:544

◆ underlyingIndices()

std::map< AssetClass, std::set< std::string > > underlyingIndices ( const QuantLib::ext::shared_ptr< ore::data::ReferenceDataManager > &  referenceDataManager = nullptr) const
override

Add underlying Commodity names.

Definition at line 318 of file commodityswap.cpp.

318 {
319
320 std::map<AssetClass, std::set<std::string>> result;
321
322 for (auto ld : legData_) {
323 set<string> indices = ld.indices();
324 for (auto ind : indices) {
325 QuantLib::ext::shared_ptr<Index> index = parseIndex(ind);
326 // only handle commodity
327 if (auto ci = QuantLib::ext::dynamic_pointer_cast<QuantExt::CommodityIndex>(index)) {
328 result[AssetClass::COM].insert(ci->name());
329 }
330 }
331 }
332 return result;
333}
QuantLib::ext::shared_ptr< Index > parseIndex(const string &s)
Convert std::string to QuantLib::Index.
+ Here is the call graph for this function:

◆ legData()

const std::vector< ore::data::LegData > & legData ( ) const

Definition at line 54 of file commodityswap.hpp.

54{ return legData_; }

◆ fromXML()

void fromXML ( ore::data::XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 335 of file commodityswap.cpp.

335 {
336 DLOG("CommoditySwap::fromXML called");
337 Trade::fromXML(node);
338 legData_.clear();
339
340 XMLNode* swapNode = XMLUtils::getChildNode(node, "SwapData");
341 QL_REQUIRE(swapNode, "No SwapData Node");
342
343 vector<XMLNode*> nodes = XMLUtils::getChildrenNodes(swapNode, "LegData");
344 for (Size i = 0; i < nodes.size(); i++) {
345 auto ld = createLegData();
346 ld->fromXML(nodes[i]);
347 legData_.push_back(*ld);
348 }
349}
QuantLib::ext::shared_ptr< ore::data::LegData > createLegData() const
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( ore::data::XMLDocument doc) const
overridevirtual

Reimplemented from Trade.

Definition at line 351 of file commodityswap.cpp.

351 {
352 XMLNode* node = Trade::toXML(doc);
353 XMLNode* swapNode = doc.allocNode("SwapData");
354 XMLUtils::appendNode(node, swapNode);
355 for (Size i = 0; i < legData_.size(); i++)
356 XMLUtils::appendNode(swapNode, legData_[i].toXML(doc));
357 return node;
358}
virtual ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 175 of file commodityswap.cpp.

175 {
176 Size numLegs = legData_.size();
177 // use the build time as of date to determine current notionals
178 Date asof = Settings::instance().evaluationDate();
179 QuantLib::ext::shared_ptr<QuantLib::Swap> swap = QuantLib::ext::dynamic_pointer_cast<QuantLib::Swap>(instrument_->qlInstrument());
180 for (Size i = 0; i < numLegs; ++i) {
181 string legID = to_string(i+1);
182 additionalData_["legType[" + legID + "]"] = legData_[i].legType();
183 additionalData_["isPayer[" + legID + "]"] = legData_[i].isPayer();
184 additionalData_["currency[" + legID + "]"] = legData_[i].currency();
185 if (swap)
186 additionalData_["legNPV[" + legID + "]"] = swap->legNPV(i);
187 else
188 ALOG("commodity swap underlying instrument not set, skip leg npv reporting");
189 for (Size j = 0; j < legs_[i].size(); ++j) {
190 QuantLib::ext::shared_ptr<CashFlow> flow = legs_[i][j];
191 if (flow->date() > asof) {
192 std::string label = legID + ":" + std::to_string(j + 1);
193 // CommodityFloatingLeg consists of indexed or indexed average cash flows
194 QuantLib::ext::shared_ptr<CommodityIndexedCashFlow> indexedFlow =
195 QuantLib::ext::dynamic_pointer_cast<CommodityIndexedCashFlow>(unpackIndexWrappedCashFlow(flow));
196 if (indexedFlow) {
197 additionalData_["quantity[" + label + "]"] = indexedFlow->quantity();
198 additionalData_["periodQuantity[" + label + "]"] = indexedFlow->periodQuantity();
199 additionalData_["gearing[" + label + "]"] = indexedFlow->gearing();
200 if (indexedFlow->isAveragingFrontMonthCashflow(asof)) {
201 std::vector<Real> priceVec;
202 std::vector<std::string> indexVec;
203 std::vector<Date> indexExpiryVec, pricingDateVec;
204 double averagePrice = 0;
205 for (const auto& pd : indexedFlow->spotAveragingPricingDates()) {
206 if (pd > asof) {
207 auto index = indexedFlow->index();
208 auto pricingDate = indexedFlow->lastPricingDate();
209 indexVec.push_back(index->name());
210 indexExpiryVec.push_back(index->expiryDate());
211 pricingDateVec.push_back(pd);
212 priceVec.push_back(index->fixing(pricingDate));
213 averagePrice += priceVec.back();
214 }
215 else {
216 auto index = indexedFlow->spotIndex();
217 indexVec.push_back(index->name());
218 indexExpiryVec.push_back(index->expiryDate());
219 pricingDateVec.push_back(pd);
220 priceVec.push_back(index->fixing(pd));
221 averagePrice += priceVec.back();
222 }
223 }
224 averagePrice /= indexedFlow->spotAveragingPricingDates().size();
225 additionalData_["index[" + label + "]"] = indexVec;
226 additionalData_["indexExpiry[" + label + "]"] = indexExpiryVec;
227 additionalData_["price[" + label + "]"] = priceVec;
228 additionalData_["averagePrice[" + label + "]"] = averagePrice;
229 additionalData_["pricingDate[" + label + "]"] = pricingDateVec;
230 }
231 else {
232 additionalData_["index[" + label + "]"] = indexedFlow->index()->name();
233 additionalData_["indexExpiry[" + label + "]"] = indexedFlow->index()->expiryDate();
234 additionalData_["price[" + label + "]"] = indexedFlow->index()->fixing(indexedFlow->pricingDate());
235 additionalData_["pricingDate[" + label + "]"] = to_string(indexedFlow->pricingDate());
236 }
237 additionalData_["paymentDate[" + label + "]"] = to_string(indexedFlow->date());
238 }
239 QuantLib::ext::shared_ptr<CommodityIndexedAverageCashFlow> indexedAvgFlow =
240 QuantLib::ext::dynamic_pointer_cast<CommodityIndexedAverageCashFlow>(unpackIndexWrappedCashFlow(flow));
241 if (indexedAvgFlow) {
242 additionalData_["quantity[" + label + "]"] = indexedAvgFlow->quantity();
243 additionalData_["periodQuantity[" + label + "]"] = indexedAvgFlow->periodQuantity();
244 additionalData_["gearing[" + label + "]"] = indexedAvgFlow->gearing();
245 std::vector<Real> priceVec;
246 std::vector<std::string> indexVec;
247 std::vector<Date> indexExpiryVec, pricingDateVec;
248 double averagePrice = 0;
249 for (const auto& kv : indexedAvgFlow->indices()) {
250 indexVec.push_back(kv.second->name());
251 indexExpiryVec.push_back(kv.second->expiryDate());
252 pricingDateVec.push_back(kv.first);
253 priceVec.push_back(kv.second->fixing(kv.first));
254 averagePrice += priceVec.back();
255 }
256 averagePrice /= indexedAvgFlow->indices().size();
257 additionalData_["index[" + label + "]"] = indexVec;
258 additionalData_["indexExpiry[" + label + "]"] = indexExpiryVec;
259 additionalData_["price[" + label + "]"] = priceVec;
260 additionalData_["averagePrice[" + label + "]"] = averagePrice;
261 additionalData_["pricingDate[" + label + "]"] = pricingDateVec;
262 additionalData_["paymentDate[" + label + "]"] = to_string(indexedAvgFlow->date());
263 }
264 // CommodityFixedLeg consists of simple cash flows
265 Real flowAmount = 0.0;
266 try {
267 flowAmount = flow->amount();
268 } catch (std::exception& e) {
269 ALOG("flow amount could not be determined for trade " << id() << ", set to zero: " << e.what());
270 }
271 additionalData_["amount[" + label + "]"] = flowAmount;
272 additionalData_["paymentDate[" + label + "]"] = to_string(flow->date());
273 }
274 }
275 if (legs_[i].size() > 0) {
276 QuantLib::ext::shared_ptr<Coupon> coupon = QuantLib::ext::dynamic_pointer_cast<Coupon>(legs_[i][0]);
277 if (coupon) {
278 Real originalNotional = 0.0;
279 try { originalNotional = coupon->nominal(); }
280 catch(std::exception& e) {
281 ALOG("original nominal could not be determined for trade " << id() << ", set to zero: " << e.what());
282 }
283 additionalData_["originalNotional[" + legID + "]"] = originalNotional;
284 }
285 }
286 }
287 return additionalData_;
288}
Size size(const ValueType &v)
Definition: value.cpp:145
Real originalNotional(const Leg &leg)
Definition: legdata.cpp:2449
+ Here is the call graph for this function:

◆ createLegData()

QuantLib::ext::shared_ptr< ore::data::LegData > createLegData ( ) const
private

Definition at line 66 of file commodityswap.hpp.

66{ return QuantLib::ext::make_shared<ore::data::LegData>(); }
+ Here is the caller graph for this function:

◆ check()

void check ( ) const
private

Definition at line 360 of file commodityswap.cpp.

360 {
361 QL_REQUIRE(legData_.size() >= 2, "Expected at least two commodity legs but found " << legData_.size());
362 auto ccy = legData_[0].currency();
363 for (const auto& legDatum : legData_) {
364 QL_REQUIRE(legDatum.currency() == ccy, "Cross currency commodity swaps are not supported");
365 }
366}
+ Here is the caller graph for this function:

◆ buildLeg()

void buildLeg ( const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &  ef,
const ore::data::LegData legDatum,
const std::string &  configuration 
)
private

Definition at line 368 of file commodityswap.cpp.

369 {
370
371 auto legBuilder = ef->legBuilder(legDatum.legType());
372 Leg leg = legBuilder->buildLeg(legDatum, ef, requiredFixings_, configuration);
373 legs_.push_back(leg);
374 legPayers_.push_back(legDatum.isPayer());
375 legCurrencies_.push_back(legDatum.currency());
376
377 // Update maturity
378 maturity_ = max(CashFlows::maturityDate(leg), maturity_);
379
380}
const string & currency() const
Definition: legdata.hpp:873
bool isPayer() const
Definition: legdata.hpp:872
const string & legType() const
Definition: legdata.hpp:890
RequiredFixings requiredFixings_
Definition: trade.hpp:223
RandomVariable max(RandomVariable x, const RandomVariable &y)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ legData_

std::vector<ore::data::LegData> legData_
private

Definition at line 75 of file commodityswap.hpp.