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

#include <ored/portfolio/basketoption.hpp>

+ Inheritance diagram for BasketOption:
+ Collaboration diagram for BasketOption:

Public Member Functions

 BasketOption (const std::string &tradeType="BasketOption")
 
 BasketOption (const std::string &currency, const std::string &notional, const TradeStrike &strike, const std::vector< QuantLib::ext::shared_ptr< ore::data::Underlying > > &underlyings, const OptionData &optionData, const std::string &settlement, const ScheduleData &observationDates)
 
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...
 

Protected Member Functions

void initIndices ()
 
- 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

std::string currency_
 
std::string notional_
 
TradeStrike tradeStrike_
 
std::vector< QuantLib::ext::shared_ptr< ore::data::Underlying > > underlyings_
 
OptionData optionData_
 
std::string settlement_
 
ScheduleData observationDates_
 
- 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 36 of file basketoption.hpp.

Constructor & Destructor Documentation

◆ BasketOption() [1/2]

BasketOption ( const std::string &  tradeType = "BasketOption")
explicit

Definition at line 38 of file basketoption.hpp.

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

◆ BasketOption() [2/2]

BasketOption ( const std::string &  currency,
const std::string &  notional,
const TradeStrike strike,
const std::vector< QuantLib::ext::shared_ptr< ore::data::Underlying > > &  underlyings,
const OptionData optionData,
const std::string &  settlement,
const ScheduleData observationDates 
)

Definition at line 39 of file basketoption.hpp.

42 : currency_(currency), notional_(notional), tradeStrike_(strike), underlyings_(underlyings),
43 optionData_(optionData), settlement_(settlement), observationDates_(observationDates) {
45 }
std::vector< QuantLib::ext::shared_ptr< ore::data::Underlying > > underlyings_
ScheduleData observationDates_
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 176 of file basketoption.cpp.

