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

#include <ored/portfolio/bestentryoption.hpp>

+ Inheritance diagram for BestEntryOption:
+ Collaboration diagram for BestEntryOption:

Public Member Functions

 BestEntryOption (const string &tradeType="BestEntryOption")
 
 BestEntryOption (const Envelope &env, const string &longShort, const string &notional, const string &multiplier, const string &strike, const string &cap, const string &resetMinimum, const string &triggerLevel, const QuantLib::ext::shared_ptr< Underlying > underlying, const string &currency, const ScheduleData &observationDates, const string &premiumDate)
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 
void setIsdaTaxonomyFields () override
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (XMLDocument &doc) const override
 
- Public Member Functions inherited from ScriptedTrade
 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...
 

Private Member Functions

void initIndices ()
 

Private Attributes

std::string longShort_
 
std::string notional_
 
std::string multiplier_
 
std::string strike_
 
std::string cap_
 
std::string resetMinimum_
 
std::string triggerLevel_
 
QuantLib::ext::shared_ptr< Underlyingunderlying_
 
std::string currency_
 
ScheduleData observationDates_
 
std::string expiryDate_
 
std::string premium_
 
std::string settlementDate_
 
std::string strikeDate_
 
std::string premiumDate_
 

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 ScriptedTrade
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_
 

Detailed Description

Definition at line 27 of file bestentryoption.hpp.

Constructor & Destructor Documentation

◆ BestEntryOption() [1/2]

BestEntryOption ( const string &  tradeType = "BestEntryOption")
explicit

Definition at line 29 of file bestentryoption.hpp.

ScriptedTrade(const std::string &tradeType="ScriptedTrade", const Envelope &env=Envelope())
const string & tradeType() const
Definition: trade.hpp:133

◆ BestEntryOption() [2/2]

BestEntryOption ( const Envelope env,
const string &  longShort,
const string &  notional,
const string &  multiplier,
const string &  strike,
const string &  cap,
const string &  resetMinimum,
const string &  triggerLevel,
const QuantLib::ext::shared_ptr< Underlying underlying,
const string &  currency,
const ScheduleData observationDates,
const string &  premiumDate 
)

Definition at line 30 of file bestentryoption.hpp.

34 : longShort_(longShort), notional_(notional), multiplier_(multiplier), strike_(strike), cap_(cap),
35 resetMinimum_(resetMinimum), triggerLevel_(triggerLevel), underlying_(underlying), currency_(currency),
36 observationDates_(observationDates), premiumDate_(premiumDate) {
38 }
std::string strike_
void initIndices()
std::string resetMinimum_
std::string currency_
std::string longShort_
std::string triggerLevel_
std::string cap_
QuantLib::ext::shared_ptr< Underlying > underlying_
std::string premiumDate_
ScheduleData observationDates_
std::string multiplier_
std::string notional_
QuantLib::Real notional() const override
Return the current notional in npvCurrency. See individual sub-classes for the precise definition.
+ Here is the call graph for this function:

Member Function Documentation

◆ build()

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.

Definition at line 29 of file bestentryoption.cpp.

