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

Serializable EQ One-Touch/No-Touch Option. More...

#include <ored/portfolio/equitytouchoption.hpp>

+ Inheritance diagram for EquityTouchOption:
+ Collaboration diagram for EquityTouchOption:

Public Member Functions

 EquityTouchOption ()
 Default constructor. More...
 
 EquityTouchOption (Envelope &env, OptionData option, BarrierData barrier, const EquityUnderlying &equityUnderlying, string payoffCurrency, double payoffAmount, string startDate="", string calendar="", string eqIndex="")
 Constructor. More...
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Build QuantLib/QuantExt instrument, link pricing engine. More...
 
Inspectors
const OptionDataoption () const
 
const BarrierDatabarrier () const
 
double payoffAmount () const
 
const string & type () const
 
const string & payoffCurrency () const
 
const string & startDate () const
 
const string & calendar () const
 
const string & eqIndex () 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_
 
BarrierData barrier_
 
string startDate_
 
string calendar_
 
string eqIndex_
 
Real payoffAmount_
 
string type_
 
string payoffCurrency_
 
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 
bool checkBarrier (Real spot, Barrier::Type type, Real level)
 

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 One-Touch/No-Touch Option.

Definition at line 36 of file equitytouchoption.hpp.

Constructor & Destructor Documentation

◆ EquityTouchOption() [1/2]

Default constructor.

Definition at line 39 of file equitytouchoption.hpp.

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

◆ EquityTouchOption() [2/2]

EquityTouchOption ( Envelope env,
OptionData  option,
BarrierData  barrier,
const EquityUnderlying equityUnderlying,
string  payoffCurrency,
double  payoffAmount,
string  startDate = "",
string  calendar = "",
string  eqIndex = "" 
)

Constructor.

Definition at line 39 of file equitytouchoption.cpp.

42 : ore::data::Trade("EquityTouchOption", env),
43 EquitySingleAssetDerivative("", env, equityUnderlying), option_(option), barrier_(barrier),
46 Barrier::Type barrierType = parseBarrierType(barrier_.type());
47 switch (barrierType) {
48 case Barrier::DownIn:
49 case Barrier::UpIn:
50 type_ = "One-Touch";
51 break;
52 case Barrier::DownOut:
53 case Barrier::UpOut:
54 type_ = "No-Touch";
55 break;
56 default:
57 QL_FAIL("unknown barrier type");
58 }
59}
const std::string & type() const
Definition: barrierdata.hpp:46
const BarrierData & barrier() const
const OptionData & option() const
const string & startDate() const
const string & payoffCurrency() const
const string & calendar() const
const string & eqIndex() const
Barrier::Type parseBarrierType(const std::string &s)
Convert std::string to QuantLib::BarrierType.
Definition: parsers.cpp:1042
+ Here is the call graph for this function:

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 61 of file equitytouchoption.cpp.

