25#include <ql/errors.hpp>
26#include <ql/exercise.hpp>
27#include <ql/instruments/barriertype.hpp>
28#include <ql/instruments/compositeinstrument.hpp>
29#include <ql/instruments/vanillaoption.hpp>
31#include <boost/make_shared.hpp>
43 additionalData_[
"isdaSubProduct"] = string(
"Price Return Basic Performance");
47 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
52 QL_REQUIRE(
barrier_.
levels().size() == 1,
"Invalid number of barrier levels");
54 QL_REQUIRE(
tradeActions().empty(),
"TradeActions not supported for FxEuropeanBarrierOption");
67 QL_REQUIRE(rebate >= 0,
"Rebate must be non-negative");
73 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(expiryDate);
78 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoffVanillaK(
new PlainVanillaPayoff(type,
strike_.
value()));
80 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoffVanillaB(
new PlainVanillaPayoff(type, level));
82 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoffDigital(
new CashOrNothingPayoff(type, level, fabs(level -
strike_.
value())));
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);
88 QuantLib::ext::shared_ptr<StrikedTypePayoff> rebatePayoff;
89 if (barrierType == Barrier::Type::UpIn || barrierType == Barrier::Type::DownOut) {
91 rebatePayoff = QuantLib::ext::make_shared<CashOrNothingPayoff>(Option::Put, level, rebate);
92 }
else if (barrierType == Barrier::Type::UpOut || barrierType == Barrier::Type::DownIn) {
94 rebatePayoff = QuantLib::ext::make_shared<CashOrNothingPayoff>(Option::Call, level, rebate);
96 QuantLib::ext::shared_ptr<Instrument> rebateInstrument = QuantLib::ext::make_shared<VanillaOption>(rebatePayoff, exercise);
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);
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);
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));
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) {
120 qlInstrument->add(vanillaB);
121 qlInstrument->add(digital);
123 qlInstrument->add(vanillaK);
125 }
else if (barrierType == Barrier::Type::UpOut || barrierType == Barrier::Type::DownIn) {
127 qlInstrument->add(vanillaK);
128 qlInstrument->add(vanillaB, -1);
129 qlInstrument->add(digital, -1);
134 QL_FAIL(
"Unknown Barrier Type: " << barrierType);
136 }
else if (type == Option::Put) {
137 if (barrierType == Barrier::Type::UpIn || barrierType == Barrier::Type::DownOut) {
141 qlInstrument->add(vanillaK);
142 qlInstrument->add(vanillaB, -1);
143 qlInstrument->add(digital, -1);
145 }
else if (barrierType == Barrier::Type::UpOut || barrierType == Barrier::Type::DownIn) {
147 qlInstrument->add(vanillaK);
149 qlInstrument->add(vanillaB);
150 qlInstrument->add(digital);
153 QL_FAIL(
"Unknown Barrier Type: " << barrierType);
159 Real bsInd = (positionType == QuantLib::Position::Long ? 1.0 : -1.0);
161 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
162 std::vector<Real> additionalMultipliers;
163 Date lastPremiumDate =
167 instrument_ = QuantLib::ext::shared_ptr<InstrumentWrapper>(
173 maturity_ = std::max(lastPremiumDate, expiryDate);
183 QL_REQUIRE(eqNode,
"No EquityEuropeanBarrierOptionData Node");
194 WLOG(
"EquityOption::fromXML: node StrikeCurrency is deprecated, please us StrikeData node");
Engine builder for equity options.
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
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
const string & equityName() const
EquityUnderlying equityUnderlying_
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
const string & callPut() const
const string & longShort() const
const string & style() const
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const PremiumData & premiumData() const
const vector< string > & exerciseDates() const
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
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
std::map< std::string, boost::any > additionalData_
XMLNode * toXML(XMLDocument &doc) const
void setCurrency(const std::string ¤cy)
void fromXML(XMLNode *node, const bool isRequired=true, const bool allowYieldStrike=false)
QuantLib::Real value() const
Vanilla Instrument Wrapper.
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 European Barrier Option data model and serialization.
Equity Option data model and serialization.
Currency parseCurrencyWithMinors(const string &s)
Convert text to QuantLib::Currency.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
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.
Option::Type parseOptionType(const std::string &s)
Convert text to QuantLib::Option::Type.
Classes and functions for log message handling.
#define WLOG(text)
Logging Macro (Level = Warning)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.