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

#include <ored/portfolio/scriptedtrade.hpp>

+ Inheritance diagram for ScriptedTrade:
+ Collaboration diagram for ScriptedTrade:

Public Member Functions

 ScriptedTrade (const std::string &tradeType="ScriptedTrade", const Envelope &env=Envelope())
 
 ScriptedTrade (const Envelope &env, const std::vector< ScriptedTradeEventData > &events, const std::vector< ScriptedTradeValueTypeData > &numbers, const std::vector< ScriptedTradeValueTypeData > &indices, const std::vector< ScriptedTradeValueTypeData > &currencies, const std::vector< ScriptedTradeValueTypeData > &daycounters, const std::map< std::string, ScriptedTradeScriptData > &script, const std::string &productTag, const std::string &tradeType="ScriptedTrade")
 
 ScriptedTrade (const Envelope &env, const std::vector< ScriptedTradeEventData > &events, const std::vector< ScriptedTradeValueTypeData > &numbers, const std::vector< ScriptedTradeValueTypeData > &indices, const std::vector< ScriptedTradeValueTypeData > &currencies, const std::vector< ScriptedTradeValueTypeData > &daycounters, const std::string &scriptName, const std::string &tradeType="ScriptedTrade")
 
void clear ()
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 
QuantLib::Real notional () const override
 Return the current notional in npvCurrency. See individual sub-classes for the precise definition. More...
 
std::string notionalCurrency () const override
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const PremiumData &premiumData, const Real premiumMultiplier)
 
std::map< ore::data::AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
 
virtual void setIsdaTaxonomyFields ()
 
const std::vector< ScriptedTradeEventData > & events () const
 
const std::vector< ScriptedTradeValueTypeData > & numbers () const
 
const std::vector< ScriptedTradeValueTypeData > & indices () const
 
const std::vector< ScriptedTradeValueTypeData > & currencies () const
 
const std::vector< ScriptedTradeValueTypeData > & daycounters () const
 
const std::map< std::string, ScriptedTradeScriptData > & script () const
 
const std::string & productTag () const
 
const std::string & scriptName () const
 
const std::string & simmProductClass () const
 
const std::string & scheduleProductClass () const
 
const ScriptedTradeScriptDatascript (const std::string &purpose, const bool fallBackOnEmptyPurpose=true) 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
 
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...
 
virtual const std::map< std::string, boost::any > & additionalData () const
 returns all additional data returned by the trade once built 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...
 

Protected Attributes

std::vector< ScriptedTradeEventDataevents_
 
std::vector< ScriptedTradeValueTypeDatanumbers_
 
std::vector< ScriptedTradeValueTypeDataindices_
 
std::vector< ScriptedTradeValueTypeDatacurrencies_
 
std::vector< ScriptedTradeValueTypeDatadaycounters_
 
std::map< std::string, ScriptedTradeScriptDatascript_
 
std::string productTag_
 
std::string scriptName_
 
std::string simmProductClass_
 
std::string scheduleProductClass_
 
- 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_
 

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)
 

Detailed Description

Definition at line 202 of file scriptedtrade.hpp.

Constructor & Destructor Documentation

◆ ScriptedTrade() [1/3]

ScriptedTrade ( const std::string &  tradeType = "ScriptedTrade",
const Envelope env = Envelope() 
)

Definition at line 205 of file scriptedtrade.hpp.

206 : Trade(tradeType, env) {}
Trade()
Default constructor.
Definition: trade.hpp:59
const string & tradeType() const
Definition: trade.hpp:133

◆ ScriptedTrade() [2/3]

ScriptedTrade ( const Envelope env,
const std::vector< ScriptedTradeEventData > &  events,
const std::vector< ScriptedTradeValueTypeData > &  numbers,
const std::vector< ScriptedTradeValueTypeData > &  indices,
const std::vector< ScriptedTradeValueTypeData > &  currencies,
const std::vector< ScriptedTradeValueTypeData > &  daycounters,
const std::map< std::string, ScriptedTradeScriptData > &  script,
const std::string &  productTag,
const std::string &  tradeType = "ScriptedTrade" 
)