29 {
30
31 // set script parameters
32
33 clear();
35
36 // clang-format off
37
38 static const std::string script =
39 "NUMBER payoff, initialIndex, triggerEvent, strikeIndexObs, strikeIndexLevel, d, resetMinValue;\n"
40 "\n"
41 "triggerEvent = 0;\n"
42 "\n"
43 "strikeIndexLevel = Underlying(StrikeDate);\n"
44 "\n"
45 "resetMinValue = strikeIndexLevel * ResetMinimum;\n"
46 "\n"
47 "strikeIndexObs = Underlying(StrikeObservationDates[1]);\n"
48 "\n"
49 "FOR d IN (1, SIZE(StrikeObservationDates), 1) DO\n"
50 " IF Underlying(StrikeObservationDates[d]) < TriggerLevel * strikeIndexLevel THEN\n"
51 " triggerEvent = 1;\n"
52 " strikeIndexObs = min(strikeIndexObs, Underlying(StrikeObservationDates[d]));\n"
53 " END;\n"
54 "END;\n"
55 "\n"
56 "IF triggerEvent == 1 THEN\n"
57 " initialIndex = max(ResetMinimum * strikeIndexLevel, strikeIndexObs);\n"
58 "ELSE\n"
59 " initialIndex = strikeIndexLevel;\n"
60 "END;\n"
61 "\n"
62 "IF Underlying(ExpiryDate) > Strike * initialIndex THEN\n"
63 " payoff = LongShort * Notional * Multiplier * min(Cap, max(0, (Underlying(ExpiryDate) - initialIndex)/initialIndex));\n"
64 "ELSE\n"
65 " payoff = -1* LongShort * Notional * (Strike * initialIndex - Underlying(ExpiryDate))/initialIndex;\n"
66 "END;\n"
67 "\n"
68 "Option = PAY(payoff, ExpiryDate, SettlementDate, Currency) - PAY(Premium, PremiumDate, PremiumDate, Currency);\n";
69
70 // clang-format on
71
72 numbers_.emplace_back("Number", "Notional", notional_);
73 numbers_.emplace_back("Number", "Multiplier", !multiplier_.empty() ? multiplier_ : "1");
74 numbers_.emplace_back("Number", "Cap", cap_);
75 numbers_.emplace_back("Number", "ResetMinimum", resetMinimum_);
76
77 numbers_.emplace_back("Number", "Strike", strike_);
78
79 numbers_.emplace_back("Number", "LongShort", longShort_ == "Long" ? "1" : "-1");
80
81 numbers_.emplace_back("Number", "TriggerLevel", triggerLevel_);
82
83 events_.emplace_back("ExpiryDate", expiryDate_);
85 "Expiry date must be before settlement date");
86
87 currencies_.emplace_back("Currency", "Currency", currency_);
88 numbers_.emplace_back("Number", "Premium", !premium_.empty() ? premium_ : "0");
89 events_.emplace_back("PremiumDate", !premiumDate_.empty() ? premiumDate_ : settlementDate_);
90
91 events_.emplace_back("SettlementDate", settlementDate_);
92 events_.emplace_back("StrikeDate", strikeDate_);
93 QL_REQUIRE(parseDate(strikeDate_) < parseDate(expiryDate_), "Strike date must be before expiry date");
94
96 events_.emplace_back("StrikeObservationDates", observationDates_);
97 }
98
99 // set product tag
100
101 productTag_ = "SingleAssetOption({AssetClass})";
102
103 // set script
104
105 script_[""] = ScriptedTradeScriptData(script, "Option",
106 {{"initialIndex", "initialIndex"}, {"strikeIndexLevel", "strikeIndexLevel"},
107 {"payoffAmount", "payoff"}, {"resetMinimumValue", "resetMinValue"},
108 {"lowestStrikeObs", "strikeIndexObs"},
109 {"Cap", "Cap"},
110 {"TriggerEvent", "triggerEvent"}},
111 {});
112
113 // build trade
114
115 ScriptedTrade::build(factory);
116}
std::string strikeDate_
std::string premium_
std::string settlementDate_
std::string expiryDate_
bool hasData() const
Check if has any dates/rules/derived schedules.
Definition: schedule.hpp:223
const std::map< std::string, ScriptedTradeScriptData > & script() const
std::vector< ScriptedTradeEventData > events_
std::vector< ScriptedTradeValueTypeData > currencies_
std::vector< ScriptedTradeValueTypeData > numbers_
std::map< std::string, ScriptedTradeScriptData > script_
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
+ Here is the call graph for this function:

◆ setIsdaTaxonomyFields()

void setIsdaTaxonomyFields ( )
overridevirtual

Reimplemented from ScriptedTrade.

Definition at line 118 of file bestentryoption.cpp.

118 {
120
121 // asset class set in the base class already
122 std::string assetClass = boost::any_cast<std::string>(additionalData_["isdaAssetClass"]);
123 if (assetClass == "Equity") {
124 additionalData_["isdaBaseProduct"] = string("Other");
125 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
126 } else if (assetClass == "Commodity") {
127 // isda taxonomy missing for this class, using the same as equity
128 additionalData_["isdaBaseProduct"] = string("Other");
129 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
130 } else if (assetClass == "Foreign Exchange") {
131 additionalData_["isdaBaseProduct"] = string("Complex Exotic");
132 additionalData_["isdaSubProduct"] = string("Generic");
133 } else {
134 WLOG("ISDA taxonomy incomplete for trade " << id());
135 }
136 additionalData_["isdaTransaction"] = string("");
137}
virtual void setIsdaTaxonomyFields()
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
+ Here is the call graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 141 of file bestentryoption.cpp.

141 {
142 Trade::fromXML(node);
143 XMLNode* tradeDataNode = XMLUtils::getChildNode(node, tradeType() + "Data");
144 QL_REQUIRE(tradeDataNode, "BestEntryOptionData node not found");
145 longShort_ = XMLUtils::getChildValue(tradeDataNode, "LongShort", true);
146 notional_ = XMLUtils::getChildValue(tradeDataNode, "Notional", true);
147 multiplier_ = XMLUtils::getChildValue(tradeDataNode, "Multiplier", false);
148 strike_ = XMLUtils::getChildValue(tradeDataNode, "Strike", true);
149 cap_ = XMLUtils::getChildValue(tradeDataNode, "Cap", true);
150 triggerLevel_ = XMLUtils::getChildValue(tradeDataNode, "TriggerLevel", true);
151 resetMinimum_ = XMLUtils::getChildValue(tradeDataNode, "ResetMinimum", true);
152 currency_ = XMLUtils::getChildValue(tradeDataNode, "Currency", true);
153
154 XMLNode* underlying = XMLUtils::getChildNode(tradeDataNode, "Underlying");
155 QL_REQUIRE(underlying, "Underlying node not found");
156
157 UnderlyingBuilder underlyingBuilder;
158 underlyingBuilder.fromXML(underlying);
159 underlying_ = underlyingBuilder.underlying();
160
161 XMLNode* observationNode = XMLUtils::getChildNode(tradeDataNode, "StrikeObservationDates");
162 QL_REQUIRE(observationNode, "No strike observation dates provided");
163 observationDates_.fromXML(observationNode);
164
165 expiryDate_ = XMLUtils::getChildValue(tradeDataNode, "ExpiryDate", true);
166 settlementDate_ = XMLUtils::getChildValue(tradeDataNode, "SettlementDate");
167 strikeDate_ = XMLUtils::getChildValue(tradeDataNode, "StrikeDate", true);
168 premium_ = XMLUtils::getChildValue(tradeDataNode, "Premium", false);
169 premiumDate_ = XMLUtils::getChildValue(tradeDataNode, "PremiumDate", false);
170 currency_ = XMLUtils::getChildValue(tradeDataNode, "Currency", true);
171
172 initIndices();
173}
virtual void fromXML(XMLNode *node) override
Definition: schedule.cpp:179
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
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
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 175 of file bestentryoption.cpp.

