37#include <ql/time/calendars/weekendsonly.hpp>
38#include <ql/time/daycounters/actual360.hpp>
41#include <boost/make_shared.hpp>
46 : side_(Protection::Buyer), nominal_(1.0), tenor_(tenor), termDate_(
boost::none), couponTenor_(3 * Months),
47 couponRate_(couponRate), upfrontRate_(0.0),
48 dayCounter_(Actual360()), lastPeriodDayCounter_(Actual360(true)),
49 rule_(DateGeneration::CDS2015), cashSettlementDays_(3), settlesAccrual_(true),
50 paysAtDefaultTime_(true), rebatesAccrual_(true) {}
53 : side_(Protection::Buyer), nominal_(1.0), tenor_(
boost::none), termDate_(termDate), couponTenor_(3 * Months),
54 couponRate_(couponRate), upfrontRate_(0.0),
55 dayCounter_(Actual360()), lastPeriodDayCounter_(Actual360(true)),
56 rule_(DateGeneration::CDS2015), cashSettlementDays_(3), settlesAccrual_(true),
57 paysAtDefaultTime_(true), rebatesAccrual_(true) {}
59MakeCreditDefaultSwap::operator CreditDefaultSwap()
const {
60 QuantLib::ext::shared_ptr<CreditDefaultSwap> swap = *
this;
64 MakeCreditDefaultSwap::operator QuantLib::ext::shared_ptr<QuantExt::CreditDefaultSwap>()
const {
66 Date tradeDate = Settings::instance().evaluationDate();
67 Date upfrontDate = WeekendsOnly().advance(tradeDate, cashSettlementDays_, Days);
70 if (rule_ == DateGeneration::CDS2015 || rule_ == DateGeneration::CDS) {
71 protectionStart = tradeDate;
73 protectionStart = tradeDate + 1;
78 if (rule_ == DateGeneration::CDS2015 || rule_ == DateGeneration::CDS || rule_ == DateGeneration::OldCDS) {
79 end = cdsMaturity(tradeDate, *tenor_, rule_);
81 end = tradeDate + *tenor_;
87 Schedule schedule(protectionStart, end, couponTenor_, WeekendsOnly(), Following, Unadjusted, rule_,
false);
89 CreditDefaultSwap::ProtectionPaymentTime timing = paysAtDefaultTime_ ?
90 CreditDefaultSwap::ProtectionPaymentTime::atDefault :
91 CreditDefaultSwap::ProtectionPaymentTime::atPeriodEnd;
92 QuantLib::ext::shared_ptr<CreditDefaultSwap> cds = QuantLib::ext::make_shared<CreditDefaultSwap>(
93 side_, nominal_, upfrontRate_, couponRate_, schedule, Following, dayCounter_, settlesAccrual_,
94 timing, protectionStart, upfrontDate, QuantLib::ext::shared_ptr<Claim>(),
95 lastPeriodDayCounter_, rebatesAccrual_, tradeDate, cashSettlementDays_);
QuantLib::ext::shared_ptr< PricingEngine > engine_
MakeCreditDefaultSwap & withPaysAtDefaultTime(bool)
MakeCreditDefaultSwap & withCouponTenor(Period)
MakeCreditDefaultSwap & withLastPeriodDayCounter(const DayCounter &)
MakeCreditDefaultSwap & withNominal(Real)
MakeCreditDefaultSwap & withRebatesAccrual(bool)
MakeCreditDefaultSwap & withPricingEngine(const QuantLib::ext::shared_ptr< PricingEngine > &)
Natural cashSettlementDays_
MakeCreditDefaultSwap & withDayCounter(const DayCounter &)
QuantLib::ext::shared_ptr< PricingEngine > engine_
MakeCreditDefaultSwap & withDateGenerationRule(DateGeneration::Rule rule)
DateGeneration::Rule rule_
MakeCreditDefaultSwap & withCashSettlementDays(Natural cashSettlementDays)
MakeCreditDefaultSwap(const Period &tenor, const Real couponRate)
MakeCreditDefaultSwap & withSide(Protection::Side)
DayCounter lastPeriodDayCounter_
MakeCreditDefaultSwap & withSettlesAccrual(bool)
MakeCreditDefaultSwap & withUpfrontRate(Real)
Helper class to instantiate standard market cds.