Definition at line 208 of file scriptedtrade.hpp.

const std::string & productTag() const
const std::map< std::string, ScriptedTradeScriptData > & script() const
std::vector< ScriptedTradeValueTypeData > daycounters_
std::vector< ScriptedTradeEventData > events_
std::vector< ScriptedTradeValueTypeData > currencies_
const std::vector< ScriptedTradeValueTypeData > & indices() const
const std::vector< ScriptedTradeValueTypeData > & daycounters() const
const std::vector< ScriptedTradeValueTypeData > & numbers() const
std::vector< ScriptedTradeValueTypeData > indices_
std::vector< ScriptedTradeValueTypeData > numbers_
const std::vector< ScriptedTradeValueTypeData > & currencies() const
std::map< std::string, ScriptedTradeScriptData > script_
const std::vector< ScriptedTradeEventData > & events() const

◆ ScriptedTrade() [3/3]

ScriptedTrade ( const Envelope env,
const std::vector< ScriptedTradeEventData > &  events,
const std::vector< ScriptedTradeValueTypeData > &  numbers,
const std::vector< ScriptedTradeValueTypeData > &  indices,
const std::vector< ScriptedTradeValueTypeData > &  currencies,
const std::vector< ScriptedTradeValueTypeData > &  daycounters,
const std::string &  scriptName,
const std::string &  tradeType = "ScriptedTrade" 
)

Member Function Documentation

◆ clear()

void clear ( )

Definition at line 177 of file scriptedtrade.cpp.

177 {
178 events_.clear();
179 numbers_.clear();
180 indices_.clear();
181 currencies_.clear();
182 daycounters_.clear();
184 script_.clear();
185}
+ Here is the caller graph for this function:

◆ build() [1/2]

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

Build QuantLib/QuantExt instrument, link pricing engine. If build() is called multiple times, reset() should be called between these calls.

Implements Trade.

Reimplemented in TaRF, WindowBarrierOption, and WorstOfBasketSwap.

Definition at line 97 of file scriptedtrade.cpp.

97 {
98 ScriptedTrade::build(engineFactory, PremiumData(), 1.0);
99}
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
+ Here is the call graph for this function:
+ Here is the caller 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 135 of file scriptedtrade.cpp.

135 {
136 if (instrument_->qlInstrument()->isExpired())
137 return 0.0;
138 // try to get the notional from the additional results of the instrument
139 auto st = QuantLib::ext::dynamic_pointer_cast<ScriptedInstrument>(instrument_->qlInstrument(true));
140 QL_REQUIRE(st, "internal error: could not cast to ScriptedInstrument");
141 try {
142 return st->result<Real>("currentNotional");
143 } catch (const std::exception& e) {
144 if (st->lastCalculationWasValid()) {
145 // calculation was valid, just the result is not provided
146 DLOG("notional was not retrieved: " << e.what() << ", return null");
147 } else {
148 // calculation threw an error, propagate this
149 QL_FAIL(e.what());
150 }
151 }
152 // if not provided, return null
153 return Null<Real>();
154}
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554

◆ notionalCurrency()

std::string notionalCurrency ( ) const
overridevirtual

Reimplemented from Trade.

Definition at line 156 of file scriptedtrade.cpp.

156 {
157 if (instrument_->qlInstrument()->isExpired())
158 return npvCurrency_;
159 // try to get the notional ccy from the additional results of the instrument
160 auto st = QuantLib::ext::dynamic_pointer_cast<ScriptedInstrument>(instrument_->qlInstrument(true));
161 QL_REQUIRE(st, "internal error: could not cast to ScriptedInstrument");
162 try {
163 return instrument_->qlInstrument()->result<std::string>("notionalCurrency");
164 } catch (const std::exception& e) {
165 if (st->lastCalculationWasValid()) {
166 // calculation was valid, just the result is not provided
167 DLOG("notional ccy was not retrieved: " << e.what() << ", return empty string");
168 } else {
169 // calculation threw an error, propagate this
170 QL_FAIL(e.what());
171 }
172 }
173 // if not provided, return an empty string
174 return std::string();
175}
string npvCurrency_
Definition: trade.hpp:201

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Reimplemented in TaRF, WindowBarrierOption, and WorstOfBasketSwap.

