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/vanillaoption.hpp>
40bool checkBarrier(Real spot, Barrier::Type type, Real barrier);
50 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
53 QL_REQUIRE(
tradeActions().empty(),
"TradeActions not supported for FxOption");
63 QL_REQUIRE(rebate >= 0,
"rebate must be non-negative");
65 QL_REQUIRE(level > 0.0 && level != Null<Real>(),
"Invalid level " << level);
74 bool flipResults =
false;
81 std::swap(boughtCcy, soldCcy);
82 type = type == Option::Call ? Option::Put : Option::Call;
83 switch (barrierType) {
85 barrierType = Barrier::UpIn;
88 barrierType = Barrier::DownIn;
90 case Barrier::DownOut:
91 barrierType = Barrier::UpOut;
94 barrierType = Barrier::DownOut;
102 DLOG(
"Setting up FxDigitalBarrierOption with strike " <<
strike <<
" level " << level <<
" foreign/bought "
103 << boughtCcy <<
" domestic/sold " << soldCcy);
120 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(expiryDate);
124 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(
new CashOrNothingPayoff(type,
strike,
payoffAmount_));
128 QuantLib::ext::shared_ptr<Instrument> vanilla = QuantLib::ext::make_shared<VanillaOption>(payoff, exercise);
129 QuantLib::ext::shared_ptr<Instrument>
barrier =
130 QuantLib::ext::make_shared<BarrierOption>(barrierType, level, rebate, payoff, exercise);
134 QuantLib::ext::shared_ptr<QuantExt::FxIndex>
fxIndex;
141 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder(
tradeType_);
142 QL_REQUIRE(builder,
"No builder found for " <<
tradeType_);
143 QuantLib::ext::shared_ptr<FxDigitalBarrierOptionEngineBuilder> fxBarrierOptBuilder =
144 QuantLib::ext::dynamic_pointer_cast<FxDigitalBarrierOptionEngineBuilder>(builder);
146 builder = engineFactory->builder(
"FxDigitalOption");
147 QL_REQUIRE(builder,
"No builder found for FxDigitalOption");
148 QuantLib::ext::shared_ptr<FxDigitalOptionEngineBuilder> fxOptBuilder =
149 QuantLib::ext::dynamic_pointer_cast<FxDigitalOptionEngineBuilder>(builder);
152 barrier->setPricingEngine(fxBarrierOptBuilder->engine(boughtCcy, soldCcy, expiryDate));
153 vanilla->setPricingEngine(fxOptBuilder->engine(boughtCcy, soldCcy, flipResults));
156 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 addPremiums(additionalInstruments, additionalMultipliers, positionType == Position::Long ? 1.0 : -1.0,
169 Handle<Quote> spot = market->fxSpot(boughtCcy.code() + soldCcy.code());
171 barrier, positionType == Position::Long ?
true :
false, expiryDate,
172 settleType == Settlement::Physical ?
true :
false, vanilla, barrierType, spot, level, rebate, soldCcy,
173 start,
fxIndex, cal, 1, 1, additionalInstruments, additionalMultipliers));
175 if (start != Date()) {
176 for (Date d = start; d <= expiryDate; d = cal.advance(d, 1 * Days)) {
184 case Barrier::DownIn:
185 case Barrier::DownOut:
186 return spot <= barrier;
189 return spot >= barrier;
191 QL_FAIL(
"unknown barrier type " << type);
198 QL_REQUIRE(fxNode,
"No FxDigitalBarrierOptionData Node");
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
const std::string & style() const
const BarrierData & barrier() const
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
const string & fxIndex() const
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
std::string & domesticCurrency_
std::string & foreignCurrency_
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
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)
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)
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
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.
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.
#define DLOG(text)
Logging Macro (Level = Debug)
market data related utilties
bool checkBarrier(Real spot, Barrier::Type type, Real barrier)
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.