176 {
177
178 // set script parameters
179
180 clear();
181 initIndices();
182
183 QL_REQUIRE(optionData_.exerciseDates().size() == 1, "expected exactly one exercise date");
184 events_.emplace_back("Expiry", optionData_.exerciseDates().front());
185 events_.emplace_back("Settlement", settlement_.empty() ? optionData_.exerciseDates().front() : settlement_);
186
187 numbers_.emplace_back("Number", "Notional", notional_);
188 auto positionType = parsePositionType(optionData_.longShort());
189 numbers_.emplace_back("Number", "LongShort", positionType == Position::Long ? "1" : "-1");
190
191 std::string ccy = parseCurrencyWithMinors(currency_).code();
192 // if no strike ccy, set it to option ccy
193 string strike;
194 if (!tradeStrike_.empty()) {
195 if (tradeStrike_.currency().empty())
197 strike = boost::lexical_cast<std::string>(tradeStrike_.value());
198 }
199 currencies_.emplace_back("Currency", "PayCcy", ccy);
200
201 QL_REQUIRE(optionData_.payoffType2().empty() || optionData_.payoffType2() == "Arithmetic",
202 "BasketOption does not support payoffType2 = '" << optionData_.payoffType2()
203 << "', expected 'Arithmetic'");
204
205 std::string scriptToUse;
206 if (optionData_.payoffType() == "Vanilla") {
207 scriptToUse = vanilla_basket_option_script;
208 numbers_.emplace_back("Number", "PutCall", parseOptionType(optionData_.callPut()) == Option::Call ? "1" : "-1");
209 numbers_.emplace_back("Number", "Strike", strike);
210 } else if (optionData_.payoffType() == "Asian") {
211 scriptToUse = asian_basket_option_script;
212 numbers_.emplace_back("Number", "PutCall", parseOptionType(optionData_.callPut()) == Option::Call ? "1" : "-1");
213 events_.emplace_back("ObservationDates", observationDates_);
214 numbers_.emplace_back("Number", "Strike", strike);
215 } else if (optionData_.payoffType() == "AverageStrike") {
216 scriptToUse = average_strike_basket_option_script;
217 numbers_.emplace_back("Number", "PutCall", parseOptionType(optionData_.callPut()) == Option::Call ? "1" : "-1");
218 events_.emplace_back("ObservationDates", observationDates_);
219 } else if (optionData_.payoffType() == "LookbackCall") {
220 scriptToUse = lookback_call_basket_option_script;
221 events_.emplace_back("ObservationDates", observationDates_);
222 } else if (optionData_.payoffType() == "LookbackPut") {
223 scriptToUse = lookback_put_basket_option_script;
224 events_.emplace_back("ObservationDates", observationDates_);
225 } else {
226 QL_FAIL("payoff type '" << optionData_.payoffType() << "' not recognised");
227 }
228
229 // set product tag
230
231 productTag_ = "MultiAssetOption({AssetClass})";
232
233 // set script
234
235 script_ = {
236 {"", ScriptedTradeScriptData(scriptToUse, "Option",
237 {{"currentNotional", "currentNotional"}, {"notionalCurrency", "PayCcy"}}, {})}};
238
239 // build trade
240
241 ScriptedTrade::build(factory, optionData_.premiumData(), positionType == QuantLib::Position::Long ? -1.0 : 1.0);
242}
const string & callPut() const
Definition: optiondata.hpp:71
const string & payoffType2() const
Definition: optiondata.hpp:73
const string & payoffType() const
Definition: optiondata.hpp:72
const string & longShort() const
Definition: optiondata.hpp:70
const PremiumData & premiumData() const
Definition: optiondata.hpp:83
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
void setCurrency(const std::string &currency)
std::string currency()
const bool empty() const
QuantLib::Real value() const
Currency parseCurrencyWithMinors(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:310
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 244 of file basketoption.cpp.

244 {
246
247 // ISDA taxonomy
248 // asset class set in the base class already
249 std::string assetClass = boost::any_cast<std::string>(additionalData_["isdaAssetClass"]);
250 if (assetClass == "Equity") {
251 additionalData_["isdaBaseProduct"] = string("Option");
252 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
253 } else if (assetClass == "Foreign Exchange") {
254 additionalData_["isdaBaseProduct"] = string("Complex Exotic");
255 additionalData_["isdaSubProduct"] = string("Generic");
256 } else if (assetClass == "Commodity") {
257 // isda taxonomy missing for this class, using the same as equity
258 additionalData_["isdaBaseProduct"] = string("Option");
259 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
260 } else {
261 WLOG("ISDA taxonomy incomplete for trade " << id());
262 }
263 additionalData_["isdaTransaction"] = string("Basket");
264}
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 278 of file basketoption.cpp.

278 {
279 Trade::fromXML(node);
280 XMLNode* dataNode = XMLUtils::getChildNode(node, tradeType() + "Data");
281 QL_REQUIRE(dataNode, tradeType() + "Data node not found");
282 notional_ = XMLUtils::getChildValue(dataNode, "Notional", true);
283 optionData_.fromXML(XMLUtils::getChildNode(dataNode, "OptionData"));
284 currency_ = XMLUtils::getChildValue(dataNode, "Currency");
285 tradeStrike_.fromXML(dataNode, false);
286 auto underlyingsNode = XMLUtils::getChildNode(dataNode, "Underlyings");
287 QL_REQUIRE(underlyingsNode, "No Underlyings node");
288 auto underlyings = XMLUtils::getChildrenNodes(underlyingsNode, "Underlying");
289 for (auto const& n : underlyings) {
290 UnderlyingBuilder underlyingBuilder;
291 underlyingBuilder.fromXML(n);
292 underlyings_.push_back(underlyingBuilder.underlying());
293 }
294
295 settlement_ = XMLUtils::getChildValue(dataNode, "Settlement");
296 if (XMLNode* n = XMLUtils::getChildNode(dataNode, "ObservationDates"))
298 initIndices();
299}
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
virtual void fromXML(XMLNode *node) override
Definition: schedule.cpp:179
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
void fromXML(XMLNode *node, const bool isRequired=true, const bool allowYieldStrike=false)
Definition: tradestrike.cpp:50
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 301 of file basketoption.cpp.

301 {
302 XMLNode* node = Trade::toXML(doc);
303 XMLNode* dataNode = doc.allocNode(tradeType() + "Data");
304 XMLUtils::appendNode(node, dataNode);
305 XMLUtils::addChild(doc, dataNode, "Notional", notional_);
306 XMLUtils::addChild(doc, dataNode, "Currency", currency_);
307 if (!tradeStrike_.empty())
309 XMLNode* underlyingsNode = doc.allocNode("Underlyings");
310 for (auto& n : underlyings_) {
311 XMLUtils::appendNode(underlyingsNode, n->toXML(doc));
312 }
313 XMLUtils::appendNode(dataNode, underlyingsNode);
314 XMLUtils::appendNode(dataNode, optionData_.toXML(doc));
315 if (!settlement_.empty())
316 XMLUtils::addChild(doc, dataNode, "Settlement", settlement_);
318 auto tmp = observationDates_.toXML(doc);
319 XMLUtils::setNodeName(doc, tmp, "ObservationDates");
320 XMLUtils::appendNode(dataNode, tmp);
321 }
322 return node;
323}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
bool hasData() const
Check if has any dates/rules/derived schedules.
Definition: schedule.hpp:223
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: schedule.cpp:198
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
XMLNode * toXML(XMLDocument &doc) const
Definition: tradestrike.cpp:86
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 ( )
protected

Definition at line 266 of file basketoption.cpp.

266 {
267 std::vector<std::string> underlyings, weights;
268 for (auto const& u : underlyings_) {
269 underlyings.push_back(scriptedIndexName(u));
270 QL_REQUIRE(u->weight() != Null<Real>(), "underlying '" << u->name() << "' has no weight");
271 weights.push_back(boost::lexical_cast<std::string>(u->weight()));
272 }
273
274 indices_.emplace_back("Index", "Underlyings", underlyings);
275 numbers_.emplace_back("Number", "Weights", weights);
276}
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_
protected

Definition at line 53 of file basketoption.hpp.

◆ notional_

std::string notional_
protected

Definition at line 53 of file basketoption.hpp.

◆ tradeStrike_

TradeStrike tradeStrike_
protected

Definition at line 54 of file basketoption.hpp.

◆ underlyings_

std::vector<QuantLib::ext::shared_ptr<ore::data::Underlying> > underlyings_
protected

Definition at line 55 of file basketoption.hpp.

◆ optionData_

OptionData optionData_
protected

Definition at line 56 of file basketoption.hpp.

◆ settlement_

std::string settlement_
protected

Definition at line 57 of file basketoption.hpp.

◆ observationDates_

ScheduleData observationDates_
protected

Definition at line 58 of file basketoption.hpp.