61 {
62
63 // ISDA taxonomy
64 additionalData_["isdaAssetClass"] = string("Equity");
65 additionalData_["isdaBaseProduct"] = string("Other");
66 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
67 // skip the transaction level mapping for now
68 additionalData_["isdaTransaction"] = string("");
69
70 Date today = Settings::instance().evaluationDate();
71 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
72
73 // Parse trade data
74 string assetName = equityName();
75 Currency ccy = parseCurrency(payoffCurrency_);
76 Real level = barrier_.levels()[0].value();
77 Date expiryDate = parseDate(option_.exerciseDates().front());
78 Barrier::Type barrierType = parseBarrierType(barrier_.type());
79 Option::Type type;
80 if (barrierType == Barrier::DownIn || barrierType == Barrier::DownOut)
81 type = Option::Type::Put;
82 else
83 type = Option::Type::Call;
84 bool payoffAtExpiry = option_.payoffAtExpiry();
85 Real rebate = barrier_.rebate();
86 Position::Type positionType = parsePositionType(option_.longShort());
87 Date start = ore::data::parseDate(startDate_);
88
89 QL_REQUIRE(tradeActions().empty(), "TradeActions not supported for EquityOption");
90 QL_REQUIRE(option_.exerciseDates().size() == 1, "Invalid number of exercise dates");
91 QL_REQUIRE(barrier_.levels().size() == 1, "Double barriers not supported for EquityTouchOptions");
92 QL_REQUIRE(barrier_.style().empty() || barrier_.style() == "American", "Only american barrier style suppported");
93 QL_REQUIRE(rebate == 0, "Rebates not supported for EquityTouchOptions");
94 QL_REQUIRE(payoffAtExpiry == true || barrierType == Barrier::Type::DownIn || barrierType == Barrier::Type::UpIn,
95 "Payoff at hit not supported for EquityNoTouchOptions");
96
97 // create payoff and exercise, as well as leg of underlying instrument
98 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(new CashOrNothingPayoff(type, level, 1.0));
99 Leg leg;
100
101 leg.push_back(QuantLib::ext::shared_ptr<CashFlow>(new SimpleCashFlow(1.0, expiryDate)));
102
103 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<AmericanExercise>(expiryDate, payoffAtExpiry);
104
105 QuantLib::ext::shared_ptr<Instrument> barrier = QuantLib::ext::make_shared<VanillaOption>(payoff, exercise);
106 QuantLib::ext::shared_ptr<Instrument> underlying = QuantLib::ext::make_shared<Swap>(Leg(), leg);
107
108 QL_REQUIRE(eqIndex_ != "", "No eqIndex provided");
109 QL_REQUIRE(calendar_ != "", "No calendar provided");
110
111 QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> eqIndex = parseEquityIndex(eqIndex_);
112
113 // check if the barrier has been triggered already
114 bool triggered = false;
115 Calendar cal = eqIndex->fixingCalendar();
116 if (startDate_ != "" && start < today) {
117
118 Date d = start;
119
120 while (d < today && !triggered) {
121
122 Real fixing = eqIndex->pastFixing(d);
123
124 if (fixing == 0.0 || fixing == Null<Real>()) {
125 ALOG("Got invalid Equity fixing for index " << eqIndex_ << " on " << d
126 << "Skipping this date, assuming no trigger");
127 } else {
128 triggered = checkBarrier(fixing, barrierType, level);
129 }
130
131 d = cal.advance(d, 1, Days);
132 }
133 }
134
135 // set pricing engines
136 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder(tradeType_);
137 QL_REQUIRE(builder, "No builder found for " << tradeType_);
138 QuantLib::ext::shared_ptr<EquityTouchOptionEngineBuilder> eqTouchOptBuilder =
139 QuantLib::ext::dynamic_pointer_cast<EquityTouchOptionEngineBuilder>(builder);
140 barrier->setPricingEngine(eqTouchOptBuilder->engine(assetName, ccy, type_));
141 setSensitivityTemplate(*eqTouchOptBuilder);
142 if (type_ == "One-Touch") {
143 // if a one-touch option is triggered it becomes a simple forward cashflow
144 // which we price as a swap
145 builder = engineFactory->builder("Swap");
146 QL_REQUIRE(builder, "No builder found for Swap");
147 QuantLib::ext::shared_ptr<SwapEngineBuilderBase> swapBuilder =
148 QuantLib::ext::dynamic_pointer_cast<SwapEngineBuilderBase>(builder);
149 underlying->setPricingEngine(swapBuilder->engine(ccy, std::string(), std::string()));
150 }
151
152 bool isLong = (positionType == Position::Long) ? true : false;
153
154 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
155 std::vector<Real> additionalMultipliers;
156 Date lastPremiumDate = addPremiums(
157 additionalInstruments, additionalMultipliers, (isLong ? 1.0 : -1.0) * payoffAmount_, option_.premiumData(),
158 isLong ? -1.0 : 1.0, ccy, engineFactory, builder->configuration(MarketContext::pricing));
159
160 Handle<Quote> spot = market->equitySpot(assetName);
161 instrument_ = QuantLib::ext::make_shared<SingleBarrierOptionWrapper>(
162 barrier, isLong, expiryDate, false, underlying, barrierType, spot, level, rebate, ccy, start, eqIndex, cal, payoffAmount_,
163 payoffAmount_, additionalInstruments, additionalMultipliers);
167 maturity_ = std::max(lastPremiumDate, expiryDate);
168
169 if (start != Date()) {
170 for (Date d = start; d <= expiryDate; d = cal.advance(d, 1 * Days))
172 }
173
174 additionalData_["payoffAmount"] = payoffAmount_;
175 additionalData_["payoffCurrency"] = payoffCurrency_;
176}
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 & type() const
bool checkBarrier(Real spot, Barrier::Type type, Real level)
const string & longShort() const
Definition: optiondata.hpp:70
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
void addFixingDate(const QuantLib::Date &fixingDate, const std::string &indexName, const QuantLib::Date &payDate=Date::maxDate(), const bool alwaysAddIfPaysOnSettlement=false, const bool mandatoryFixing=true)
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
RequiredFixings requiredFixings_
Definition: trade.hpp:223
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
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > parseEquityIndex(const string &s)
Convert std::string (e.g SP5) to QuantExt::EquityIndex.
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
#define ALOG(text)
Logging Macro (Level = Alert)
Definition: log.hpp:544
+ Here is the call graph for this function:

◆ option()

const OptionData & option ( ) const

Definition at line 51 of file equitytouchoption.hpp.

51{ return option_; }

◆ barrier()

const BarrierData & barrier ( ) const

Definition at line 52 of file equitytouchoption.hpp.

52{ return barrier_; }
+ Here is the caller graph for this function:

◆ payoffAmount()

double payoffAmount ( ) const

