• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lballabio / QuantLib / 23142641499

16 Mar 2026 12:02PM UTC coverage: 74.35% (+0.001%) from 74.349%
23142641499

push

github

lballabio
Automated fixes by clang-tidy

1 of 4 new or added lines in 3 files covered. (25.0%)

1 existing line in 1 file now uncovered.

58119 of 78169 relevant lines covered (74.35%)

8691593.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/ql/instruments/makecds.cpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
/*
4
 Copyright (C) 2014 Jose Aparicio
5
 Copyright (C) 2014 Peter Caspers
6

7
 This file is part of QuantLib, a free-software/open-source library
8
 for financial quantitative analysts and developers - http://quantlib.org/
9

10
 QuantLib is free software: you can redistribute it and/or modify it
11
 under the terms of the QuantLib license.  You should have received a
12
 copy of the license along with this program; if not, please email
13
 <quantlib-dev@lists.sf.net>. The license is also available online at
14
 <https://www.quantlib.org/license.shtml>.
15

16
 This program is distributed in the hope that it will be useful, but WITHOUT
17
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 FOR A PARTICULAR PURPOSE.  See the license for more details.
19
*/
20

21
#include <ql/instruments/makecds.hpp>
22
#include <ql/time/daycounters/actual360.hpp>
23
#include <ql/time/calendars/weekendsonly.hpp>
24
#include <utility>
25

26