175 {
176 XMLNode* node = Trade::toXML(doc);
177 XMLNode* tradeNode = doc.allocNode(tradeType() + "Data");
178 XMLUtils::appendNode(node, tradeNode);
179 XMLUtils::addChild(doc, tradeNode, "LongShort", longShort_);
180 XMLUtils::addChild(doc, tradeNode, "Notional", notional_);
181 XMLUtils::addChild(doc, tradeNode, "Multiplier", multiplier_);
182 XMLUtils::addChild(doc, tradeNode, "Strike", strike_);
183 XMLUtils::addChild(doc, tradeNode, "Cap", cap_);
184 XMLUtils::addChild(doc, tradeNode, "TriggerLevel", triggerLevel_);
185 XMLUtils::addChild(doc, tradeNode, "ResetMinimum", resetMinimum_);
186
187 XMLUtils::appendNode(tradeNode, underlying_->toXML(doc));
188
189 XMLNode* observationNode = observationDates_.toXML(doc);
190 XMLUtils::setNodeName(doc, observationNode, "StrikeObservationDates");
191 XMLUtils::appendNode(tradeNode, observationNode);
192
193 XMLUtils::addChild(doc, tradeNode, "ExpiryDate", expiryDate_);
194 XMLUtils::addChild(doc, tradeNode, "StrikeDate", strikeDate_);
195 XMLUtils::addChild(doc, tradeNode, "Currency", currency_);
196 XMLUtils::addChild(doc, tradeNode, "Premium", premium_);
197 XMLUtils::addChild(doc, tradeNode, "PremiumDate", premiumDate_);
198 XMLUtils::addChild(doc, tradeNode, "SettlementDate", settlementDate_);
199
200 return node;
201}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: schedule.cpp:198
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
static void setNodeName(XMLDocument &doc, XMLNode *node, const string &name)
Definition: xmlutils.cpp:478
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:

◆ initIndices()

void initIndices ( )
private

Definition at line 139 of file bestentryoption.cpp.

139{ indices_.emplace_back("Index", "Underlying", scriptedIndexName(underlying_)); }
std::vector< ScriptedTradeValueTypeData > indices_
QL_DEPRECATED_ENABLE_WARNING std::string scriptedIndexName(const QuantLib::ext::shared_ptr< Underlying > &underlying)
Definition: utilities.cpp:614
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ longShort_

std::string longShort_
private

Definition at line 48 of file bestentryoption.hpp.

◆ notional_

std::string notional_
private

Definition at line 48 of file bestentryoption.hpp.

◆ multiplier_

std::string multiplier_
private

Definition at line 48 of file bestentryoption.hpp.

◆ strike_

std::string strike_
private

Definition at line 48 of file bestentryoption.hpp.

◆ cap_

std::string cap_
private

Definition at line 49 of file bestentryoption.hpp.

◆ resetMinimum_

std::string resetMinimum_
private

Definition at line 49 of file bestentryoption.hpp.

◆ triggerLevel_

std::string triggerLevel_
private

Definition at line 49 of file bestentryoption.hpp.

◆ underlying_

QuantLib::ext::shared_ptr<Underlying> underlying_
private

Definition at line 50 of file bestentryoption.hpp.

◆ currency_

std::string currency_
private

Definition at line 51 of file bestentryoption.hpp.

◆ observationDates_

ScheduleData observationDates_
private

Definition at line 52 of file bestentryoption.hpp.

◆ expiryDate_

std::string expiryDate_
private

Definition at line 53 of file bestentryoption.hpp.

◆ premium_

std::string premium_
private

Definition at line 53 of file bestentryoption.hpp.

◆ settlementDate_

std::string settlementDate_
private

Definition at line 53 of file bestentryoption.hpp.

◆ strikeDate_

std::string strikeDate_
private

Definition at line 54 of file bestentryoption.hpp.

◆ premiumDate_

std::string premiumDate_
private

Definition at line 54 of file bestentryoption.hpp.