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

#include <ored/portfolio/windowbarrieroption.hpp>

+ Inheritance diagram for WindowBarrierOption:
+ Collaboration diagram for WindowBarrierOption:

Public Member Functions

 WindowBarrierOption (const std::string &tradeType="WindowBarrierOption")
 
 WindowBarrierOption (const std::string &currency, const std::string &fixingAmount, const TradeStrike &strike, const QuantLib::ext::shared_ptr< Underlying > &underlying, const std::string &startDate, const std::string &endDate, const OptionData &optionData, const BarrierData &barrier)
 
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...
 

Inspectors

std::string currency_
 
std::string fixingAmount_
 
TradeStrike strike_
 
QuantLib::ext::shared_ptr< Underlyingunderlying_
 
std::string startDate_
 
std::string endDate_
 
OptionData optionData_
 
BarrierData barrier_
 
const std::string & name () const
 
void initIndices ()
 

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 36 of file windowbarrieroption.hpp.

Constructor & Destructor Documentation

◆ WindowBarrierOption() [1/2]

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

Definition at line 38 of file windowbarrieroption.hpp.

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

◆ WindowBarrierOption() [2/2]

WindowBarrierOption ( const std::string &  currency,
const std::string &  fixingAmount,
const TradeStrike strike,
const QuantLib::ext::shared_ptr< Underlying > &  underlying,
const std::string &  startDate,
const std::string &  endDate,
const OptionData optionData,
const BarrierData barrier 
)

Definition at line 39 of file windowbarrieroption.hpp.

+ 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.

Reimplemented from ScriptedTrade.

Definition at line 58 of file windowbarrieroption.cpp.

58 {
59
60 // set script parameters
61
62 clear();
64
65 if (strike_.currency().empty())
67
68 currencies_.emplace_back("Currency", "PayCcy", currency_);
69 numbers_.emplace_back("Number", "Quantity", fixingAmount_);
70 numbers_.emplace_back("Number", "Strike", boost::lexical_cast<std::string>(strike_.value()));
71 events_.emplace_back("StartDate", startDate_);
72 events_.emplace_back("EndDate", endDate_);
73
74 auto positionType = parsePositionType(optionData_.longShort());
75 numbers_.emplace_back("Number", "LongShort", positionType == Position::Long ? "1" : "-1");
76 numbers_.emplace_back("Number", "PutCall",
77 parseOptionType(optionData_.callPut()) == Option::Type::Call ? "1" : "-1");
78
79 QL_REQUIRE(optionData_.exerciseDates().size() == 1, "WindowBarrierOption: one exercise date required, got " << optionData_.exerciseDates().size());
80 events_.emplace_back("Expiry", optionData_.exerciseDates().front());
81
82 std::string settlementDate = optionData_.exerciseDates().front();
84 QL_REQUIRE(optionData_.paymentData()->dates().size() == 1,
85 "WindowBarrierOption: exactly one payment date required under PaymentData/Dates/Date");
86 }
87 events_.emplace_back("Settlement", settlementDate);
88
89 std::string barrierType;
90 QL_REQUIRE(barrier_.style().empty() || barrier_.style() == "American",
91 "expected barrier style American, got " << barrier_.style());
92 QL_REQUIRE(barrier_.levels().size() == 1,
93 "WindowBarrierOption: exactly one barrier level required, got " << barrier_.levels().size());
94 if (barrier_.type() == "UpAndOut")
95 barrierType = "4";
96 else if (barrier_.type() == "UpAndIn")
97 barrierType = "2";
98 else if (barrier_.type() == "DownAndOut")
99 barrierType = "3";
100 else if (barrier_.type() == "DownAndIn")
101 barrierType = "1";
102 else {
103 QL_FAIL("WindowBarrierOption: invalid barrier level " << barrier_.type());
104 }
105 numbers_.emplace_back("Number", "BarrierType", barrierType);
106 numbers_.emplace_back("Number", "BarrierLevel", boost::lexical_cast<std::string>(barrier_.levels().front().value()));
107
108 // set product tag
109
110 productTag_ = "SingleAssetOption({AssetClass})";
111
112 // set script
113
114 script_[""] = ScriptedTradeScriptData(
115 window_barrier_script, "Option",
116 {{"currentNotional", "currentNotional"},
117 {"notionalCurrency", "PayCcy"},
118 {"TriggerProbability", "TriggerProbability"},
119 {"ExerciseProbability", "ExerciseProbability"}},
120 {}, {}, {ScriptedTradeScriptData::CalibrationData("Underlying", {"Strike", "BarrierLevel"})});
121
122 // build trade
123
124 ScriptedTrade::build(factory, optionData_.premiumData(), positionType == QuantLib::Position::Long ? -1.0 : 1.0);
125
126 additionalData_["isdaTransaction"] = string("");
127}
const std::string & type() const
Definition: barrierdata.hpp:46
std::vector< ore::data::TradeBarrier > levels() const
Definition: barrierdata.hpp:50
const std::string & style() const
Definition: barrierdata.hpp:51
const string & callPut() const
Definition: optiondata.hpp:71
const string & longShort() const
Definition: optiondata.hpp:70
const boost::optional< OptionPaymentData > & paymentData() const
Definition: optiondata.hpp:93
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
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
void setCurrency(const std::string &currency)
std::string currency()
QuantLib::Real value() const
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 129 of file windowbarrieroption.cpp.

