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

Serializable EQ European Barrier Option. More...

#include <ored/portfolio/equityeuropeanbarrieroption.hpp>

+ Inheritance diagram for EquityEuropeanBarrierOption:
+ Collaboration diagram for EquityEuropeanBarrierOption:

Public Member Functions

 EquityEuropeanBarrierOption ()
 Default constructor. More...
 
 EquityEuropeanBarrierOption (Envelope &env, OptionData option, BarrierData barrier, EquityUnderlying equityUnderlying, string currency, TradeStrike strike, double quantity)
 Constructor. More...
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Build QuantLib/QuantExt instrument, link pricing engine. More...
 
Inspectors
const BarrierDatabarrier () const
 
- Public Member Functions inherited from EquityOption
 EquityOption ()
 Default constructor. More...
 
 EquityOption (Envelope &env, OptionData option, EquityUnderlying equityUnderlying, string currency, QuantLib::Real quantity, TradeStrike tradeStrike)
 Constructor. More...
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Build QuantLib/QuantExt instrument, link pricing engine. More...
 
std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
 Add underlying Equity names. More...
 
const string & equityName () const
 
const string & strikeCurrency () const
 
- Public Member Functions inherited from VanillaOptionTrade
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Build QuantLib/QuantExt instrument, link pricing engine. More...
 
void setNotionalAndCurrencies ()
 
const OptionDataoption () const
 
const string & asset () const
 
const string & currency () const
 
TradeStrike strike () const
 
double quantity () const
 
const QuantLib::Date forwardDate () const
 
const QuantLib::Date paymentDate () 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
 
virtual QuantLib::Real notional () const
 Return the current notional in npvCurrency. See individual sub-classes for the precise definition. More...
 
virtual string notionalCurrency () 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...
 

Serialisation

BarrierData barrier_
 
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 

Additional Inherited Members

- Protected Member Functions inherited from VanillaOptionTrade
 VanillaOptionTrade (AssetClass assetClassUnderlying)
 
 VanillaOptionTrade (const Envelope &env, AssetClass assetClassUnderlying, OptionData option, string assetName, string currency, double quantity, TradeStrike strike, const QuantLib::ext::shared_ptr< QuantLib::Index > &index=nullptr, const std::string &indexName="", QuantLib::Date forwardDate=QuantLib::Date())
 
- 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 EquityOption
EquityUnderlying equityUnderlying_
 
string strikeCurrency_
 
- Protected Attributes inherited from VanillaOptionTrade
AssetClass assetClassUnderlying_
 
OptionData option_
 
string assetName_
 
string currency_
 
Currency underlyingCurrency_
 
double quantity_
 
TradeStrike strike_
 
QuantLib::ext::shared_ptr< QuantLib::Index > index_
 An index is needed if the option is to be automatically exercised on expiry. More...
 
std::string indexName_
 Hold the external index name if needed e.g. in the case of an FX index. More...
 
QuantLib::Date expiryDate_
 Store the option expiry date. More...
 
QuantLib::Date forwardDate_
 Store the (optional) forward date. More...
 
QuantLib::Date paymentDate_
 Store the (optional) payment date. More...
 
- 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

Serializable EQ European Barrier Option.

Definition at line 39 of file equityeuropeanbarrieroption.hpp.

Constructor & Destructor Documentation

◆ EquityEuropeanBarrierOption() [1/2]

Default constructor.

Definition at line 42 of file equityeuropeanbarrieroption.hpp.

42: EquityOption() {}
EquityOption()
Default constructor.

◆ EquityEuropeanBarrierOption() [2/2]

EquityEuropeanBarrierOption ( Envelope env,
OptionData  option,
BarrierData  barrier,
EquityUnderlying  equityUnderlying,
string  currency,
TradeStrike  strike,
double  quantity 
)

Constructor.

Definition at line 44 of file equityeuropeanbarrieroption.hpp.

