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

lballabio / QuantLib / 23745403900

30 Mar 2026 12:46PM UTC coverage: 74.417% (-0.002%) from 74.419%
23745403900

push

github

lballabio
Avoid or silence a few clang-tidy warnings

4 of 5 new or added lines in 2 files covered. (80.0%)

1 existing line in 1 file now uncovered.

58224 of 78240 relevant lines covered (74.42%)

8784240.69 hits per line

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

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

3
/*
4
 Copyright (C) 2009, 2014, 2015 Ferdinando Ametrano
5
 Copyright (C) 2015 Paolo Mazzocchi
6
 Copyright (C) 2017 Joseph Jeisman
7
 Copyright (C) 2017 Fabrice Lecuyer
8

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

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

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

23
#include <ql/instruments/makeois.hpp>
24
#include <ql/pricingengines/swap/discountingswapengine.hpp>
25
#include <ql/indexes/iborindex.hpp>
26
#include <ql/time/schedule.hpp>
27
#include <ql/indexes/ibor/sonia.hpp>
28
#include <ql/indexes/ibor/corra.hpp>
29

30
namespace QuantLib {
31

32
    MakeOIS::MakeOIS(const Period& swapTenor,
1,627✔
33
                     const ext::shared_ptr<OvernightIndex>& overnightIndex,
34
                     Rate fixedRate,
35
                     const Period& forwardStart)
1,627✔
36
    : swapTenor_(swapTenor), overnightIndex_(overnightIndex), fixedRate_(fixedRate),
1,627✔
37
      forwardStart_(forwardStart),
1,627✔
38
      fixedCalendar_(overnightIndex->fixingCalendar()),
1,627✔
39
      overnightCalendar_(overnightIndex->fixingCalendar()),
1,627✔
40
      fixedDayCount_(overnightIndex->dayCounter()) {}
4,881✔
41

42
    MakeOIS::operator OvernightIndexedSwap() const {
30✔
43
        ext::shared_ptr<OvernightIndexedSwap> ois = *this;
30✔
44
        return *ois;
60✔
45
    }
46

47
    MakeOIS::operator ext::shared_ptr<OvernightIndexedSwap>() const {
1,627✔
48

49
        QL_REQUIRE(effectiveDate_ == Date() || settlementDays_ == Null<Natural>(),
1,631✔
50
                   "cannot set both an explicit effective date and settlement days; "
51
                   "use one or the other");
52

53
        Date startDate;
1,625✔
54
        if (effectiveDate_ != Date())
1,625✔
55
            startDate = effectiveDate_;
1,179✔
56
        else {
57
            // settlement days: override if set, else fallback to default by index name
58
            Natural settlementDays = settlementDays_;
446✔
59
            if (settlementDays == Null<Natural>()) {
446✔
60
                if (ext::dynamic_pointer_cast<Sonia>(overnightIndex_)) {
34✔
61
                    settlementDays = 0; 
62
                }
63
                else if (ext::dynamic_pointer_cast<Corra>(overnightIndex_)) {
30✔
64
                    settlementDays = 1;
65
                }
66
                else {
67
                    settlementDays = 2;
68
                }
69
            }            
70

71
            Date refDate = Settings::instance().evaluationDate();
446✔
72
            // if the evaluation date is not a business day
73
            // then move to the next business day
74
            refDate = overnightCalendar_.adjust(refDate);
446✔
75
            Date spotDate = overnightCalendar_.advance(refDate,
446✔
76
                                                       settlementDays*Days);
446✔
77
            startDate = spotDate+forwardStart_;
446✔
78
            if (forwardStart_.length()<0)
446✔
79
                startDate = overnightCalendar_.adjust(startDate, Preceding);
×
80
            else
81
                startDate = overnightCalendar_.adjust(startDate, Following);
446✔
82
        }
83

84
        bool fixedEndOfMonth, overnightEndOfMonth, maturityEndOfMonth;
85
        if (isDefaultEOM_)
1,625✔
86
            fixedEndOfMonth = overnightEndOfMonth = maturityEndOfMonth =
87
                overnightCalendar_.isEndOfMonth(startDate);
1,624✔
88
        else {
89
            fixedEndOfMonth = fixedEndOfMonth_;
1✔
90
            overnightEndOfMonth = overnightEndOfMonth_;
1✔
91
            maturityEndOfMonth = maturityEndOfMonth_ ? *maturityEndOfMonth_ : overnightEndOfMonth_;
1✔
92
        }
93

94
        Date endDate = terminationDate_;
1,625✔
95
        if (endDate == Date()) {
1,625✔
96
            endDate = startDate + swapTenor_;
1,619✔
97
            if (maturityEndOfMonth && allowsEndOfMonth(swapTenor_) &&
1,620✔
98
                overnightCalendar_.isEndOfMonth(startDate))
1✔
UNCOV
99
                endDate = overnightCalendar_.endOfMonth(endDate);
×
100
        }
101

102
        Frequency fixedPaymentFrequency, overnightPaymentFrequency;
103
        DateGeneration::Rule fixedRule, overnightRule;
104
        if (fixedPaymentFrequency_ == Once || fixedRule_ == DateGeneration::Zero) {
1,625✔
105
            fixedPaymentFrequency = Once;
106
            fixedRule = DateGeneration::Zero;
107
        } else {
108
            fixedPaymentFrequency = fixedPaymentFrequency_;
109
            fixedRule = fixedRule_;
110
        }
111
        if (overnightPaymentFrequency_ == Once || overnightRule_ == DateGeneration::Zero) {
1,625✔
112
            overnightPaymentFrequency = Once;
113
            overnightRule = DateGeneration::Zero;
114
        } else {
115
            overnightPaymentFrequency = overnightPaymentFrequency_;
116
            overnightRule = overnightRule_;
117
        }
118

119
        Schedule fixedSchedule(startDate, endDate,
120
                               Period(fixedPaymentFrequency),
3,250✔
121
                               fixedCalendar_,
122
                               fixedConvention_,
1,625✔
123
                               fixedTerminationDateConvention_,
1,625✔
124
                               fixedRule,
125
                               fixedEndOfMonth);
3,250✔
126

127
        Schedule overnightSchedule(startDate, endDate,
128
                                   Period(overnightPaymentFrequency),
3,250✔
129
                                   overnightCalendar_,
130
                                   overnightConvention_,
1,625✔
131
                                   overnightTerminationDateConvention_,
1,625✔
132
                                   overnightRule,
133
                                   overnightEndOfMonth);
3,250✔
134

135
        Rate usedFixedRate = fixedRate_;
1,625✔
136
        if (fixedRate_ == Null<Rate>()) {
1,625✔
137
            OvernightIndexedSwap temp(type_, nominal_,
1✔
138
                                      fixedSchedule,
139
                                      0.0, // fixed rate
140
                                      fixedDayCount_,
141
                                      overnightSchedule,
142
                                      overnightIndex_, overnightSpread_,
1✔
143
                                      paymentLag_, paymentAdjustment_,
1✔
144
                                      paymentCalendar_, telescopicValueDates_);
3✔
145
            if (engine_ == nullptr) {
1✔
146
                Handle<YieldTermStructure> disc =
147
                                    overnightIndex_->forwardingTermStructure();
1✔
148
                QL_REQUIRE(!disc.empty(),
1✔
149
                           "null term structure set to this instance of " <<
150
                           overnightIndex_->name());
151
                bool includeSettlementDateFlows = false;
152
                ext::shared_ptr<PricingEngine> engine(new
153
                    DiscountingSwapEngine(disc, includeSettlementDateFlows));
1✔
154
                temp.setPricingEngine(engine);
1✔
155
            } else
156
                temp.setPricingEngine(engine_);
×
157

158
            usedFixedRate = temp.fairRate();
1✔
159
        }
1✔
160

161
        ext::shared_ptr<OvernightIndexedSwap> ois(new
162
            OvernightIndexedSwap(type_, nominal_,
1,625✔
163
                                 fixedSchedule,
164
                                 usedFixedRate, fixedDayCount_,
165
                                 overnightSchedule,
166
                                 overnightIndex_, overnightSpread_,
1,625✔
167
                                 paymentLag_, paymentAdjustment_,
1,625✔
168
                                 paymentCalendar_, telescopicValueDates_, 
1,625✔
169
                                 averagingMethod_, lookbackDays_,
1,625✔
170
                                 lockoutDays_, applyObservationShift_));
4,877✔
171

172
        if (engine_ == nullptr) {
1,623✔
173
            Handle<YieldTermStructure> disc =
174
                                overnightIndex_->forwardingTermStructure();
610✔
175
            bool includeSettlementDateFlows = false;
176
            ext::shared_ptr<PricingEngine> engine(new
177
                DiscountingSwapEngine(disc, includeSettlementDateFlows));
610✔
178
            ois->setPricingEngine(engine);
610✔
179
        } else
180
            ois->setPricingEngine(engine_);
1,013✔
181

182
        return ois;
1,623✔
183
    }
1,627✔
184

185
    MakeOIS& MakeOIS::receiveFixed(bool flag) {
×
186
        type_ = flag ? Swap::Receiver : Swap::Payer ;
×
187
        return *this;
×
188
    }
189

190
    MakeOIS& MakeOIS::withType(Swap::Type type) {
576✔
191
        type_ = type;
576✔
192
        return *this;
576✔
193
    }
194

195
    MakeOIS& MakeOIS::withNominal(Real n) {
595✔
196
        nominal_ = n;
595✔
197
        return *this;
595✔
198
    }
199

200
    MakeOIS& MakeOIS::withSettlementDays(Natural settlementDays) {
431✔
201
        settlementDays_ = settlementDays;
431✔
202
        return *this;
431✔
203
    }
204

205
    MakeOIS& MakeOIS::withEffectiveDate(const Date& effectiveDate) {
1,595✔
206
        effectiveDate_ = effectiveDate;
1,595✔
207
        return *this;
1,595✔
208
    }
209

210
    MakeOIS& MakeOIS::withTerminationDate(const Date& terminationDate) {
420✔
211
        terminationDate_ = terminationDate;
420✔
212
        if (terminationDate != Date())
420✔
213
            swapTenor_ = Period();
6✔
214
        return *this;
420✔
215
    }
216

217
    MakeOIS& MakeOIS::withPaymentFrequency(Frequency f) {
997✔
218
        return withFixedLegPaymentFrequency(f).withOvernightLegPaymentFrequency(f);
997✔
219
    }
220

221
    MakeOIS& MakeOIS::withFixedLegPaymentFrequency(Frequency f) {
997✔
222
        fixedPaymentFrequency_ = f;
997✔
223
        return *this;
997✔
224
    }
225

226
    MakeOIS& MakeOIS::withOvernightLegPaymentFrequency(Frequency f) {
997✔
227
        overnightPaymentFrequency_ = f;
997✔
228
        return *this;
997✔
229
    }
230

231
    MakeOIS& MakeOIS::withPaymentAdjustment(BusinessDayConvention convention) {
420✔
232
        paymentAdjustment_ = convention;
420✔
233
        return *this;
420✔
234
    }
235

236
    MakeOIS& MakeOIS::withPaymentLag(Integer lag) {
1,015✔
237
        paymentLag_ = lag;
1,015✔
238
        return *this;
1,015✔
239
    }
240

241
    MakeOIS& MakeOIS::withPaymentCalendar(const Calendar& cal) {
420✔
242
        paymentCalendar_ = cal;
243
        return *this;
420✔
244
    }
245

246
    MakeOIS& MakeOIS::withCalendar(const Calendar& cal) {
×
247
        return withFixedLegCalendar(cal).withOvernightLegCalendar(cal);
×
248
    }
249

250
    MakeOIS& MakeOIS::withFixedLegCalendar(const Calendar& cal) {
3✔
251
        fixedCalendar_ = cal;
252
        return *this;
3✔
253
    }
254

255
    MakeOIS& MakeOIS::withOvernightLegCalendar(const Calendar& cal) {
3✔
256
        overnightCalendar_ = cal;
257
        return *this;
3✔
258
    }
259

260
    MakeOIS& MakeOIS::withRule(DateGeneration::Rule r) {
420✔
261
        return withFixedLegRule(r).withOvernightLegRule(r);
420✔
262
    }
263

264
    MakeOIS& MakeOIS::withFixedLegRule(DateGeneration::Rule r) {
420✔
265
        fixedRule_ = r;
420✔
266
        return *this;
420✔
267
    }
268

269
    MakeOIS& MakeOIS::withOvernightLegRule(DateGeneration::Rule r) {
420✔
270
        overnightRule_ = r;
420✔
271
        return *this;
420✔
272
    }
273

274
    MakeOIS& MakeOIS::withDiscountingTermStructure(
1,015✔
275
                                        const Handle<YieldTermStructure>& d) {
276
        bool includeSettlementDateFlows = false;
277
        engine_ = ext::shared_ptr<PricingEngine>(new
3,045✔
278
            DiscountingSwapEngine(d, includeSettlementDateFlows));
2,030✔
279
        return *this;
1,015✔
280
    }
281

282
    MakeOIS& MakeOIS::withPricingEngine(
×
283
                             const ext::shared_ptr<PricingEngine>& engine) {
284
        engine_ = engine;
×
285
        return *this;
×
286
    }
287

288
    MakeOIS& MakeOIS::withFixedLegDayCount(const DayCounter& dc) {
577✔
289
        fixedDayCount_ = dc;
290
        return *this;
577✔
291
    }
292

293
    MakeOIS& MakeOIS::withConvention(BusinessDayConvention bdc) {
420✔
294
        return withFixedLegConvention(bdc).withOvernightLegConvention(bdc);
420✔
295
    }
296

297
    MakeOIS& MakeOIS::withFixedLegConvention(BusinessDayConvention bdc) {
420✔
298
        fixedConvention_ = bdc;
420✔
299
        return *this;
420✔
300
    }
301

302
    MakeOIS& MakeOIS::withOvernightLegConvention(BusinessDayConvention bdc) {
420✔
303
        overnightConvention_ = bdc;
420✔
304
        return *this;
420✔
305
    }
306

307
    MakeOIS& MakeOIS::withTerminationDateConvention(BusinessDayConvention bdc) {
420✔
308
        withFixedLegTerminationDateConvention(bdc);
420✔
309
        return withOvernightLegTerminationDateConvention(bdc);
420✔
310
    }
311

312
    MakeOIS& MakeOIS::withFixedLegTerminationDateConvention(BusinessDayConvention bdc) {
420✔
313
        fixedTerminationDateConvention_ = bdc;
420✔
314
        return *this;
420✔
315
    }
316

317
    MakeOIS& MakeOIS::withOvernightLegTerminationDateConvention(BusinessDayConvention bdc) {
420✔
318
        overnightTerminationDateConvention_ = bdc;
420✔
319
        return *this;
420✔
320
    }
321

322
    MakeOIS& MakeOIS::withEndOfMonth(bool flag) {
1✔
323
        return withFixedLegEndOfMonth(flag).withOvernightLegEndOfMonth(flag);
1✔
324
    }
325

326
    MakeOIS& MakeOIS::withFixedLegEndOfMonth(bool flag) {
1✔
327
        fixedEndOfMonth_ = flag;
1✔
328
        isDefaultEOM_ = false;
1✔
329
        return *this;
1✔
330
    }
331

332
    MakeOIS& MakeOIS::withOvernightLegEndOfMonth(bool flag) {
1✔
333
        overnightEndOfMonth_ = flag;
1✔
334
        isDefaultEOM_ = false;
1✔
335
        return *this;
1✔
336
    }
337

338
    MakeOIS& MakeOIS::withMaturityEndOfMonth(bool flag) {
×
339
        maturityEndOfMonth_ = flag;
×
340
        isDefaultEOM_ = false;
×
341
        return *this;
×
342
    }
343

344
    MakeOIS& MakeOIS::withOvernightLegSpread(Spread sp) {
397✔
345
        overnightSpread_ = sp;
397✔
346
        return *this;
397✔
347
    }
348

349
    MakeOIS& MakeOIS::withTelescopicValueDates(bool telescopicValueDates) {
1,015✔
350
        telescopicValueDates_ = telescopicValueDates;
1,015✔
351
        return *this;
1,015✔
352
    }
353

354
    MakeOIS& MakeOIS::withAveragingMethod(RateAveraging::Type averagingMethod) {
817✔
355
        averagingMethod_ = averagingMethod;
817✔
356
        return *this;
817✔
357
    }
358

359
    MakeOIS& MakeOIS::withLookbackDays(Natural lookbackDays) {
618✔
360
        lookbackDays_ = lookbackDays;
618✔
361
        return *this;
618✔
362
    }
363

364
    MakeOIS& MakeOIS::withLockoutDays(Natural lockoutDays) {
618✔
365
        lockoutDays_ = lockoutDays;
618✔
366
        return *this;
618✔
367
    }
368

369
    MakeOIS& MakeOIS::withObservationShift(bool applyObservationShift) {
618✔
370
        applyObservationShift_ = applyObservationShift;
618✔
371
        return *this;
618✔
372
    }
373

374
}
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