Definition at line 53 of file equitytouchoption.hpp.

53{ return payoffAmount_; }

◆ type()

const string & type ( ) const

Definition at line 54 of file equitytouchoption.hpp.

54{ return type_; }
+ Here is the caller graph for this function:

◆ payoffCurrency()

const string & payoffCurrency ( ) const

Definition at line 55 of file equitytouchoption.hpp.

55{ return payoffCurrency_; }

◆ startDate()

const string & startDate ( ) const

Definition at line 56 of file equitytouchoption.hpp.

56{ return startDate_; }

◆ calendar()

const string & calendar ( ) const

Definition at line 57 of file equitytouchoption.hpp.

57{ return calendar_; }

◆ eqIndex()

const string & eqIndex ( ) const

Definition at line 58 of file equitytouchoption.hpp.

58{ return eqIndex_; }
+ Here is the caller graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 191 of file equitytouchoption.cpp.

191 {
192 Trade::fromXML(node);
193 XMLNode* eqNode = XMLUtils::getChildNode(node, "EquityTouchOptionData");
194 QL_REQUIRE(eqNode, "No EquityOptionData Node");
195 option_.fromXML(XMLUtils::getChildNode(eqNode, "OptionData"));
196 barrier_.fromXML(XMLUtils::getChildNode(eqNode, "BarrierData"));
197 Barrier::Type barrierType = parseBarrierType(barrier_.type());
198 switch (barrierType) {
199 case Barrier::DownIn:
200 case Barrier::UpIn:
201 type_ = "One-Touch";
202 break;
203 case Barrier::DownOut:
204 case Barrier::UpOut:
205 type_ = "No-Touch";
206 break;
207 default:
208 QL_FAIL("unknown barrier type");
209 }
210
211 XMLNode* tmp = XMLUtils::getChildNode(eqNode, "Underlying");
212 if (!tmp)
213 tmp = XMLUtils::getChildNode(eqNode, "Name");
215 payoffAmount_ = XMLUtils::getChildValueAsDouble(eqNode, "PayoffAmount", true);
216 payoffCurrency_ = XMLUtils::getChildValue(eqNode, "PayoffCurrency", true);
217 startDate_ = XMLUtils::getChildValue(eqNode, "StartDate", false);
218 calendar_ = XMLUtils::getChildValue(eqNode, "Calendar", false);
219 eqIndex_ = XMLUtils::getChildValue(eqNode, "EQIndex", false);
220}
virtual void fromXML(ore::data::XMLNode *node) override
Definition: barrierdata.cpp:25
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 222 of file equitytouchoption.cpp.

222 {
223 XMLNode* node = Trade::toXML(doc);
224 XMLNode* eqNode = doc.allocNode("EquityTouchOptionData");
225 XMLUtils::appendNode(node, eqNode);
226 XMLUtils::appendNode(eqNode, option_.toXML(doc));
227 XMLUtils::appendNode(eqNode, barrier_.toXML(doc));
229 XMLUtils::addChild(doc, eqNode, "PayoffCurrency", payoffCurrency_);
230 XMLUtils::addChild(doc, eqNode, "PayoffAmount", payoffAmount_);
231 if (startDate_ != "")
232 XMLUtils::addChild(doc, eqNode, "StartDate", startDate_);
233 if (eqIndex_ != "")
234 XMLUtils::addChild(doc, eqNode, "EQIndex", eqIndex_);
235 if (calendar_ != "")
236 XMLUtils::addChild(doc, eqNode, "Calendar", calendar_);
237
238 return node;
239}
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
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:

◆ checkBarrier()

bool checkBarrier ( Real  spot,
Barrier::Type  type,
Real  level 
)
private

Definition at line 178 of file equitytouchoption.cpp.

178 {
179 switch (type) {
180 case Barrier::DownIn:
181 case Barrier::DownOut:
182 return spot <= barrier;
183 case Barrier::UpIn:
184 case Barrier::UpOut:
185 return spot >= barrier;
186 default:
187 QL_FAIL("unknown barrier type " << type);
188 }
189}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ option_

OptionData option_
private

Definition at line 69 of file equitytouchoption.hpp.

◆ barrier_

BarrierData barrier_
private

Definition at line 70 of file equitytouchoption.hpp.

◆ startDate_

string startDate_
private

Definition at line 71 of file equitytouchoption.hpp.

◆ calendar_

string calendar_
private

Definition at line 72 of file equitytouchoption.hpp.

◆ eqIndex_

string eqIndex_
private

Definition at line 73 of file equitytouchoption.hpp.

◆ payoffAmount_

Real payoffAmount_
private

Definition at line 74 of file equitytouchoption.hpp.

◆ type_

string type_
private

Definition at line 75 of file equitytouchoption.hpp.

◆ payoffCurrency_

string payoffCurrency_
private

Definition at line 76 of file equitytouchoption.hpp.