22#include <boost/make_shared.hpp>
27#include <ql/errors.hpp>
28#include <ql/exercise.hpp>
29#include <ql/instruments/barrieroption.hpp>
30#include <ql/instruments/compositeinstrument.hpp>
31#include <ql/instruments/swap.hpp>
32#include <ql/instruments/vanillaoption.hpp>
42 double payoffAmount,
string startDate,
string calendar)
46 barrier_(barrier), startDate_(startDate), calendar_(
calendar), payoffAmount_(payoffAmount),
47 payoffCurrency_(payoffCurrency) {
49 switch (barrierType) {
50 case DoubleBarrier::KnockIn:
53 case DoubleBarrier::KnockOut:
57 QL_FAIL(
"unsupported barrier type " << barrierType);
66 additionalData_[
"isdaSubProduct"] = string(
"Price Return Basic Performance");
70 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
74 QL_REQUIRE(
tradeActions().empty(),
"TradeActions not supported for FxOption");
76 QL_REQUIRE(
barrier_.
levels().size() == 2,
"Invalid number of barrier levels");
88 QL_REQUIRE(rebate == 0,
"Rebates not supported for EquityDoubleTouchOptions");
89 if (payoffAtExpiry ==
false) {
90 payoffAtExpiry =
true;
91 DLOG(
"Payoff at hit not yet supported for EquityDoubleTouchOptions, setting to payoff at expiry");
96 QL_REQUIRE(levelLow < levelHigh,
"barrier levels are not in ascending order");
100 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(
new CashOrNothingPayoff(Option::Call, (levelLow + levelHigh) / 2, 1.0));
103 leg.push_back(QuantLib::ext::shared_ptr<CashFlow>(
new SimpleCashFlow(1.0, expiryDate)));
105 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(expiryDate);
107 QuantLib::ext::shared_ptr<Instrument> doubleTouch =
108 QuantLib::ext::make_shared<DoubleBarrierOption>(barrierType, levelLow, levelHigh, 0.0, payoff, exercise);
109 QuantLib::ext::shared_ptr<Instrument> underlying = QuantLib::ext::make_shared<Swap>(Leg(), leg);
113 QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> eqIndex = engineFactory->market()->equityCurve(assetName).currentLink();
116 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder(
tradeType_);
117 QL_REQUIRE(builder,
"No builder found for " <<
tradeType_);
118 QuantLib::ext::shared_ptr<EquityDoubleTouchOptionEngineBuilder> eqDoubleTouchOptBuilder =
119 QuantLib::ext::dynamic_pointer_cast<EquityDoubleTouchOptionEngineBuilder>(builder);
120 doubleTouch->setPricingEngine(eqDoubleTouchOptBuilder->engine(assetName, ccy));
122 if (
type_ ==
"KnockIn") {
125 builder = engineFactory->builder(
"Swap");
126 QL_REQUIRE(builder,
"No builder found for Swap");
127 QuantLib::ext::shared_ptr<SwapEngineBuilderBase> swapBuilder =
128 QuantLib::ext::dynamic_pointer_cast<SwapEngineBuilderBase>(builder);
132 bool isLong = (positionType == Position::Long) ?
true :
false;
134 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
135 std::vector<Real> additionalMultipliers;
140 Handle<Quote> spot = market->equitySpot(assetName);
141 instrument_ = QuantLib::ext::make_shared<DoubleBarrierOptionWrapper>(
142 doubleTouch, isLong, expiryDate,
false, underlying, barrierType, spot, levelLow, levelHigh, 0, ccy, start, eqIndex, cal,
147 maturity_ = std::max(lastPremiumDate, expiryDate);
149 if (start != Date()) {
150 for (Date d = start; d <= expiryDate; d = eqIndex->fixingCalendar().advance(d, 1 * Days))
160 case Barrier::DownIn:
161 case Barrier::DownOut:
167 QL_FAIL(
"unknown barrier type " <<
type);
174 QL_REQUIRE(eqNode,
"No EquityDoubleTouchOptionData Node");
178 switch (barrierType) {
179 case DoubleBarrier::KnockIn:
182 case DoubleBarrier::KnockOut:
186 QL_FAIL(
"unsupported barrier type " << barrierType);
Wrapper for option instruments, tracks whether option has been exercised or not.
Engine builder for Swaps.
Serializable obejct holding barrier data.
const std::string & type() const
virtual void fromXML(ore::data::XMLNode *node) override
virtual ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
std::vector< ore::data::TradeBarrier > levels() const
const std::string & style() const
Serializable object holding generic trade data, reporting dimensions.
EquityDoubleTouchOption()
Default constructor.
const BarrierData & barrier() const
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const string & type() const
bool checkBarrier(Real spot, Barrier::Type type, Real level)
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
Base class for all single asset Equity Derivaties.
const string & equityName() const
EquityUnderlying equityUnderlying_
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
Serializable object holding option data.
const string & longShort() const
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const bool & payoffAtExpiry() const
const PremiumData & premiumData() const
const vector< string > & exerciseDates() const
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.
virtual void fromXML(XMLNode *node) override
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 setSensitivityTemplate(const EngineBuilder &builder)
virtual XMLNode * toXML(XMLDocument &doc) const override
RequiredFixings requiredFixings_
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
std::map< std::string, boost::any > additionalData_
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
static void appendNode(XMLNode *parent, XMLNode *child)
EQ Double One-Touch/No-Touch Option data model and serialization.
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
DoubleBarrier::Type parseDoubleBarrierType(const std::string &s)
Convert std::string to QuantLib::DoubleBarrierType.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
#define DLOG(text)
Logging Macro (Level = Debug)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.