22#include <boost/make_shared.hpp>
30#include <ql/errors.hpp>
31#include <ql/exercise.hpp>
32#include <ql/instruments/barrieroption.hpp>
33#include <ql/instruments/barriertype.hpp>
35#include <ql/instruments/compositeinstrument.hpp>
36#include <ql/instruments/vanillaoption.hpp>
38#include <ql/instruments/doublebarrieroption.hpp>
47 QL_REQUIRE(
tradeActions().empty(),
"TradeActions not supported for FxBarrierOption");
57 Date payDate = expiryDate;
60 if (opd->rulesBased()) {
61 Calendar payCalendar = opd->calendar();
62 payDate = payCalendar.advance(expiryDate, opd->lag(), Days, opd->convention());
64 if (opd->dates().size() > 1)
66 "Found more than 1 payment date. The first one will be used.")
68 payDate = opd->dates().front();
71 QL_REQUIRE(payDate >= expiryDate,
"Settlement date cannot be earlier than expiry date");
74 QL_REQUIRE(rebate >= 0,
"rebate must be non-negative");
83 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(
new PlainVanillaPayoff(type,
strike()));
85 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(expiryDate);
89 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
90 std::vector<Real> additionalMultipliers;
94 QuantLib::ext::shared_ptr<Instrument> vanilla;
95 QuantLib::ext::shared_ptr<Instrument>
barrier;
96 QuantLib::ext::shared_ptr<InstrumentWrapper> instWrapper;
98 bool exercised =
false;
99 Real exercisePrice = Null<Real>();
101 if (payDate > expiryDate) {
105 QL_REQUIRE(oed->date() == expiryDate,
"The supplied exercise date ("
106 << io::iso_date(oed->date())
107 <<
") should equal the option's expiry date ("
108 << io::iso_date(expiryDate) <<
").");
110 exercisePrice = oed->price();
113 QuantLib::ext::shared_ptr<Index> index;
116 QL_REQUIRE(index,
"Barrier option trade with delayed payment "
117 <<
id() <<
": the FXIndex node needs to be populated.");
120 vanilla = QuantLib::ext::make_shared<CashSettledEuropeanOption>(payoff->optionType(), payoff->strike(), expiryDate,
122 exercised, exercisePrice);
124 vanilla = QuantLib::ext::make_shared<VanillaOption>(payoff, exercise);
127 boost::variant<Barrier::Type, DoubleBarrier::Type> barrierType;
130 barrier = QuantLib::ext::make_shared<QuantLib::BarrierOption>(QuantLib::ext::get<Barrier::Type>(barrierType),
barrier_.
levels()[0].value(),
131 rebate, payoff, exercise);
134 barrier = QuantLib::ext::make_shared<QuantLib::DoubleBarrierOption>(QuantLib::ext::get<DoubleBarrier::Type>(barrierType),
138 QuantLib::ext::shared_ptr<QuantLib::PricingEngine> barrierEngine =
barrierPricingEngine(engineFactory, expiryDate, payDate);
139 QuantLib::ext::shared_ptr<QuantLib::PricingEngine> vanillaEngine =
vanillaPricingEngine(engineFactory, expiryDate, payDate);
142 barrier->setPricingEngine(barrierEngine);
143 vanilla->setPricingEngine(vanillaEngine);
145 QuantLib::ext::shared_ptr<QuantLib::Index> index =
getIndex();
146 const QuantLib::Handle<QuantLib::Quote>& spot =
spotQuote();
148 instWrapper = QuantLib::ext::make_shared<SingleBarrierOptionWrapper>(
149 barrier, positionType == Position::Long ?
true :
false, expiryDate,
150 settleType == Settlement::Physical ?
true :
false, vanilla, QuantLib::ext::get<Barrier::Type>(barrierType),
154 instWrapper = QuantLib::ext::make_shared<DoubleBarrierOptionWrapper>(
155 barrier, positionType == Position::Long ?
true :
false, expiryDate,
156 settleType == Settlement::Physical ?
true :
false, vanilla, QuantLib::ext::get<DoubleBarrier::Type>(barrierType),
162 Calendar fixingCal = index ? index->fixingCalendar() :
calendar_;
164 for (Date d = fixingCal.adjust(
startDate_); d <= expiryDate; d = fixingCal.advance(d, 1 * Days)) {
170 Real bsInd = (positionType == QuantLib::Position::Long ? 1.0 : -1.0);
179 QL_REQUIRE(dataNode,
"No " +
tradeType_ +
" Node");
229 QuantLib::Date expiryDate =
parseDate(
option().exerciseDates().front());
230 maturity_ = std::max(
option().premiumData().latestPremiumDate(), expiryDate);
260 additionalData_[
"isdaSubProduct"] = string(
"Price Return Basic Performance");
267 QuantLib::Date expiryDate =
parseDate(
option().exerciseDates().front());
268 maturity_ = std::max(
option().premiumData().latestPremiumDate(), expiryDate);
Barrier Option data model and serialization.
Wrapper for option instruments, tracks whether option has been exercised or not.
Engine builder for FX 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
virtual QuantLib::ext::shared_ptr< QuantLib::PricingEngine > vanillaPricingEngine(const QuantLib::ext::shared_ptr< EngineFactory > &ef, const QuantLib::Date &expiryDate, const QuantLib::Date &paymentDate)=0
const BarrierData & barrier() const
virtual std::string indexFixingName()=0
virtual QuantLib::Real tradeMultiplier()=0
const ore::data::OptionData & option() const
virtual Currency tradeCurrency()=0
ore::data::OptionData option_
void fromXML(ore::data::XMLNode *node) override
virtual void checkBarriers()=0
check validity of barriers
virtual void additionalToXml(ore::data::XMLDocument &doc, ore::data::XMLNode *node) const =0
QuantLib::Calendar calendar_
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
virtual QuantLib::ext::shared_ptr< QuantLib::PricingEngine > barrierPricingEngine(const QuantLib::ext::shared_ptr< EngineFactory > &ef, const QuantLib::Date &expiryDate, const QuantLib::Date &paymentDate)=0
virtual void additionalFromXml(ore::data::XMLNode *node)=0
void build(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
virtual const QuantLib::Handle< QuantLib::Quote > & spotQuote()=0
QuantLib::Date startDate_
virtual const QuantLib::Real strike()=0
virtual QuantLib::ext::shared_ptr< QuantLib::Index > getIndex()=0
void build(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &ef) override
void additionalFromXml(ore::data::XMLNode *node) override
QuantLib::Currency currency_
void additionalToXml(ore::data::XMLDocument &doc, ore::data::XMLNode *node) const override
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > eqIndex_
const string & equityName() const
EquityUnderlying equityUnderlying_
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
void build(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &ef) override
QuantLib::Real soldAmount_
QuantLib::ext::shared_ptr< QuantExt::FxIndex > fxIndex_
void additionalFromXml(ore::data::XMLNode *node) override
QuantLib::Real boughtAmount_
void additionalToXml(ore::data::XMLDocument &doc, ore::data::XMLNode *node) const override
QuantLib::Handle< QuantLib::Quote > spotQuote_
std::string indexFixingName() override
std::string soldCurrency_
std::string boughtCurrency_
void log() const
generate Boost log record to pass to corresponding sinks
const string & callPut() const
const string & longShort() const
const string & style() const
const string & settlement() const
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
bool isAutomaticExercise() const
Automatic exercise assumed false if not explicitly provided.
const boost::optional< OptionPaymentData > & paymentData() const
const boost::optional< OptionExerciseData > & exerciseData() const
const PremiumData & premiumData() const
const vector< string > & exerciseDates() const
QuantLib::Date latestPremiumDate() 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)
Utility classes for Structured warnings, contains the Trade ID and Type.
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)
virtual XMLNode * toXML(XMLDocument &doc) const override
RequiredFixings requiredFixings_
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
const string & tradeType() const
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
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)
FX 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.
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.
Settlement::Type parseSettlementType(const std::string &s)
Convert text to QuantLib::Settlement::Type.
Option::Type parseOptionType(const std::string &s)
Convert text to QuantLib::Option::Type.
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
market data related utilties
std::string to_string(const LocationInfo &l)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.
Classes for structured trade warnings.