Build QuantLib/QuantExt instrument, link pricing engine.
61 {
62
63
68
71
75
76 const QuantLib::ext::shared_ptr<Market> market = engineFactory->market();
79
80 QL_REQUIRE(
tradeActions().empty(),
"TradeActions not supported for FxOption");
82 QL_REQUIRE(
barrier_.
levels().size() == 2,
"Invalid number of barrier levels");
84
85
93
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");
98 }
99
100 Date payDate = expiryDate;
102 if (opd) {
103 if (opd->rulesBased()) {
104 payDate = opd->calendar().advance(expiryDate, opd->lag(), Days, opd->convention());
105 } else {
106 if (opd->dates().size() > 1)
108 "Found more than 1 payment date. The first one will be used.")
110 payDate = opd->dates().front();
111 }
112 }
113 QL_REQUIRE(payDate >= expiryDate, "Settlement date cannot be earlier than expiry date");
115
118 QL_REQUIRE(levelLow < levelHigh, "barrier levels are not in ascending order");
119
120
121 bool flipResults = false;
123
124 levelLow = 1.0 / levelLow;
125 levelHigh = 1.0 / levelHigh;
126 std::swap(levelLow, levelHigh);
127 std::swap(fgnCcy, domCcy);
128 flipResults = true;
132 }
133 DLOG(
"Setting up FxDoubleTouchOption with level " << levelLow <<
", " << levelHigh <<
" foreign/bought " << fgnCcy
134 << " domestic/sold " << domCcy);
135
136
137
138
139 QuantLib::ext::shared_ptr<StrikedTypePayoff> payoff(new CashOrNothingPayoff(Option::Call, (levelLow + levelHigh) / 2, 1.0));
140 Leg leg;
141
142 leg.push_back(QuantLib::ext::shared_ptr<CashFlow>(new SimpleCashFlow(1.0, payDate)));
143
144 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(expiryDate);
145
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);
149
150 QuantLib::ext::shared_ptr<QuantExt::FxIndex>
fxIndex;
154
155
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));
162
163
164
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);
170
171 bool isLong = (positionType == Position::Long) ? true : false;
172
173 std::vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
174 std::vector<Real> additionalMultipliers;
178
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,
183
184
186 if (start != Date()) {
187 for (Date d = start; d <= expiryDate; d = fixingCal.advance(d, 1 * Days))
189 }
190
191}
std::vector< ore::data::TradeBarrier > levels() const
const std::string & style() const
std::string & domesticCurrency_
std::string & foreignCurrency_
void log() const
generate Boost log record to pass to corresponding sinks
const string & longShort() const
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.
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_
const string & tradeType() const
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.
#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)