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
RainbowOption Class Reference

#include <ored/portfolio/rainbowoption.hpp>

+ Inheritance diagram for RainbowOption:
+ Collaboration diagram for RainbowOption:

Public Member Functions

 RainbowOption (const QuantLib::ext::shared_ptr< Conventions > &conventions=nullptr, const std::string &tradeType="RainbowOption")
 
 RainbowOption (const std::string &currency, const std::string &notional, const std::string &strike, const std::vector< QuantLib::ext::shared_ptr< Underlying > > &underlyings, const OptionData &optionData, const std::string &settlement)
 
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 currency_
 
std::string notional_
 
std::string strike_
 
std::vector< QuantLib::ext::shared_ptr< Underlying > > underlyings_
 
OptionData optionData_
 
std::string settlement_
 

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 34 of file rainbowoption.hpp.

Constructor & Destructor Documentation

◆ RainbowOption() [1/2]

RainbowOption ( const QuantLib::ext::shared_ptr< Conventions > &  conventions = nullptr,
const std::string &  tradeType = "RainbowOption" 
)
explicit

Definition at line 36 of file rainbowoption.hpp.

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

◆ RainbowOption() [2/2]

RainbowOption ( const std::string &  currency,
const std::string &  notional,
const std::string &  strike,
const std::vector< QuantLib::ext::shared_ptr< Underlying > > &  underlyings,
const OptionData optionData,
const std::string &  settlement 
)

Definition at line 39 of file rainbowoption.hpp.

42 : currency_(currency), notional_(notional), strike_(strike), underlyings_(underlyings), optionData_(optionData),
43 settlement_(settlement) {
45 }
std::vector< QuantLib::ext::shared_ptr< Underlying > > underlyings_
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 109 of file rainbowoption.cpp.

109 {
110
111 // set script parameters
112
113 clear();
114 initIndices();
115
116 QL_REQUIRE(optionData_.exerciseDates().size() == 1, "expected exactly one exercise date");
117 events_.emplace_back("Expiry", optionData_.exerciseDates().front());
118 events_.emplace_back("Settlement", settlement_.empty() ? optionData_.exerciseDates().front() : settlement_);
119
120 numbers_.emplace_back("Number", "Notional", notional_);
121 numbers_.emplace_back("Number", "LongShort",
122 parsePositionType(optionData_.longShort()) == Position::Long ? "1" : "-1");
123
124 currencies_.emplace_back("Currency", "PayCcy", currency_);
125
126 numbers_.emplace_back("Number", "Strike", strike_);
127
128 std::string scriptToUse;
129 if (optionData_.payoffType() == "BestOfAssetOrCash") {
130 scriptToUse = best_of_asset_or_cash_rainbow_option_script;
131 } else if (optionData_.payoffType() == "WorstOfAssetOrCash") {
132 scriptToUse = worst_of_asset_or_cash_rainbow_option_script;
133 } else if (optionData_.payoffType() == "MaxRainbow") {
134 scriptToUse = max_rainbow_option_script;
135 numbers_.emplace_back("Number", "PutCall", parseOptionType(optionData_.callPut()) == Option::Call ? "1" : "-1");
136 } else if (optionData_.payoffType() == "MinRainbow") {
137 scriptToUse = min_rainbow_option_script;
138 numbers_.emplace_back("Number", "PutCall", parseOptionType(optionData_.callPut()) == Option::Call ? "1" : "-1");
139 } else {
140 QL_FAIL("payoff type '" << optionData_.payoffType() << "' not recognised");
141 }
142
143 // set product tag
144
145 productTag_ = "MultiAssetOption({AssetClass})";
146
147 // set script
148
149 script_ = {{"", ScriptedTradeScriptData(scriptToUse, "Option",
150 {{"currentNotional", "currentNotional"},
151 {"notionalCurrency", "PayCcy"},
152 {"expectedUnderlyingValue", "expUnderValue"}},
153 {})}};
154
155 // build trade
156
157 ScriptedTrade::build(factory);
158}
const string & callPut() const
Definition: optiondata.hpp:71
const string & payoffType() const
Definition: optiondata.hpp:72
const string & longShort() const
Definition: optiondata.hpp:70
const vector< string > & exerciseDates() const
Definition: optiondata.hpp:76
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
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Definition: parsers.cpp:404
Option::Type parseOptionType(const std::string &s)
Convert text to QuantLib::Option::Type.
Definition: parsers.cpp:481
+ Here is the call graph for this function:

◆ setIsdaTaxonomyFields()

void setIsdaTaxonomyFields ( )
overridevirtual

Reimplemented from ScriptedTrade.

Definition at line 160 of file rainbowoption.cpp.

160 {
162
163 // ISDA taxonomy
164 // asset class set in the base class already
165 std::string assetClass = boost::any_cast<std::string>(additionalData_["isdaAssetClass"]);
166 if (assetClass == "Equity") {
167 additionalData_["isdaBaseProduct"] = string("Other");
168 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
169 }
170 else if (assetClass == "Commodity") {
171 // isda taxonomy missing for this class, using the same as equity
172 additionalData_["isdaBaseProduct"] = string("Other");
173 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
174 }
175 else if (assetClass == "Foreign Exchange") {
176 additionalData_["isdaBaseProduct"] = string("Complex Exotic");
177 additionalData_["isdaSubProduct"] = string("Generic");
178 }
179 else {
180 WLOG("ISDA taxonomy incomplete for trade " << id());
181 }
182 additionalData_["isdaTransaction"] = string("Basket");
183}
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 196 of file rainbowoption.cpp.

196 {
197 Trade::fromXML(node);
198 XMLNode* dataNode = XMLUtils::getChildNode(node, tradeType() + "Data");
199 QL_REQUIRE(dataNode, tradeType() + "Data node not found");
200 currency_ = XMLUtils::getChildValue(dataNode, "Currency", true);
201 notional_ = XMLUtils::getChildValue(dataNode, "Notional", true);
202 strike_ = XMLUtils::getChildValue(dataNode, "Strike", true);
203 auto underlyingsNode = XMLUtils::getChildNode(dataNode, "Underlyings");
204 QL_REQUIRE(underlyingsNode, "No Underlyings node");
205 auto underlyings = XMLUtils::getChildrenNodes(underlyingsNode, "Underlying");
206 for (auto const& n : underlyings) {
207 UnderlyingBuilder underlyingBuilder;
208 underlyingBuilder.fromXML(n);
209 underlyings_.push_back(underlyingBuilder.underlying());
210 }
211 optionData_.fromXML(XMLUtils::getChildNode(dataNode, "OptionData"));
212 settlement_ = XMLUtils::getChildValue(dataNode, "Settlement");
213 initIndices();
214}
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
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 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 216 of file rainbowoption.cpp.

216 {
217 XMLNode* node = Trade::toXML(doc);
218 XMLNode* dataNode = doc.allocNode(tradeType() + "Data");
219 XMLUtils::appendNode(node, dataNode);
220 XMLUtils::addChild(doc, dataNode, "Currency", currency_);
221 XMLUtils::addChild(doc, dataNode, "Notional", notional_);
222 XMLUtils::addChild(doc, dataNode, "Strike", strike_);
223 XMLNode* underlyingsNode = doc.allocNode("Underlyings");
224 for (auto& n : underlyings_) {
225 XMLUtils::appendNode(underlyingsNode, n->toXML(doc));
226 }
227 XMLUtils::appendNode(dataNode, underlyingsNode);
228 XMLUtils::appendNode(dataNode, optionData_.toXML(doc));
229 if (!settlement_.empty())
230 XMLUtils::addChild(doc, dataNode, "Settlement", settlement_);
231 return node;
232}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
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:

◆ initIndices()

void initIndices ( )
private

Definition at line 185 of file rainbowoption.cpp.

185 {
186 std::vector<std::string> underlyings, weights;
187 for (auto const& u : underlyings_) {
188 underlyings.push_back(scriptedIndexName(u));
189 QL_REQUIRE(u->weight() != Null<Real>(), "underlying '" << u->name() << "' has no weight");
190 weights.push_back(boost::lexical_cast<std::string>(u->weight()));
191 }
192 indices_.emplace_back("Index", "Underlyings", underlyings);
193 numbers_.emplace_back("Number", "Weights", weights);
194}
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

◆ currency_

std::string currency_
private

Definition at line 53 of file rainbowoption.hpp.

◆ notional_

std::string notional_
private

Definition at line 53 of file rainbowoption.hpp.

◆ strike_

std::string strike_
private

Definition at line 53 of file rainbowoption.hpp.

◆ underlyings_

std::vector<QuantLib::ext::shared_ptr<Underlying> > underlyings_
private

Definition at line 54 of file rainbowoption.hpp.

◆ optionData_

OptionData optionData_
private

Definition at line 55 of file rainbowoption.hpp.

◆ settlement_

std::string settlement_
private

Definition at line 56 of file rainbowoption.hpp.