17#include <boost/make_shared.hpp>
26#include <ql/errors.hpp>
27#include <ql/exercise.hpp>
28#include <ql/instruments/barrieroption.hpp>
29#include <ql/instruments/compositeinstrument.hpp>
30#include <ql/instruments/swap.hpp>
31#include <ql/instruments/vanillaoption.hpp>
41 double payoffAmount,
string startDate,
string calendar,
string eqIndex)
44 startDate_(startDate), calendar_(
calendar), eqIndex_(eqIndex), payoffAmount_(payoffAmount),
45 payoffCurrency_(payoffCurrency) {
47 switch (barrierType) {
52 case Barrier::DownOut:
57 QL_FAIL(
"unknown barrier type");
66 additionalData_[
"isdaSubProduct"] = string(
"Price Return Basic Performance");
70 Date today = Settings::instance().evaluationDate();
71 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
80 if (barrierType == Barrier::DownIn || barrierType == Barrier::DownOut)
81 type = Option::Type::Put;
83 type = Option::Type::Call;
89 QL_REQUIRE(
tradeActions().empty(),
"TradeActions not supported for EquityOption");
91 QL_REQUIRE(
barrier_.
levels().size() == 1,
"Double barriers not supported for EquityTouchOptions");
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");
98 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(
new CashOrNothingPayoff(
type, level, 1.0));
101 leg.push_back(QuantLib::ext::shared_ptr<CashFlow>(
new SimpleCashFlow(1.0, expiryDate)));
103 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<AmericanExercise>(expiryDate, payoffAtExpiry);
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);
108 QL_REQUIRE(
eqIndex_ !=
"",
"No eqIndex provided");
109 QL_REQUIRE(
calendar_ !=
"",
"No calendar provided");
114 bool triggered =
false;
115 Calendar cal =
eqIndex->fixingCalendar();
120 while (d < today && !triggered) {
122 Real fixing =
eqIndex->pastFixing(d);
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");
131 d = cal.advance(d, 1, Days);
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_));
142 if (
type_ ==
"One-Touch") {
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()));
152 bool isLong = (positionType == Position::Long) ?
true :
false;
154 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
155 std::vector<Real> additionalMultipliers;
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);
169 if (start != Date()) {
170 for (Date d = start; d <= expiryDate; d = cal.advance(d, 1 * Days))
180 case Barrier::DownIn:
181 case Barrier::DownOut:
187 QL_FAIL(
"unknown barrier type " <<
type);
194 QL_REQUIRE(eqNode,
"No EquityOptionData Node");
198 switch (barrierType) {
199 case Barrier::DownIn:
203 case Barrier::DownOut:
208 QL_FAIL(
"unknown barrier type");
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.
Base class for all single asset Equity Derivaties.
const string & equityName() const
EquityUnderlying equityUnderlying_
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)
EquityTouchOption()
Default constructor.
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
const string & eqIndex() const
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 One-Touch/No-Touch Option data model and serialization.
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.
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Barrier::Type parseBarrierType(const std::string &s)
Convert std::string to QuantLib::BarrierType.
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
#define ALOG(text)
Logging Macro (Level = Alert)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.