Definition at line 252 of file scriptedtrade.cpp.

252 {
253 clear();
254 Trade::fromXML(node);
255
256 // if we find a ScriptedTradeData node we use this (native format)
257
258 XMLNode* tradeDataNode = XMLUtils::getChildNode(node, "ScriptedTradeData");
259 if (tradeDataNode) {
260 XMLNode* dataNode = XMLUtils::getChildNode(tradeDataNode, "Data");
261 QL_REQUIRE(dataNode, "ScriptedTradeData/Data node not found");
262 vector<XMLNode*> nodes = XMLUtils::getChildrenNodes(dataNode, "");
263 for (auto const n : nodes) {
264 if (XMLUtils::getNodeName(n) == "Event") {
265 events_.push_back(ScriptedTradeEventData());
266 events_.back().fromXML(n);
267 } else if (XMLUtils::getNodeName(n) == "Number") {
268 numbers_.push_back(ScriptedTradeValueTypeData("Number"));
269 numbers_.back().fromXML(n);
270 } else if (XMLUtils::getNodeName(n) == "Index") {
271 indices_.push_back(ScriptedTradeValueTypeData("Index"));
272 indices_.back().fromXML(n);
273 } else if (XMLUtils::getNodeName(n) == "Currency") {
274 currencies_.push_back(ScriptedTradeValueTypeData("Currency"));
275 currencies_.back().fromXML(n);
276 } else if (XMLUtils::getNodeName(n) == "Daycounter") {
277 daycounters_.push_back(ScriptedTradeValueTypeData("Daycounter"));
278 daycounters_.back().fromXML(n);
279 }
280 }
281 if (XMLNode* scriptName = XMLUtils::getChildNode(tradeDataNode, "ScriptName")) {
283 } else if (XMLUtils::getChildNode(tradeDataNode, "Script")) {
284 productTag_ = XMLUtils::getChildValue(tradeDataNode, "ProductTag", false);
285 auto sn = XMLUtils::getChildrenNodes(tradeDataNode, "Script");
286 for (auto const& n : sn) {
287 ScriptedTradeScriptData s;
288 s.fromXML(n);
289 std::string purpose = XMLUtils::getAttribute(n, "purpose");
290 script_[purpose] = s;
291 }
292 } else {
293 QL_FAIL("either Script or ScriptName expected");
294 }
295 return;
296 }
297
298 // otherwise we look for a xxxData node and interpret the xxx as the script name (freestyle parsing)
299
300 for (XMLNode* child = XMLUtils::getChildNode(node); child; child = XMLUtils::getNextSibling(child)) {
301 std::string name = XMLUtils::getNodeName(child);
302 if (name.size() > 4 && name.substr(name.size() - 4, 4) == "Data") {
303 QL_REQUIRE(!tradeDataNode, "multiple child nodes xxxData found");
304 tradeDataNode = child;
305 scriptName_ = name.substr(0, name.size() - 4);
306 }
307 }
308
309 QL_REQUIRE(tradeDataNode, "expected ScriptedTradeData or xxxData node");
310
311 // now loop over the child nodes and populate the script data
312 for (XMLNode* child = XMLUtils::getChildNode(tradeDataNode); child; child = XMLUtils::getNextSibling(child)) {
313
314 // the name of the node will be the name of the script variable
315 std::string varName = XMLUtils::getNodeName(child);
316 std::string type = XMLUtils::getAttribute(child, "type");
317 QL_REQUIRE(!type.empty(), "no type given for node '" << varName << "'");
318
319 std::string scalarValue = XMLUtils::getNodeValue(child);
320 if (!scalarValue.empty()) {
321 // if we have a value, this is a scalar
322 auto native = getNativeTypeAndValue(scalarValue, type);
323 if (native.first == NodeType::Event) {
324 events_.push_back(ScriptedTradeEventData(varName, native.second));
325 } else if (native.first == NodeType::Number) {
326 numbers_.push_back(ScriptedTradeValueTypeData("Number", varName, native.second));
327 } else if (native.first == NodeType::Index) {
328 indices_.push_back(ScriptedTradeValueTypeData("Index", varName, native.second));
329 } else if (native.first == NodeType::Currency) {
330 currencies_.push_back(ScriptedTradeValueTypeData("Currency", varName, native.second));
331 } else if (native.first == NodeType::Daycounter) {
332 daycounters_.push_back(ScriptedTradeValueTypeData("Daycounter", varName, native.second));
333 } else {
334 QL_FAIL("unexpected node type");
335 }
336 } else {
337 // if we don't have a value, this is a vector given by some sub node
338 if (XMLNode* v = XMLUtils::getChildNode(child, "ScheduleData")) {
339 ScheduleData sched;
340 sched.fromXML(v);
341 events_.push_back(ScriptedTradeEventData(varName, sched));
342 } else if (XMLNode* v = XMLUtils::getChildNode(child, "DerivedSchedule")) {
343 events_.push_back(ScriptedTradeEventData(varName, XMLUtils::getChildValue(v, "BaseSchedule", true),
344 XMLUtils::getChildValue(v, "Shift", true),
345 XMLUtils::getChildValue(v, "Calendar", true),
346 XMLUtils::getChildValue(v, "Convention", true)));
347 } else if (XMLNode* v = XMLUtils::getChildNode(child, "Value")) {
348 auto native = getNativeTypeAndValue(XMLUtils::getNodeValue(v), type);
349 QL_REQUIRE(native.first != NodeType::Event, "unexpected even array under node '" << varName << "'");
350 std::vector<std::string> arrayValues;
351 for (XMLNode* val = XMLUtils::getChildNode(child, "Value"); val;
352 val = XMLUtils::getNextSibling(val, "Value")) {
353 auto v = getNativeTypeAndValue(XMLUtils::getNodeValue(val), type);
354 arrayValues.push_back(v.second);
355 }
356 if (native.first == NodeType::Number) {
357 numbers_.push_back(ScriptedTradeValueTypeData("Number", varName, arrayValues));
358 } else if (native.first == NodeType::Index) {
359 indices_.push_back(ScriptedTradeValueTypeData("Index", varName, arrayValues));
360 } else if (native.first == NodeType::Currency) {
361 currencies_.push_back(ScriptedTradeValueTypeData("Currency", varName, arrayValues));
362 } else if (native.first == NodeType::Daycounter) {
363 daycounters_.push_back(ScriptedTradeValueTypeData("Daycounter", varName, arrayValues));
364 } else {
365 QL_FAIL("unexpected node type");
366 }
367 } else {
368 QL_FAIL("unexpected content under node '" << varName << "'");
369 }
370 }
371 }
372}
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
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 string getNodeName(XMLNode *n)
Get and set a node's name.
Definition: xmlutils.cpp:473
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static string getNodeValue(XMLNode *node)
Get a node's value.
Definition: xmlutils.cpp:489
static XMLNode * getNextSibling(XMLNode *node, const string &name="")
Get a node's next sibling node.
Definition: xmlutils.cpp:484
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
string name
+ Here is the call graph for this function:

