Build QuantLib/QuantExt instrument, link pricing engine.
42 {
43
44
49
50 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
51
52
53 QL_REQUIRE(
tradeActions().empty(),
"TradeActions not supported for FxOption");
57
63 QL_REQUIRE(rebate >= 0, "rebate must be non-negative");
64
65 QL_REQUIRE(level > 0.0 && level != Null<Real>(), "Invalid level " << level);
66
67
71
72
74 bool flipResults = false;
78
80 level = 1.0 / level;
81 std::swap(boughtCcy, soldCcy);
82 type = type == Option::Call ? Option::Put : Option::Call;
83 switch (barrierType) {
84 case Barrier::DownIn:
85 barrierType = Barrier::UpIn;
86 break;
87 case Barrier::UpIn:
88 barrierType = Barrier::DownIn;
89 break;
90 case Barrier::DownOut:
91 barrierType = Barrier::UpOut;
92 break;
93 case Barrier::UpOut:
94 barrierType = Barrier::DownOut;
95 break;
96 }
97 flipResults = true;
101 }
102 DLOG(
"Setting up FxDigitalBarrierOption with strike " <<
strike <<
" level " << level <<
" foreign/bought "
103 << boughtCcy << " domestic/sold " << soldCcy);
104
105
106
107
112
116
117
118
120 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(expiryDate);
122
123
124 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(
new CashOrNothingPayoff(type,
strike,
payoffAmount_));
125
126
127
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);
131
132
134 QuantLib::ext::shared_ptr<QuantExt::FxIndex>
fxIndex;
138
139
140
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);
145
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);
151
152 barrier->setPricingEngine(fxBarrierOptBuilder->engine(boughtCcy, soldCcy, expiryDate));
153 vanilla->setPricingEngine(fxOptBuilder->engine(boughtCcy, soldCcy, flipResults));
154
156 Real bsInd = (positionType == QuantLib::Position::Long ? 1.0 : -1.0);
157
158
159
160
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,
166
168
169 Handle<Quote> spot = market->fxSpot(boughtCcy.code() + soldCcy.code());
170 instrument_ = QuantLib::ext::shared_ptr<InstrumentWrapper>(
new SingleBarrierOptionWrapper(
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));
174
175 if (start != Date()) {
176 for (Date d = start; d <= expiryDate; d = cal.advance(d, 1 * Days)) {
178 }
179 }
180}
const std::string & type() const
std::vector< ore::data::TradeBarrier > levels() const
const std::string & style() const
std::string & domesticCurrency_
std::string & foreignCurrency_
const string & callPut() const
const string & longShort() const
const string & style() const
const string & settlement() 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)
TradeActions & tradeActions()
Set the trade actions.
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)
RequiredFixings requiredFixings_
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
std::map< std::string, boost::any > additionalData_
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.
#define DLOG(text)
Logging Macro (Level = Debug)
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)