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

Serializable EQ Digital Option. More...

#include <ored/portfolio/equitydigitaloption.hpp>

+ Inheritance diagram for EquityDigitalOption:
+ Collaboration diagram for EquityDigitalOption:

Public Member Functions

 EquityDigitalOption ()
 Default constructor. More...
 
 EquityDigitalOption (Envelope &env, OptionData option, double strike, const string &payoffCurrency, double payoffAmount, const EquityUnderlying &equityUnderlying, double quantity)
 Constructor. More...
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Build QuantLib/QuantExt instrument, link pricing engine. More...
 
Inspectors
const OptionDataoption () const
 
double strike () const
 
const string & payoffCurrency () const
 
double payoffAmount () const
 
double quantity () const
 
- Public Member Functions inherited from EquitySingleAssetDerivative
const string & equityName () 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

OptionData option_
 
Real strike_
 
string payoffCurrency_
 
Real payoffAmount_
 
Real quantity_
 
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 

Additional Inherited Members

- Protected Member Functions inherited from EquitySingleAssetDerivative
 EquitySingleAssetDerivative (const std::string &tradeType)
 
 EquitySingleAssetDerivative (const std::string &tradeType, ore::data::Envelope &env, const EquityUnderlying &equityUnderlying)
 
- Protected Member Functions inherited from EquityDerivative
 EquityDerivative (const std::string &tradeType)
 
 EquityDerivative (const std::string &tradeType, ore::data::Envelope &env)
 
- 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 EquitySingleAssetDerivative
EquityUnderlying equityUnderlying_
 
- 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 Digital Option.

Definition at line 35 of file equitydigitaloption.hpp.

Constructor & Destructor Documentation

◆ EquityDigitalOption() [1/2]

Default constructor.

Definition at line 38 of file equitydigitaloption.hpp.

39 : ore::data::Trade("EquityDigitalOption"), EquitySingleAssetDerivative("") {}
EquitySingleAssetDerivative(const std::string &tradeType)
Trade base class.
Definition: trade.hpp:55

◆ EquityDigitalOption() [2/2]

EquityDigitalOption ( Envelope env,
OptionData  option,
double  strike,
const string &  payoffCurrency,
double  payoffAmount,
const EquityUnderlying equityUnderlying,
double  quantity 
)

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 34 of file equitydigitaloption.cpp.

34 {
35
36 // ISDA taxonomy
37 additionalData_["isdaAssetClass"] = string("Equity");
38 additionalData_["isdaBaseProduct"] = string("Option");
39 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
40 // skip the transaction level mapping for now
41 additionalData_["isdaTransaction"] = string("");
42
43 // Only European Vanilla supported for now
44 QL_REQUIRE(option_.style() == "European", "Option Style unknown: " << option_.style());
45 QL_REQUIRE(option_.exerciseDates().size() == 1, "Invalid number of exercise dates");
46 QL_REQUIRE(option_.payoffAtExpiry() == true, "PayoffAtExpiry must be True for EquityDigitalOption");
47 QL_REQUIRE(tradeActions().empty(), "TradeActions not supported for EquityDigitalOption");
48 QL_REQUIRE(strike_ > 0.0 && strike_ != Null<Real>(), "Invalid strike " << strike_);
49 QL_REQUIRE(payoffAmount_ > 0.0 && payoffAmount_ != Null<Real>(), "Invalid payoff amount " << payoffAmount_);
50 QL_REQUIRE(payoffCurrency_ != "", "PayoffCurrency is missing");
51
52 // Currency
53 Currency ccy = parseCurrency(payoffCurrency_);
54
55 // Asset Name
56 string assetName = equityName();
57
58 // Payoff Type
59 Option::Type type = parseOptionType(option_.callPut());
60
61 // Set up the CashOrNothing
62 Real strike = strike_;
63 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(new CashOrNothingPayoff(type, strike, payoffAmount_));
64
65 // Exercise
66 Date expiryDate = parseDate(option_.exerciseDates().front());
67 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(expiryDate);
68
69 // QL does not have an EquityDigitalOption, so we add a vanilla one here and wrap
70 // it in a composite.
71 QuantLib::ext::shared_ptr<Instrument> vanilla = QuantLib::ext::make_shared<VanillaOption>(payoff, exercise);
72
73 // set pricing engines
74 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder(tradeType_);
75 QL_REQUIRE(builder, "No builder found for " << tradeType_);
76 QuantLib::ext::shared_ptr<EquityDigitalOptionEngineBuilder> eqOptBuilder =
77 QuantLib::ext::dynamic_pointer_cast<EquityDigitalOptionEngineBuilder>(builder);
78 vanilla->setPricingEngine(eqOptBuilder->engine(assetName, ccy));
79 setSensitivityTemplate(*eqOptBuilder);
80
81 Position::Type positionType = parsePositionType(option_.longShort());
82 Real bsInd = (positionType == QuantLib::Position::Long ? 1.0 : -1.0);
83 Real mult = bsInd;
84
85 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
86 std::vector<Real> additionalMultipliers;
87 Date lastPremiumDate =
88 addPremiums(additionalInstruments, additionalMultipliers, mult * quantity_, option_.premiumData(), -bsInd, ccy,
89 engineFactory, eqOptBuilder->configuration(MarketContext::pricing));
90
91 instrument_ = QuantLib::ext::shared_ptr<InstrumentWrapper>(
92 new VanillaInstrument(vanilla, mult*quantity_, additionalInstruments, additionalMultipliers));
93
97 maturity_ = std::max(lastPremiumDate, expiryDate);
98
99 additionalData_["payoffAmount"] = payoffAmount_;
100 additionalData_["payoffCurrency"] = payoffCurrency_;
101}
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 bool & payoffAtExpiry() const
Definition: optiondata.hpp:75
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
string tradeType_
Definition: trade.hpp:196
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
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:290
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:

