17#include <boost/make_shared.hpp>
28#include <ql/errors.hpp>
29#include <ql/exercise.hpp>
30#include <ql/instruments/barrieroption.hpp>
31#include <ql/instruments/compositeinstrument.hpp>
32#include <ql/instruments/swap.hpp>
33#include <ql/instruments/vanillaoption.hpp>
42 string domesticCurrency,
string payoffCurrency,
double payoffAmount,
43 string startDate,
string calendar,
string fxIndex)
46 barrier_(barrier), startDate_(startDate), calendar_(
calendar), fxIndex_(fxIndex), payoffAmount_(payoffAmount),
47 payoffCurrency_(payoffCurrency) {
49 switch (barrierType) {
50 case DoubleBarrier::KnockIn:
53 case DoubleBarrier::KnockOut:
57 QL_FAIL(
"unsupported barrier type " << barrierType);
76 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
80 QL_REQUIRE(
tradeActions().empty(),
"TradeActions not supported for FxOption");
82 QL_REQUIRE(
barrier_.
levels().size() == 2,
"Invalid number of barrier levels");
94 QL_REQUIRE(rebate == 0,
"Rebates not supported for FxDoubleTouchOptions");
95 if (payoffAtExpiry ==
false) {
96 payoffAtExpiry =
true;
97 DLOG(
"Payoff at hit not yet supported for FxDoubleTouchOptions, setting to payoff at expiry");
100 Date payDate = expiryDate;
103 if (opd->rulesBased()) {
104 payDate = opd->calendar().advance(expiryDate, opd->lag(), Days, opd->convention());
106 if (opd->dates().size() > 1)
108 "Found more than 1 payment date. The first one will be used.")
110 payDate = opd->dates().front();
113 QL_REQUIRE(payDate >= expiryDate,
"Settlement date cannot be earlier than expiry date");
118 QL_REQUIRE(levelLow < levelHigh,
"barrier levels are not in ascending order");
121 bool flipResults =
false;
124 levelLow = 1.0 / levelLow;
125 levelHigh = 1.0 / levelHigh;
126 std::swap(levelLow, levelHigh);
127 std::swap(fgnCcy, domCcy);
133 DLOG(
"Setting up FxDoubleTouchOption with level " << levelLow <<
", " << levelHigh <<
" foreign/bought " << fgnCcy
134 <<
" domestic/sold " << domCcy);
139 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(
new CashOrNothingPayoff(Option::Call, (levelLow + levelHigh) / 2, 1.0));
142 leg.push_back(QuantLib::ext::shared_ptr<CashFlow>(
new SimpleCashFlow(1.0, payDate)));
144 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(expiryDate);
146 QuantLib::ext::shared_ptr<Instrument> doubleTouch =
147 QuantLib::ext::make_shared<DoubleBarrierOption>(barrierType, levelLow, levelHigh, 0.0, payoff, exercise);
148 QuantLib::ext::shared_ptr<Instrument> underlying = QuantLib::ext::make_shared<Swap>(Leg(), leg);
150 QuantLib::ext::shared_ptr<QuantExt::FxIndex>
fxIndex;
156 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder(
tradeType_);
157 QL_REQUIRE(builder,
"No builder found for " <<
tradeType_);
158 QuantLib::ext::shared_ptr<FxDoubleTouchOptionEngineBuilder> fxDoubleTouchOptBuilder =
159 QuantLib::ext::dynamic_pointer_cast<FxDoubleTouchOptionEngineBuilder>(builder);
160 doubleTouch->setPricingEngine(fxDoubleTouchOptBuilder->engine(fgnCcy, domCcy, payDate, flipResults));
165 builder = engineFactory->builder(
"Swap");
166 QL_REQUIRE(builder,
"No builder found for Swap");
167 QuantLib::ext::shared_ptr<SwapEngineBuilderBase> swapBuilder =
168 QuantLib::ext::dynamic_pointer_cast<SwapEngineBuilderBase>(builder);
171 bool isLong = (positionType == Position::Long) ?
true :
false;
173 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
174 std::vector<Real> additionalMultipliers;
179 Handle<Quote> spot = market->fxSpot(fgnCcy.code() + domCcy.code());
180 instrument_ = QuantLib::ext::make_shared<DoubleBarrierOptionWrapper>(
181 doubleTouch, isLong, expiryDate,
false, underlying, barrierType, spot, levelLow, levelHigh, 0, domCcy,
186 if (start != Date()) {
187 for (Date d = start; d <= expiryDate; d = fixingCal.advance(d, 1 * Days))
195 case Barrier::DownIn:
196 case Barrier::DownOut:
202 QL_FAIL(
"unknown barrier type " <<
type);
209 QL_REQUIRE(fxNode,
"No FxDoubleTouchOptionData Node");
213 switch (barrierType) {
214 case DoubleBarrier::KnockIn:
217 case DoubleBarrier::KnockOut:
221 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.
const BarrierData & barrier() const
FxDoubleTouchOption()
Default constructor.
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const string & type() const
const string & fxIndex() 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 FX Derivaties.
std::string & domesticCurrency_
std::string & foreignCurrency_
void log() const
generate Boost log record to pass to corresponding sinks
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 boost::optional< OptionPaymentData > & paymentData() 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)
void setSensitivityTemplate(const EngineBuilder &builder)
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_
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 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)
market data related utilties
QuantLib::ext::shared_ptr< QuantExt::FxIndex > buildFxIndex(const string &fxIndex, const string &domestic, const string &foreign, const QuantLib::ext::shared_ptr< Market > &market, const string &configuration, bool useXbsCurves)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.
Classes for structured trade warnings.