◆ toXML()

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

Reimplemented from Trade.

Reimplemented in TaRF, WindowBarrierOption, and WorstOfBasketSwap.

Definition at line 374 of file scriptedtrade.cpp.

374 {
375 XMLNode* node = Trade::toXML(doc);
376 XMLNode* tradeDataNode = doc.allocNode("ScriptedTradeData");
377 XMLUtils::appendNode(node, tradeDataNode);
378 if (!scriptName_.empty())
379 XMLUtils::addChild(doc, tradeDataNode, "ScriptName", scriptName_);
380 else {
381 XMLUtils::addChild(doc, tradeDataNode, "ProductTag", productTag_);
382 for (auto& s : script_) {
383 XMLNode* n = s.second.toXML(doc);
384 XMLUtils::addAttribute(doc, n, "purpose", s.first);
385 XMLUtils::appendNode(tradeDataNode, n);
386 }
387 }
388 XMLNode* dataNode = doc.allocNode("Data");
389 XMLUtils::appendNode(tradeDataNode, dataNode);
390 for (auto& x : events_)
391 XMLUtils::appendNode(dataNode, x.toXML(doc));
392 for (auto& x : numbers_)
393 XMLUtils::appendNode(dataNode, x.toXML(doc));
394 for (auto& x : indices_)
395 XMLUtils::appendNode(dataNode, x.toXML(doc));
396 for (auto& x : currencies_)
397 XMLUtils::appendNode(dataNode, x.toXML(doc));
398 for (auto& x : daycounters_)
399 XMLUtils::appendNode(dataNode, x.toXML(doc));
400 return node;
401}
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 addAttribute(XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
Definition: xmlutils.cpp:412
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:

◆ build() [2/2]

void build ( const QuantLib::ext::shared_ptr< EngineFactory > &  engineFactory,
const PremiumData premiumData,
const Real  premiumMultiplier 
)

Definition at line 39 of file scriptedtrade.cpp.

40 {
41
42 DLOG("ScriptedTrade::build() called for trade " << id());
43
44 auto builder = QuantLib::ext::dynamic_pointer_cast<ScriptedTradeEngineBuilder>(engineFactory->builder("ScriptedTrade"));
45
46 QL_REQUIRE(builder, "no builder found for ScriptedTrade");
47 auto engine = builder->engine(id(), *this, engineFactory->referenceData(), engineFactory->iborFallbackConfig());
48
49 simmProductClass_ = builder->simmProductClass();
50 scheduleProductClass_ = builder->scheduleProductClass();
51
53
54 auto qleInstr = QuantLib::ext::make_shared<ScriptedInstrument>(builder->lastRelevantDate());
55 qleInstr->setPricingEngine(engine);
56
57 npvCurrency_ = builder->npvCurrency();
58 maturity_ = builder->lastRelevantDate();
59 notional_ = Null<Real>(); // is handled by override of notional()
60 notionalCurrency_ = ""; // is handled by override of notionalCurrency()
61 legs_.clear();
62 legCurrencies_.clear();
63 legPayers_.clear();
64
65 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
66 std::vector<Real> additionalMultipliers;
67 maturity_ = std::max(maturity_, addPremiums(additionalInstruments, additionalMultipliers, 1.0, premiumData,
68 premiumMultiplier, parseCurrencyWithMinors(npvCurrency_), engineFactory,
69 builder->configuration(MarketContext::pricing)));
70
71 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(qleInstr, 1.0, additionalInstruments, additionalMultipliers);
72
73 // add required fixings
74 for (auto const& f : builder->fixings()) {
75 for (auto const& d : f.second) {
76 IndexInfo info(f.first);
77 if (info.isInf()) {
78 QL_DEPRECATED_DISABLE_WARNING
79 requiredFixings_.addZeroInflationFixingDate(d, info.infName(), info.inf()->interpolated(),
80 info.inf()->frequency(), info.inf()->availabilityLag(),
81 CPI::AsIndex, info.inf()->frequency(), Date::maxDate(), false, false);
82 QL_DEPRECATED_ENABLE_WARNING
83 } else if (info.isFx()) {
84 // for FX we do not know if FX-TAG-CCY1-CCY2 or FX-TAG-CCY2-CCY1 is in the history, require both
85 requiredFixings_.addFixingDate(d, f.first, Date::maxDate(), false, false);
86 requiredFixings_.addFixingDate(d, inverseFxIndex(f.first), Date::maxDate(), false, false);
87 } else {
88 requiredFixings_.addFixingDate(d, f.first, Date::maxDate(), false, false);
89 }
90 }
91 }
92
93 // set sensitivity template
94 setSensitivityTemplate(builder->sensitivityTemplate());
95}
void addZeroInflationFixingDate(const QuantLib::Date &fixingDate, const std::string &indexName, const bool indexInterpolated, const Frequency indexFrequency, const Period &indexAvailabilityLag, const CPI::InterpolationType coupopnInterpolation, const Frequency couponFrequency, const QuantLib::Date &payDate=Date::maxDate(), const bool alwaysAddIfPaysOnSettlement=false, const bool mandatoryFixing=true)
void addFixingDate(const QuantLib::Date &fixingDate, const std::string &indexName, const QuantLib::Date &payDate=Date::maxDate(), const bool alwaysAddIfPaysOnSettlement=false, const bool mandatoryFixing=true)
virtual void setIsdaTaxonomyFields()
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
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)
Definition: trade.cpp:58
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
RequiredFixings requiredFixings_
Definition: trade.hpp:223
string notionalCurrency_
Definition: trade.hpp:203
Currency parseCurrencyWithMinors(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:310
std::string inverseFxIndex(const std::string &indexName)
+ Here is the call graph for this function:

◆ underlyingIndices()

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

Reimplemented from Trade.

Definition at line 226 of file scriptedtrade.cpp.

226 {
227
228 map<ore::data::AssetClass, set<string>> result;
229
230 for (const auto& p : indices_) {
231 vector<string> vals;
232 if (!p.value().empty())
233 vals.push_back(p.value());
234 else
235 vals = p.values();
236
237 for (auto v : vals) {
238 if (!v.empty()) {
239 IndexInfo ind(v);
240 if (ind.isComm()) {
241 result[ore::data::AssetClass::COM].insert(ind.commName());
242 } else if (ind.isEq()) {
243 result[ore::data::AssetClass::EQ].insert(ind.eq()->name());
244 }
245 }
246 }
247 }
248
249 return result;
250}
+ Here is the call graph for this function:

◆ setIsdaTaxonomyFields()

void setIsdaTaxonomyFields ( )
virtual

Reimplemented in Accumulator, Autocallable_01, BasketOption, BasketVarianceSwap, BestEntryOption, PerformanceOption_01, RainbowOption, WindowBarrierOption, and WorstOfBasketSwap.

Definition at line 101 of file scriptedtrade.cpp.

101 {
102 // ISDA taxonomy, can be overwritten in derived classes
103 if (scheduleProductClass_ == "FX") {
104 additionalData_["isdaAssetClass"] = string("Foreign Exchange");
105 additionalData_["isdaBaseProduct"] = string("Complex Exotic");
106 additionalData_["isdaSubProduct"] = string("Generic");
107 additionalData_["isdaTransaction"] = string("");
108 } else if (scheduleProductClass_ == "Rates") {
109 additionalData_["isdaAssetClass"] = string("Interest Rate");
110 additionalData_["isdaBaseProduct"] = string("Exotic");
111 additionalData_["isdaSubProduct"] = string("");
112 additionalData_["isdaTransaction"] = string("");
113 } else if (scheduleProductClass_ == "Equity") {
114 additionalData_["isdaAssetClass"] = string("Equity");
115 additionalData_["isdaBaseProduct"] = string("Other");
116 additionalData_["isdaSubProduct"] = string("");
117 additionalData_["isdaTransaction"] = string("");
118 } else if (scheduleProductClass_ == "Credit") {
119 additionalData_["isdaAssetClass"] = string("Credit");
120 additionalData_["isdaBaseProduct"] = string("Exotic");
121 additionalData_["isdaSubProduct"] = string("Other");
122 additionalData_["isdaTransaction"] = string("");
123 } else if (scheduleProductClass_ == "Commodity") {
124 DLOG("ISDA taxonomy for trade " << id() << " and product class " << scheduleProductClass_
125 << " follows the Equity template");
126 additionalData_["isdaAssetClass"] = string("Commodity");
127 additionalData_["isdaBaseProduct"] = string("Other");
128 additionalData_["isdaSubProduct"] = string("");
129 additionalData_["isdaTransaction"] = string("");
130 } else {
131 DLOG("ISDA taxonomy not set for trade " << id() << " and product class " << scheduleProductClass_);
132 }
133}
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
+ Here is the caller graph for this function:

◆ events()

const std::vector< ScriptedTradeEventData > & events ( ) const

Definition at line 249 of file scriptedtrade.hpp.

249{ return events_; }
+ Here is the caller graph for this function:

◆ numbers()

const std::vector< ScriptedTradeValueTypeData > & numbers ( ) const

Definition at line 250 of file scriptedtrade.hpp.

250{ return numbers_; }
+ Here is the caller graph for this function:

◆ indices()

const std::vector< ScriptedTradeValueTypeData > & indices ( ) const

Definition at line 251 of file scriptedtrade.hpp.

251{ return indices_; }
+ Here is the caller graph for this function:

◆ currencies()

const std::vector< ScriptedTradeValueTypeData > & currencies ( ) const

Definition at line 252 of file scriptedtrade.hpp.

252{ return currencies_; }
+ Here is the caller graph for this function:

◆ daycounters()

const std::vector< ScriptedTradeValueTypeData > & daycounters ( ) const

Definition at line 253 of file scriptedtrade.hpp.

253{ return daycounters_; }
+ Here is the caller graph for this function:

◆ script() [1/2]

const std::map< std::string, ScriptedTradeScriptData > & script ( ) const

Definition at line 254 of file scriptedtrade.hpp.

254{ return script_; }
+ Here is the caller graph for this function:

◆ productTag()

const std::string & productTag ( ) const

Definition at line 255 of file scriptedtrade.hpp.

255{ return productTag_; }
+ Here is the caller graph for this function:

◆ scriptName()

const std::string & scriptName ( ) const

Definition at line 256 of file scriptedtrade.hpp.

256{ return scriptName_; }
+ Here is the caller graph for this function:

◆ simmProductClass()

const std::string & simmProductClass ( ) const

Definition at line 257 of file scriptedtrade.hpp.

257{ return simmProductClass_; }

◆ scheduleProductClass()

const std::string & scheduleProductClass ( ) const

Definition at line 258 of file scriptedtrade.hpp.

258{ return scheduleProductClass_; }

◆ script() [2/2]

const ScriptedTradeScriptData & script ( const std::string &  purpose,
const bool  fallBackOnEmptyPurpose = true 
) const

Definition at line 403 of file scriptedtrade.cpp.

404 {
405 auto s1 = script_.find(purpose);
406 if (s1 != script_.end())
407 return s1->second;
408 if (fallBackOnEmptyPurpose) {
409 auto s2 = script_.find("");
410 if (s2 != script_.end())
411 return s2->second;
412 }
413 QL_FAIL("ScriptedTrade::script(): script with purpose '"
414 << purpose << "' not found, fall back on empty purpose was " << std::boolalpha << fallBackOnEmptyPurpose);
415}

Member Data Documentation

◆ events_

std::vector<ScriptedTradeEventData> events_
protected

Definition at line 265 of file scriptedtrade.hpp.

◆ numbers_

std::vector<ScriptedTradeValueTypeData> numbers_
protected

Definition at line 266 of file scriptedtrade.hpp.

◆ indices_

std::vector<ScriptedTradeValueTypeData> indices_
protected

Definition at line 267 of file scriptedtrade.hpp.

◆ currencies_

std::vector<ScriptedTradeValueTypeData> currencies_
protected

Definition at line 268 of file scriptedtrade.hpp.

◆ daycounters_

std::vector<ScriptedTradeValueTypeData> daycounters_
protected

Definition at line 269 of file scriptedtrade.hpp.

◆ script_

std::map<std::string, ScriptedTradeScriptData> script_
protected

Definition at line 271 of file scriptedtrade.hpp.

◆ productTag_

std::string productTag_
protected

Definition at line 272 of file scriptedtrade.hpp.

◆ scriptName_

std::string scriptName_
protected

Definition at line 274 of file scriptedtrade.hpp.

◆ simmProductClass_

std::string simmProductClass_
protected

Definition at line 277 of file scriptedtrade.hpp.

◆ scheduleProductClass_

std::string scheduleProductClass_
protected

Definition at line 278 of file scriptedtrade.hpp.