Member Function Documentation

◆ build()

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

Build QuantLib/QuantExt instrument, link pricing engine.

Implements Trade.

Definition at line 38 of file equityeuropeanbarrieroption.cpp.

38 {
39
40 // ISDA taxonomy
41 additionalData_["isdaAssetClass"] = string("Equity");
42 additionalData_["isdaBaseProduct"] = string("Other");
43 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
44 // skip the transaction level mapping for now
45 additionalData_["isdaTransaction"] = string("");
46
47 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
48
49 // Only European Single Barrier supported for now
50 QL_REQUIRE(option_.style() == "European", "Option Style unknown: " << option_.style());
51 QL_REQUIRE(option_.exerciseDates().size() == 1, "Invalid number of exercise dates");
52 QL_REQUIRE(barrier_.levels().size() == 1, "Invalid number of barrier levels");
53 QL_REQUIRE(barrier_.style().empty() || barrier_.style() == "European", "Only european barrier style suppported");
54 QL_REQUIRE(tradeActions().empty(), "TradeActions not supported for FxEuropeanBarrierOption");
55
57
58 Currency ccy = parseCurrencyWithMinors(currency_);
59 // Set the strike currency - if we have a minor currency, convert the strike
60 if (!strikeCurrency_.empty())
62 else if (strike_.currency().empty())
64
65 Real level = barrier_.levels()[0].value();
66 Real rebate = barrier_.rebate() / quantity_;
67 QL_REQUIRE(rebate >= 0, "Rebate must be non-negative");
68
69 Option::Type type = parseOptionType(option_.callPut());
70
71 // Exercise
72 Date expiryDate = parseDate(option_.exerciseDates().front());
73 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(expiryDate);
74
75 Barrier::Type barrierType = parseBarrierType(barrier_.type());
76
77 // Payoff - European Option with strike K
78 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoffVanillaK(new PlainVanillaPayoff(type, strike_.value()));
79 // Payoff - European Option with strike B
80 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoffVanillaB(new PlainVanillaPayoff(type, level));
81 // Payoff - Digital Option with barrier B payoff abs(B - K)
82 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoffDigital(new CashOrNothingPayoff(type, level, fabs(level - strike_.value())));
83
84 QuantLib::ext::shared_ptr<Instrument> digital = QuantLib::ext::make_shared<VanillaOption>(payoffDigital, exercise);
85 QuantLib::ext::shared_ptr<Instrument> vanillaK = QuantLib::ext::make_shared<VanillaOption>(payoffVanillaK, exercise);
86 QuantLib::ext::shared_ptr<Instrument> vanillaB = QuantLib::ext::make_shared<VanillaOption>(payoffVanillaB, exercise);
87
88 QuantLib::ext::shared_ptr<StrikedTypePayoff> rebatePayoff;
89 if (barrierType == Barrier::Type::UpIn || barrierType == Barrier::Type::DownOut) {
90 // Payoff - Up&Out / Down&In Digital Option with barrier B payoff rebate
91 rebatePayoff = QuantLib::ext::make_shared<CashOrNothingPayoff>(Option::Put, level, rebate);
92 } else if (barrierType == Barrier::Type::UpOut || barrierType == Barrier::Type::DownIn) {
93 // Payoff - Up&In / Down&Out Digital Option with barrier B payoff rebate
94 rebatePayoff = QuantLib::ext::make_shared<CashOrNothingPayoff>(Option::Call, level, rebate);
95 }
96 QuantLib::ext::shared_ptr<Instrument> rebateInstrument = QuantLib::ext::make_shared<VanillaOption>(rebatePayoff, exercise);
97
98 // set pricing engines
99 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder("EquityOption");
100 QL_REQUIRE(builder, "No builder found for EquityOption");
101 QuantLib::ext::shared_ptr<EquityEuropeanOptionEngineBuilder> eqOptBuilder =
102 QuantLib::ext::dynamic_pointer_cast<EquityEuropeanOptionEngineBuilder>(builder);
103
104 builder = engineFactory->builder("EquityDigitalOption");
105 QL_REQUIRE(builder, "No builder found for EquityDigitalOption");
106 QuantLib::ext::shared_ptr<EquityDigitalOptionEngineBuilder> eqDigitalOptBuilder =
107 QuantLib::ext::dynamic_pointer_cast<EquityDigitalOptionEngineBuilder>(builder);
108
109 digital->setPricingEngine(eqDigitalOptBuilder->engine(assetName_, ccy));
110 vanillaK->setPricingEngine(eqOptBuilder->engine(assetName_, ccy, expiryDate));
111 vanillaB->setPricingEngine(eqOptBuilder->engine(assetName_, ccy, expiryDate));
112 rebateInstrument->setPricingEngine(eqDigitalOptBuilder->engine(assetName_, ccy));
113 setSensitivityTemplate(*eqDigitalOptBuilder);
114
115 QuantLib::ext::shared_ptr<CompositeInstrument> qlInstrument = QuantLib::ext::make_shared<CompositeInstrument>();
116 qlInstrument->add(rebateInstrument);
117 if (type == Option::Call) {
118 if (barrierType == Barrier::Type::UpIn || barrierType == Barrier::Type::DownOut) {
119 if (level > strike_.value()) {
120 qlInstrument->add(vanillaB);
121 qlInstrument->add(digital);
122 } else {
123 qlInstrument->add(vanillaK);
124 }
125 } else if (barrierType == Barrier::Type::UpOut || barrierType == Barrier::Type::DownIn) {
126 if (level > strike_.value()) {
127 qlInstrument->add(vanillaK);
128 qlInstrument->add(vanillaB, -1);
129 qlInstrument->add(digital, -1);
130 } else {
131 // empty
132 }
133 } else {
134 QL_FAIL("Unknown Barrier Type: " << barrierType);
135 }
136 } else if (type == Option::Put) {
137 if (barrierType == Barrier::Type::UpIn || barrierType == Barrier::Type::DownOut) {
138 if (level > strike_.value()) {
139 // empty
140 } else {
141 qlInstrument->add(vanillaK);
142 qlInstrument->add(vanillaB, -1);
143 qlInstrument->add(digital, -1);
144 }
145 } else if (barrierType == Barrier::Type::UpOut || barrierType == Barrier::Type::DownIn) {
146 if (level > strike_.value()) {
147 qlInstrument->add(vanillaK);
148 } else {
149 qlInstrument->add(vanillaB);
150 qlInstrument->add(digital);
151 }
152 } else {
153 QL_FAIL("Unknown Barrier Type: " << barrierType);
154 }
155 }
156
157 // Add additional premium payments
158 Position::Type positionType = parsePositionType(option_.longShort());
159 Real bsInd = (positionType == QuantLib::Position::Long ? 1.0 : -1.0);
160
161 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
162 std::vector<Real> additionalMultipliers;
163 Date lastPremiumDate =
164 addPremiums(additionalInstruments, additionalMultipliers, quantity_ * bsInd, option_.premiumData(), -bsInd, ccy,
165 engineFactory, eqOptBuilder->configuration(MarketContext::pricing));
166
167 instrument_ = QuantLib::ext::shared_ptr<InstrumentWrapper>(
168 new VanillaInstrument(qlInstrument, quantity_ * bsInd, additionalInstruments, additionalMultipliers));
169
170 npvCurrency_ = ccy.code();
173 maturity_ = std::max(lastPremiumDate, expiryDate);
174
175 additionalData_["quantity"] = quantity_;
176 additionalData_["strike"] = strike_.value();
177 additionalData_["strikeCurrency"] = strike_.currency();
178}
const std::string & type() const
Definition: barrierdata.hpp:46
double rebate() const
Definition: barrierdata.hpp:47
std::vector< ore::data::TradeBarrier > levels() const
Definition: barrierdata.hpp:50
const std::string & style() const
Definition: barrierdata.hpp:51
const string & equityName() const
const string & callPut() const
Definition: optiondata.hpp:71
const string & longShort() const
Definition: optiondata.hpp:70
const string & style() const
Definition: optiondata.hpp:74
const PremiumData & premiumData() const
Definition: optiondata.hpp:83
const vector< string > & exerciseDates() const
Definition: optiondata.hpp:76
TradeActions & tradeActions()
Set the trade actions.
Definition: trade.hpp:126
string npvCurrency_
Definition: trade.hpp:201
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
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
string notionalCurrency_
Definition: trade.hpp:203
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
void setCurrency(const std::string &currency)
std::string currency()
QuantLib::Real value() const
Currency parseCurrencyWithMinors(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:310
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Definition: parsers.cpp:404
Barrier::Type parseBarrierType(const std::string &s)
Convert std::string to QuantLib::BarrierType.
Definition: parsers.cpp:1042
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:

◆ barrier()

const BarrierData & barrier ( ) const

Definition at line 53 of file equityeuropeanbarrieroption.hpp.

53{ return barrier_; }

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from EquityOption.

Definition at line 180 of file equityeuropeanbarrieroption.cpp.

180 {
181 Trade::fromXML(node);
182 XMLNode* eqNode = XMLUtils::getChildNode(node, "EquityEuropeanBarrierOptionData");
183 QL_REQUIRE(eqNode, "No EquityEuropeanBarrierOptionData Node");
184 option_.fromXML(XMLUtils::getChildNode(eqNode, "OptionData"));
185 XMLNode* tmp = XMLUtils::getChildNode(eqNode, "Underlying");
186 if (!tmp)
187 tmp = XMLUtils::getChildNode(eqNode, "Name");
189 currency_ = XMLUtils::getChildValue(eqNode, "Currency", true);
190
191 strike_.fromXML(eqNode);
192 strikeCurrency_ = XMLUtils::getChildValue(eqNode, "StrikeCurrency", false);
193 if (!strikeCurrency_.empty())
194 WLOG("EquityOption::fromXML: node StrikeCurrency is deprecated, please us StrikeData node");
195
196 barrier_.fromXML(XMLUtils::getChildNode(eqNode, "BarrierData"));
197 quantity_ = XMLUtils::getChildValueAsDouble(eqNode, "Quantity", true);
198}
virtual void fromXML(ore::data::XMLNode *node) override
Definition: barrierdata.cpp:25
EquityUnderlying equityUnderlying_
void fromXML(XMLNode *node) override
Definition: underlying.cpp:81
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 Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
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
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
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 EquityOption.

Definition at line 200 of file equityeuropeanbarrieroption.cpp.

200 {
201 XMLNode* node = Trade::toXML(doc);
202 XMLNode* eqNode = doc.allocNode("EquityEuropeanBarrierOptionData");
203 XMLUtils::appendNode(node, eqNode);
204
205 XMLUtils::appendNode(eqNode, option_.toXML(doc));
206 XMLUtils::appendNode(eqNode, barrier_.toXML(doc));
208 XMLUtils::addChild(doc, eqNode, "Currency", currency_);
209 XMLUtils::appendNode(eqNode, strike_.toXML(doc));
210 if (!strikeCurrency_.empty())
211 XMLUtils::addChild(doc, eqNode, "StrikeCurrency", strikeCurrency_);
212
213 XMLUtils::addChild(doc, eqNode, "Quantity", quantity_);
214
215 return node;
216}
virtual ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
Definition: barrierdata.cpp:49
XMLNode * toXML(XMLDocument &doc) const override
Definition: underlying.cpp:102
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:

Member Data Documentation

◆ barrier_

BarrierData barrier_
private

Definition at line 62 of file equityeuropeanbarrieroption.hpp.