Build CDS option given that no default.
199 {
200
201 DLOG(
"CreditDefaultSwapOption: building CDS option trade " <<
id() <<
" given no default.");
202
203
204
205
206
208 QL_REQUIRE(legData.legType() == "Fixed", "CDS option " << id() << " requires fixed leg.");
209 auto fixedLegData = QuantLib::ext::dynamic_pointer_cast<FixedLegData>(legData.concreteLegData());
210 QL_REQUIRE(fixedLegData->rates().size() == 1, "Index CDS option " << id() << " requires single fixed rate.");
211 auto runningCoupon = fixedLegData->rates().front();
212
213
214 auto side = legData.isPayer() ? Protection::Side::Buyer : Protection::Side::Seller;
215
216
217
218 Actual360 standardDayCounter;
219 const std::string& strDc = legData.dayCounter();
220 DayCounter dc = strDc.empty() ? standardDayCounter :
parseDayCounter(strDc);
221 DayCounter lastPeriodDayCounter = dc == standardDayCounter ? Actual360(true) : dc;
222
223
225 BusinessDayConvention payConvention = legData.paymentConvention().empty() ? Following :
227
228
230 "Upfront fee on the CDS underlying a CDS option is not supported.");
231
232
233 auto cds = QuantLib::ext::make_shared<QuantLib::CreditDefaultSwap>(side,
notional_, runningCoupon, schedule,
236
237
238
240
241
242 auto cdsBuilder = QuantLib::ext::dynamic_pointer_cast<CreditDefaultSwapEngineBuilder>(
243 engineFactory->builder("CreditDefaultSwap"));
244 QL_REQUIRE(cdsBuilder, "CreditDefaultSwapOption expected CDS engine " <<
245 " builder for underlying while building trade " << id() << ".");
250
251
252 QL_REQUIRE(
option_.
style() ==
"European",
"CreditDefaultSwapOption option style must" <<
255 QL_REQUIRE(
option_.
exerciseFees().empty(),
"CreditDefaultSwapOption cannot handle exercise fees.");
256
257
259 QL_REQUIRE(exerciseDates.size() == 1, "CreditDefaultSwapOption expects one exercise date" <<
260 " but got " << exerciseDates.size() << " exercise dates.");
261 Date exerciseDate =
parseDate(exerciseDates.front());
262 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(exerciseDate);
263
264
267
268
270
271
273
274
275 auto cdsOptionEngineBuilder = QuantLib::ext::dynamic_pointer_cast<CreditDefaultSwapOptionEngineBuilder>(
276 engineFactory->builder("CreditDefaultSwapOption"));
277 QL_REQUIRE(cdsOptionEngineBuilder, "CreditDefaultSwapOption expected CDS option engine " <<
278 " builder for underlying while building trade " << id() << ".");
281
282
283 legs_ = { cds->coupons() };
286
287
288 vector<QuantLib::ext::shared_ptr<Instrument>> additionalInstruments;
289 vector<Real> additionalMultipliers;
291 addPremium(engineFactory, ccy, marketConfig, additionalInstruments, additionalMultipliers);
292
293
296
297
298
299
300 if (settleType == Settlement::Cash || exerciseDate <= Settings::instance().evaluationDate()) {
301 Real indicatorLongShort = positionType == Position::Long ? 1.0 : -1.0;
302 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(cdsOption, indicatorLongShort,
303 additionalInstruments, additionalMultipliers);
304 } else {
305 bool isLong = positionType == Position::Long;
306 bool isPhysical = settleType == Settlement::Physical;
307 instrument_ = QuantLib::ext::make_shared<EuropeanOptionWrapper>(cdsOption, isLong, exerciseDate,
308 isPhysical, cds, 1.0, 1.0, additionalInstruments, additionalMultipliers);
309 }
310}
QuantLib::Real recoveryRate() const
QuantLib::Natural cashSettlementDays() const
bool settlesAccrual() const
const QuantLib::Date & tradeDate() const
PPT protectionPaymentTime() const
const Date & protectionStart() const
const std::string & strikeType() const
QuantLib::Real strike() const
Date addPremium(const QuantLib::ext::shared_ptr< EngineFactory > &ef, const QuantLib::Currency &tradeCurrency, const std::string &marketConfig, std::vector< QuantLib::ext::shared_ptr< QuantLib::Instrument > > &additionalInstruments, std::vector< QuantLib::Real > &additionalMultipliers)
Add the premium payment.
const string & longShort() const
const string & style() const
const string & settlement() const
const bool & payoffAtExpiry() const
const PremiumData & premiumData() const
const vector< double > & exerciseFees() const
const vector< string > & exerciseDates() const
QuantLib::Date latestPremiumDate() const
std::vector< bool > legPayers_
std::vector< string > legCurrencies_
std::vector< QuantLib::Leg > legs_
void setSensitivityTemplate(const EngineBuilder &builder)
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
CdsOption::StrikeType parseCdsOptionStrikeType(const string &s)
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.
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
Settlement::Type parseSettlementType(const std::string &s)
Convert text to QuantLib::Settlement::Type.
DayCounter parseDayCounter(const string &s)
Convert text to QuantLib::DayCounter.
Schedule makeSchedule(const ScheduleDates &data)