129 {
131
132 // ISDA taxonomy, asset class set in the base class build
133 // asset class set in the base class already
134 std::string assetClass = boost::any_cast<std::string>(additionalData_["isdaAssetClass"]);
135 if (assetClass == "Equity") {
136 additionalData_["isdaBaseProduct"] = string("Other");
137 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
138 } else if (assetClass == "Commodity") {
139 // isda taxonomy missing for this class, using the same as equity
140 additionalData_["isdaBaseProduct"] = string("Other");
141 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
142 } else if (assetClass == "Foreign Exchange") {
143 additionalData_["isdaBaseProduct"] = string("Exotic");
144 additionalData_["isdaSubProduct"] = string("Target");
145 } else {
146 WLOG("ISDA taxonomy incomplete for trade " << id());
147 }
148}
virtual void setIsdaTaxonomyFields()
#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 ScriptedTrade.

Definition at line 154 of file windowbarrieroption.cpp.

154 {
155 Trade::fromXML(node);
156 XMLNode* dataNode = XMLUtils::getChildNode(node, tradeType() + "Data");
157 QL_REQUIRE(dataNode, tradeType() + "Data node not found");
158 fixingAmount_ = XMLUtils::getChildValue(dataNode, "FixingAmount");
159
160 currency_ = XMLUtils::getChildValue(dataNode, "Currency");
161 strike_.fromXML(dataNode, true, false);
162
163 XMLNode* tmp = XMLUtils::getChildNode(dataNode, "Underlying");
164 if (!tmp)
165 tmp = XMLUtils::getChildNode(dataNode, "Name");
166 UnderlyingBuilder underlyingBuilder;
167 underlyingBuilder.fromXML(tmp);
168 underlying_ = underlyingBuilder.underlying();
169
170 optionData_.fromXML(XMLUtils::getChildNode(dataNode, "OptionData"));
171 startDate_ = XMLUtils::getChildValue(dataNode, "StartDate");
172 endDate_ = XMLUtils::getChildValue(dataNode, "EndDate");
173
174 auto barrierNode = XMLUtils::getChildNode(dataNode, "BarrierData");
175 QL_REQUIRE(barrierNode, "No BarrierData node");
176 barrier_.fromXML(barrierNode);
177 initIndices();
178}
virtual void fromXML(ore::data::XMLNode *node) override
Definition: barrierdata.cpp:25
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
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 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 ScriptedTrade.

Definition at line 180 of file windowbarrieroption.cpp.

180 {
181 XMLNode* node = Trade::toXML(doc);
182 XMLNode* dataNode = doc.allocNode(tradeType() + "Data");
183 XMLUtils::appendNode(node, dataNode);
184 XMLUtils::addChild(doc, dataNode, "FixingAmount", fixingAmount_);
185 XMLUtils::addChild(doc, dataNode, "Currency", currency_);
186
187 XMLUtils::appendNode(dataNode, strike_.toXML(doc));
188
189 XMLUtils::appendNode(dataNode, underlying_->toXML(doc));
190 XMLUtils::appendNode(dataNode, optionData_.toXML(doc));
191 XMLUtils::addChild(doc, dataNode, "StartDate", startDate_);
192 XMLUtils::addChild(doc, dataNode, "EndDate", endDate_);
193 XMLUtils::appendNode(dataNode, barrier_.toXML(doc));
194
195 return node;
196}
virtual ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
Definition: barrierdata.cpp:49
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
XMLNode * toXML(XMLDocument &doc) const
Definition: tradestrike.cpp:86
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:

◆ name()

const std::string & name ( ) const

Definition at line 53 of file windowbarrieroption.hpp.

53{ return underlying_->name(); }

◆ initIndices()

void initIndices ( )
private

Definition at line 150 of file windowbarrieroption.cpp.

150 {
151 indices_.emplace_back("Index", "Underlying", scriptedIndexName(underlying_));
152}
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 58 of file windowbarrieroption.hpp.

◆ fixingAmount_

std::string fixingAmount_
private

Definition at line 58 of file windowbarrieroption.hpp.

◆ strike_

TradeStrike strike_
private

Definition at line 59 of file windowbarrieroption.hpp.

◆ underlying_

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

Definition at line 60 of file windowbarrieroption.hpp.

◆ startDate_

std::string startDate_
private

Definition at line 61 of file windowbarrieroption.hpp.

◆ endDate_

std::string endDate_
private

Definition at line 61 of file windowbarrieroption.hpp.

◆ optionData_

OptionData optionData_
private

Definition at line 62 of file windowbarrieroption.hpp.

◆ barrier_

BarrierData barrier_
private

Definition at line 63 of file windowbarrieroption.hpp.