From 6ad3d06e53e0ede0c44346fe56fb3925681b67a3 Mon Sep 17 00:00:00 2001 From: francis Date: Wed, 18 Nov 2020 15:17:20 +0000 Subject: [PATCH] In some cases, schedule may not have a rule so check. --- ql/instruments/creditdefaultswap.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ql/instruments/creditdefaultswap.cpp b/ql/instruments/creditdefaultswap.cpp index 2896cd66667..c57309c6686 100644 --- a/ql/instruments/creditdefaultswap.cpp +++ b/ql/instruments/creditdefaultswap.cpp @@ -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_) @@ -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;