◆ option()

const OptionData & option ( ) const

Definition at line 52 of file equitydigitaloption.hpp.

52{ return option_; }

◆ strike()

double strike ( ) const

Definition at line 53 of file equitydigitaloption.hpp.

53{ return strike_; }
+ Here is the caller graph for this function:

◆ payoffCurrency()

const string & payoffCurrency ( ) const

Definition at line 54 of file equitydigitaloption.hpp.

54{ return payoffCurrency_; }

◆ payoffAmount()

double payoffAmount ( ) const

Definition at line 55 of file equitydigitaloption.hpp.

55{ return payoffAmount_; }

◆ quantity()

double quantity ( ) const

Definition at line 56 of file equitydigitaloption.hpp.

56{ return quantity_; }

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 103 of file equitydigitaloption.cpp.

103 {
104 Trade::fromXML(node);
105 XMLNode* eqNode = XMLUtils::getChildNode(node, "EquityDigitalOptionData");
106 QL_REQUIRE(eqNode, "No EquityDigitalOptionData Node");
107 option_.fromXML(XMLUtils::getChildNode(eqNode, "OptionData"));
108 strike_ = XMLUtils::getChildValueAsDouble(eqNode, "Strike", true);
109 payoffCurrency_ = XMLUtils::getChildValue(eqNode, "PayoffCurrency", true);
110 payoffAmount_ = XMLUtils::getChildValueAsDouble(eqNode, "PayoffAmount", true);
111 XMLNode* tmp = XMLUtils::getChildNode(eqNode, "Underlying");
112 if (!tmp)
113 tmp = XMLUtils::getChildNode(eqNode, "Name");
115 quantity_ = XMLUtils::getChildValueAsDouble(eqNode, "Quantity", true);
116}
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
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
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 118 of file equitydigitaloption.cpp.

118 {
119 XMLNode* node = Trade::toXML(doc);
120 XMLNode* eqNode = doc.allocNode("EquityDigitalOptionData");
121 XMLUtils::appendNode(node, eqNode);
122
123 XMLUtils::appendNode(eqNode, option_.toXML(doc));
124 XMLUtils::addChild(doc, eqNode, "Strike", strike_);
125 XMLUtils::addChild(doc, eqNode, "PayoffCurrency", payoffCurrency_);
126 XMLUtils::addChild(doc, eqNode, "PayoffAmount", payoffAmount_);
128 XMLUtils::addChild(doc, eqNode, "Quantity", quantity_);
129
130 return node;
131}
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
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

◆ option_

OptionData option_
private

Definition at line 65 of file equitydigitaloption.hpp.

◆ strike_

Real strike_
private

Definition at line 66 of file equitydigitaloption.hpp.

◆ payoffCurrency_

string payoffCurrency_
private

Definition at line 67 of file equitydigitaloption.hpp.

◆ payoffAmount_

Real payoffAmount_
private

Definition at line 68 of file equitydigitaloption.hpp.

◆ quantity_

Real quantity_
private

Definition at line 69 of file equitydigitaloption.hpp.