3131#include < ql/quotes/simplequote.hpp>
3232#include < ql/math/solvers1d/brent.hpp>
3333#include < ql/time/calendars/weekendsonly.hpp>
34+ #include < iostream>
3435
3536namespace QuantLib {
3637
@@ -45,7 +46,7 @@ namespace QuantLib {
4546 const Date& protectionStart,
4647 const ext::shared_ptr<Claim>& claim,
4748 const DayCounter& lastPeriodDayCounter,
48- boost::optional< bool > rebatesAccrual,
49+ bool rebatesAccrual,
4950 const Date& tradeDate,
5051 Natural cashSettlementDays)
5152 : side_(side), notional_(notional), upfront_(boost::none),
@@ -72,7 +73,7 @@ namespace QuantLib {
7273 const Date& upfrontDate,
7374 const ext::shared_ptr<Claim>& claim,
7475 const DayCounter& lastPeriodDayCounter,
75- boost::optional< bool > rebatesAccrual,
76+ bool rebatesAccrual,
7677 const Date& tradeDate,
7778 Natural cashSettlementDays)
7879 : side_(side), notional_(notional), upfront_(upfront),
@@ -86,12 +87,20 @@ namespace QuantLib {
8687 init (schedule, convention, dayCounter, lastPeriodDayCounter, rebatesAccrual, upfrontDate);
8788 }
8889
89- CreditDefaultSwap::CreditDefaultSwap (Protection::Side side, Real notional, Rate spread, const Schedule& schedule,
90- BusinessDayConvention convention, const DayCounter& dayCounter,
91- bool settlesAccrual, ProtectionPaymentTime protectionPaymentTime,
92- const Date& protectionStart, const boost::shared_ptr<Claim>& claim,
93- const DayCounter& lastPeriodDayCounter, boost::optional<bool > rebatesAccrual,
94- const Date& tradeDate, Natural cashSettlementDays)
90+ CreditDefaultSwap::CreditDefaultSwap (Protection::Side side,
91+ Real notional,
92+ Rate spread,
93+ const Schedule& schedule,
94+ BusinessDayConvention convention,
95+ const DayCounter& dayCounter,
96+ bool settlesAccrual,
97+ ProtectionPaymentTime protectionPaymentTime,
98+ const Date& protectionStart,
99+ const boost::shared_ptr<Claim>& claim,
100+ const DayCounter& lastPeriodDayCounter,
101+ bool rebatesAccrual,
102+ const Date& tradeDate,
103+ Natural cashSettlementDays)
95104 : side_(side), notional_(notional), upfront_(boost::none), runningSpread_(spread), settlesAccrual_(settlesAccrual),
96105 paysAtDefaultTime_(protectionPaymentTime == atDefault ? true : false ),
97106 protectionPaymentTime_(protectionPaymentTime), claim_(claim),
@@ -101,13 +110,22 @@ namespace QuantLib {
101110 init (schedule, convention, dayCounter, lastPeriodDayCounter, rebatesAccrual);
102111 }
103112
104- CreditDefaultSwap::CreditDefaultSwap (Protection::Side side, Real notional, Rate upfront, Rate runningSpread,
105- const Schedule& schedule, BusinessDayConvention convention,
106- const DayCounter& dayCounter, bool settlesAccrual,
107- ProtectionPaymentTime protectionPaymentTime, const Date& protectionStart,
108- const Date& upfrontDate, const boost::shared_ptr<Claim>& claim,
109- const DayCounter& lastPeriodDayCounter, boost::optional<bool > rebatesAccrual,
110- const Date& tradeDate, Natural cashSettlementDays)
113+ CreditDefaultSwap::CreditDefaultSwap (Protection::Side side,
114+ Real notional,
115+ Rate upfront,
116+ Rate runningSpread,
117+ const Schedule& schedule,
118+ BusinessDayConvention convention,
119+ const DayCounter& dayCounter,
120+ bool settlesAccrual,
121+ ProtectionPaymentTime protectionPaymentTime,
122+ const Date& protectionStart,
123+ const Date& upfrontDate,
124+ const boost::shared_ptr<Claim>& claim,
125+ const DayCounter& lastPeriodDayCounter,
126+ bool rebatesAccrual,
127+ const Date& tradeDate,
128+ Natural cashSettlementDays)
111129 : side_(side), notional_(notional), upfront_(upfront), runningSpread_(runningSpread),
112130 settlesAccrual_(settlesAccrual),
113131 paysAtDefaultTime_(protectionPaymentTime == atDefault ? true : false ),
@@ -118,13 +136,21 @@ namespace QuantLib {
118136 init (schedule, convention, dayCounter, lastPeriodDayCounter, rebatesAccrual, upfrontDate);
119137 }
120138
121- CreditDefaultSwap::CreditDefaultSwap (Protection::Side side, Real notional, const Leg& amortized_leg, Rate spread,
122- const Schedule& schedule, BusinessDayConvention convention,
123- const DayCounter& dayCounter, bool settlesAccrual,
124- ProtectionPaymentTime protectionPaymentTime, const Date& protectionStart,
125- const boost::shared_ptr<Claim>& claim, const DayCounter& lastPeriodDayCounter,
126- boost::optional<bool > rebatesAccrual,
127- const Date& tradeDate, Natural cashSettlementDays)
139+ CreditDefaultSwap::CreditDefaultSwap (Protection::Side side,
140+ Real notional,
141+ const Leg& amortized_leg,
142+ Rate spread,
143+ const Schedule& schedule,
144+ BusinessDayConvention convention,
145+ const DayCounter& dayCounter,
146+ bool settlesAccrual,
147+ ProtectionPaymentTime protectionPaymentTime,
148+ const Date& protectionStart,
149+ const boost::shared_ptr<Claim>& claim,
150+ const DayCounter& lastPeriodDayCounter,
151+ bool rebatesAccrual,
152+ const Date& tradeDate,
153+ Natural cashSettlementDays)
128154 : side_(side), notional_(notional), upfront_(boost::none), runningSpread_(spread), settlesAccrual_(settlesAccrual),
129155 paysAtDefaultTime_(protectionPaymentTime == atDefault ? true : false ),
130156 protectionPaymentTime_(protectionPaymentTime), claim_(claim), leg_(amortized_leg),
@@ -134,13 +160,23 @@ namespace QuantLib {
134160 init (schedule, convention, dayCounter, lastPeriodDayCounter, rebatesAccrual);
135161 }
136162
137- CreditDefaultSwap::CreditDefaultSwap (Protection::Side side, Real notional, const Leg& amortized_leg, Rate upfront,
138- Rate runningSpread, const Schedule& schedule, BusinessDayConvention convention,
139- const DayCounter& dayCounter, bool settlesAccrual,
140- ProtectionPaymentTime protectionPaymentTime, const Date& protectionStart,
141- const Date& upfrontDate, const boost::shared_ptr<Claim>& claim,
142- const DayCounter& lastPeriodDayCounter, boost::optional<bool > rebatesAccrual,
143- const Date& tradeDate, Natural cashSettlementDays)
163+ CreditDefaultSwap::CreditDefaultSwap (Protection::Side side,
164+ Real notional,
165+ const Leg& amortized_leg,
166+ Rate upfront,
167+ Rate runningSpread,
168+ const Schedule& schedule,
169+ BusinessDayConvention convention,
170+ const DayCounter& dayCounter,
171+ bool settlesAccrual,
172+ ProtectionPaymentTime protectionPaymentTime,
173+ const Date& protectionStart,
174+ const Date& upfrontDate,
175+ const boost::shared_ptr<Claim>& claim,
176+ const DayCounter& lastPeriodDayCounter,
177+ bool rebatesAccrual,
178+ const Date& tradeDate,
179+ Natural cashSettlementDays)
144180 : side_(side), notional_(notional), upfront_(upfront), runningSpread_(runningSpread),
145181 settlesAccrual_(settlesAccrual),
146182 paysAtDefaultTime_(protectionPaymentTime == atDefault ? true : false ),
@@ -154,7 +190,7 @@ namespace QuantLib {
154190
155191 void CreditDefaultSwap::init (const Schedule& schedule, BusinessDayConvention paymentConvention,
156192 const DayCounter& dayCounter, const DayCounter& lastPeriodDayCounter,
157- boost::optional< bool > rebatesAccrual, const Date& upfrontDate) {
193+ bool rebatesAccrual, const Date& upfrontDate) {
158194
159195 QL_REQUIRE (!schedule.empty (), " CreditDefaultSwap needs a non-empty schedule." );
160196
@@ -204,8 +240,8 @@ namespace QuantLib {
204240 maturity_ = schedule.dates ().back ();
205241
206242 // Deal with the accrual rebate. We use the standard conventions for accrual calculation introduced with the
207- // CDS Big Bang in 2009, but the explicit rebatesAccrual argument dominates if provided.
208- if (rebatesAccrual ? *rebatesAccrual : postBigBang) {
243+ // CDS Big Bang in 2009
244+ if (rebatesAccrual && postBigBang) {
209245 accrualRebate_ = boost::make_shared<SimpleCashFlow>(CashFlows::accruedAmount (leg_, false , tradeDate_ + 1 ),
210246 effectiveUpfrontDate);
211247 Date current = std::max ((Date)Settings::instance ().evaluationDate (), tradeDate_);
@@ -443,22 +479,6 @@ namespace QuantLib {
443479 Handle<Quote>(flatRate), dayCounter));
444480
445481 ext::shared_ptr<PricingEngine> engine = buildPricingEngine (probability, recoveryRate, discountCurve, model);
446- // switch (model) {
447- // case Midpoint:
448- // engine = ext::make_shared<MidPointCdsEngine>(
449- // probability, recoveryRate, discountCurve);
450- // break;
451- // case ISDA:
452- // engine = ext::make_shared<IsdaCdsEngine>(
453- // probability, recoveryRate, discountCurve,
454- // boost::none,
455- // IsdaCdsEngine::Taylor,
456- // IsdaCdsEngine::HalfDayBias,
457- // IsdaCdsEngine::Piecewise);
458- // break;
459- // default:
460- // QL_FAIL("unknown CDS pricing model: " << model);
461- // }
462482
463483 setupArguments (engine->getArguments ());
464484 const CreditDefaultSwap::results* results =
@@ -580,4 +600,18 @@ namespace QuantLib {
580600 accrualRebateNPVCurrent = Null<Real>();
581601 }
582602
603+ std::ostream &operator <<(std::ostream &out,
604+ const CreditDefaultSwap::ProtectionPaymentTime &t) {
605+ if (t == CreditDefaultSwap::ProtectionPaymentTime::atDefault)
606+ out << " at default" ;
607+ else if (t == CreditDefaultSwap::ProtectionPaymentTime::atPeriodEnd)
608+ out << " at period end" ;
609+ else if (t == CreditDefaultSwap::ProtectionPaymentTime::atMaturity)
610+ out << " at maturity" ;
611+ else
612+ out << " unknown protection payment time" ;
613+
614+ return out;
615+ }
616+
583617}
0 commit comments