Skip to content

Commit

Permalink
In some cases, schedule may not have a rule so check.
Browse files Browse the repository at this point in the history
  • Loading branch information
francis committed Nov 18, 2020
1 parent 24ca459 commit 6ad3d06
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ql/instruments/creditdefaultswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,15 @@ namespace QuantLib {

QL_REQUIRE(!schedule.empty(), "CreditDefaultSwap needs a non-empty schedule.");

DateGeneration::Rule rule = schedule.rule();
QL_REQUIRE((protectionStart_ <= schedule[0])
|| (rule == DateGeneration::CDS) || (rule == DateGeneration::CDS2015),
"protection can not start after accrual");
bool postBigBang = false;
if (schedule.hasRule()) {
DateGeneration::Rule rule = schedule.rule();
postBigBang = rule == DateGeneration::CDS || rule == DateGeneration::CDS2015;
}

if (!postBigBang) {
QL_REQUIRE(protectionStart_ <= schedule[0], "protection can not start after accrual");
}

leg_ = FixedRateLeg(schedule)
.withNotionals(notional_)
Expand All @@ -100,7 +105,7 @@ namespace QuantLib {

// Deduce the trade date if not given.
if (tradeDate_ == Date()) {
if (rule == DateGeneration::CDS2015 || rule == DateGeneration::CDS) {
if (postBigBang) {
tradeDate_ = protectionStart_;
} else {
tradeDate_ = protectionStart_ - 1;
Expand Down

0 comments on commit 6ad3d06

Please sign in to comment.