27
namespace QuantLib {
28

29
    MakeCreditDefaultSwap::MakeCreditDefaultSwap(const Period& tenor,
12✔
30
                                                 Rate runningSpread)
12✔
31
    : tenor_(tenor), runningSpread_(runningSpread) {}
12✔
32

33
    MakeCreditDefaultSwap::MakeCreditDefaultSwap(const Date& termDate,
95✔
34
                                                 Rate runningSpread)
95✔
35
    : termDate_(termDate), runningSpread_(runningSpread) {}
95✔
36

37
    MakeCreditDefaultSwap::MakeCreditDefaultSwap(const Schedule& schedule,
1✔
38
                                                 Rate runningSpread)
1✔
39
    : schedule_(schedule), runningSpread_(runningSpread) {}
1✔
40

41

42
    MakeCreditDefaultSwap::operator CreditDefaultSwap() const {
10✔
43
        ext::shared_ptr<CreditDefaultSwap> swap = *this;
10✔
44
        return *swap;
20✔
45
    }
46

47
    MakeCreditDefaultSwap::operator ext::shared_ptr<CreditDefaultSwap>() const {
108✔
48

49
        Date tradeDate = tradeDate_ != Date() ? tradeDate_ : Settings::instance().evaluationDate();
108✔
50
        Date upfrontDate = upfrontDate_ != Date() ? upfrontDate_ : WeekendsOnly().advance(tradeDate, cashSettlementDays_, Days);
108✔
51

52
        Date protectionStart = protectionStart_;
108✔
53
        if (protectionStart == Date()) {
108✔
54
            if (schedule_) { // NOLINT(readability-implicit-bool-conversion)
107✔
55
                protectionStart = schedule_->at(0);
1✔
56
            } else {
57
                if (rule_ == DateGeneration::CDS2015 || rule_ == DateGeneration::CDS) {
106✔
58
                    protectionStart = tradeDate;
106✔
59
                } else {
60
                    protectionStart = tradeDate + 1;
×
61
                }
62
            }
63
        }
64

65
        // schedule, tenor and term date come from different constructors; exactly one of them is not null.
66
        Schedule schedule;
108✔
67
        if (schedule_) { // NOLINT(readability-implicit-bool-conversion)
108✔
68
            schedule = *schedule_;
1✔
69
        } else {
70
            Date end;
107✔
71
            if (tenor_) { // NOLINT(readability-implicit-bool-conversion)
107✔
72
                if (rule_ == DateGeneration::CDS2015 || rule_ == DateGeneration::CDS || rule_ == DateGeneration::OldCDS) {
12✔
73
                    end = cdsMaturity(tradeDate, *tenor_, rule_);
12✔
74
                } else {
75
                    end = tradeDate + *tenor_;
×
76
                }
77
            } else {
78
                end = *termDate_; // NOLINT(bugprone-unchecked-optional-access)
95✔
79
            }
80

81
            schedule = Schedule(protectionStart, end, couponTenor_, WeekendsOnly(), convention_,
321✔
82
                                Unadjusted, rule_, false);
214✔
83
        }
84

85
        auto cds = ext::make_shared<CreditDefaultSwap>(
86
            side_, nominal_, upfrontRate_, runningSpread_, schedule, convention_,
108✔
87
            dayCounter_, settlesAccrual_, paysAtDefaultTime_, protectionStart, upfrontDate,
108✔
88
            claim_, lastPeriodDayCounter_, rebatesAccrual_, tradeDate, cashSettlementDays_);
108✔
89

90
        cds->setPricingEngine(engine_);
108✔
91
        return cds;
108✔
92
    }
108✔
93

94

95
    MakeCreditDefaultSwap &
96
    MakeCreditDefaultSwap::withSide(Protection::Side side) {
40✔
97
        side_ = side;
40✔
98
        return *this;
40✔
99
    }
100

101
    MakeCreditDefaultSwap &MakeCreditDefaultSwap::withNominal(Real nominal) {
95✔
102
        nominal_ = nominal;
95✔
103
        return *this;
95✔
104
    }
105

106
    MakeCreditDefaultSwap &
107
    MakeCreditDefaultSwap::withUpfrontRate(Real upfrontRate) {
41✔
108
        upfrontRate_ = upfrontRate;
41✔
109
        return *this;
41✔
110
    }
111

112
    MakeCreditDefaultSwap &
113
    MakeCreditDefaultSwap::withCouponTenor(Period couponTenor) {
1✔
114
        couponTenor_ = couponTenor;
1✔
115
        return *this;
1✔
116
    }
117

118
    MakeCreditDefaultSwap& MakeCreditDefaultSwap::withDateGenerationRule(DateGeneration::Rule rule) {
×
119
        rule_ = rule;
×
120
        return *this;
×
121
    }
122

123
    MakeCreditDefaultSwap& MakeCreditDefaultSwap::withConvention(BusinessDayConvention convention) {
×
124
        convention_ = convention;
×
125
        return *this;
×
126
    }
127

128
    MakeCreditDefaultSwap &
129
    MakeCreditDefaultSwap::withDayCounter(const DayCounter& dayCounter) {
1✔
130
        dayCounter_ = dayCounter;
131
        return *this;
1✔
132
    }
133

134
    MakeCreditDefaultSwap &
135
    MakeCreditDefaultSwap::settleAccrual(bool b) {
1✔
136
        settlesAccrual_ = b;
1✔
137
        return *this;
1✔
138
    }
139

140
    MakeCreditDefaultSwap &
141
    MakeCreditDefaultSwap::payAtDefaultTime(bool b) {
1✔
142
        paysAtDefaultTime_ = b;
1✔
143
        return *this;
1✔
144
    }
145

146
    MakeCreditDefaultSwap& MakeCreditDefaultSwap::withProtectionStart(Date d) {
1✔
147
        protectionStart_ = d;
1✔
148
        return *this;
1✔
149
    }
150

151
    MakeCreditDefaultSwap& MakeCreditDefaultSwap::withUpfrontDate(Date d) {
1✔
152
        upfrontDate_ = d;
1✔
153
        return *this;
1✔
154
    }
155

156
    MakeCreditDefaultSwap& MakeCreditDefaultSwap::withClaim(ext::shared_ptr<Claim> claim) {
×
NEW
157
        claim_ = std::move(claim);
×
158
        return *this;
×
159
    }
160

161
    MakeCreditDefaultSwap &MakeCreditDefaultSwap::withLastPeriodDayCounter(
1✔
162
        const DayCounter& lastPeriodDayCounter) {
163
        lastPeriodDayCounter_ = lastPeriodDayCounter;
164
        return *this;
1✔
165
    }
166

167
    MakeCreditDefaultSwap &
168
    MakeCreditDefaultSwap::rebateAccrual(bool b) {
1✔
169
        rebatesAccrual_ = b;
1✔
170
        return *this;
1✔
171
    }
172

173
    MakeCreditDefaultSwap& MakeCreditDefaultSwap::withTradeDate(Date tradeDate) {
2✔
174
        tradeDate_ = tradeDate;
2✔
175
        return *this;
2✔
176
    }
177

178
    MakeCreditDefaultSwap& MakeCreditDefaultSwap::withCashSettlementDays(Natural cashSettlementDays) {
2✔
179
        cashSettlementDays_ = cashSettlementDays;
2✔
180
        return *this;
2✔
181
    }
182

183
    MakeCreditDefaultSwap &MakeCreditDefaultSwap::withPricingEngine(
62✔
184
                               const ext::shared_ptr<PricingEngine> &engine) {
185
        engine_ = engine;
62✔
186
        return *this;
62✔
187
    }
188

189
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc