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

lballabio / QuantLib / 15548169004

10 Jun 2025 01:07AM UTC coverage: 73.367% (+0.002%) from 73.365%
15548169004

Pull #2241

github

web-flow
Merge dcdd743bd into 0c872a623
Pull Request #2241: Apply index-specific default settlement days in OISRateHelper

2 of 2 new or added lines in 1 file covered. (100.0%)

53 existing lines in 2 files now uncovered.

56301 of 76739 relevant lines covered (73.37%)

8670364.05 hits per line

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

70.95
/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
 <http://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,605✔
33
                     const ext::shared_ptr<OvernightIndex>& overnightIndex,
34
                     Rate fixedRate,
35
                     const Period& forwardStart)
1,605✔
36
    : swapTenor_(swapTenor), overnightIndex_(overnightIndex), fixedRate_(fixedRate),
1,605✔
37
      forwardStart_(forwardStart),
1,605✔
38
      settlementDays_(Null<Natural>()),
1,605✔
39
      fixedCalendar_(overnightIndex->fixingCalendar()),
1,605✔
40
      overnightCalendar_(overnightIndex->fixingCalendar()),
1,605✔
41
      fixedDayCount_(overnightIndex->dayCounter()) {}
4,815✔
42

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

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

50
        Date startDate;
1,605✔
51
        if (effectiveDate_ != Date())
1,605✔
52
            startDate = effectiveDate_;
1,180✔
53
        else {
54
            // settlement days: override if set, else fallback to default by index name
55
            Natural settlementDays = settlementDays_;
425✔
56
            if (settlementDays == Null<Natural>()) {
425✔
57
                if (ext::dynamic_pointer_cast<Sonia>(overnightIndex_) 
6✔
58
                    || ext::dynamic_pointer_cast<Corra>(overnightIndex_)) {
5✔
59
                    settlementDays = 0;
60
                } else {
61
                    settlementDays = 2;
62
                }
63
            }            
64

65
            Date refDate = Settings::instance().evaluationDate();
425✔
66
            // if the evaluation date is not a business day
67
            // then move to the next business day
68
            refDate = overnightCalendar_.adjust(refDate);
425✔
69
            Date spotDate = overnightCalendar_.advance(refDate,
425✔
70
                                                       settlementDays*Days);
425✔
71
            startDate = spotDate+forwardStart_;
425✔
72
            if (forwardStart_.length()<0)
425✔
UNCOV
73
                startDate = overnightCalendar_.adjust(startDate, Preceding);
×
74
            else
75
                startDate = overnightCalendar_.adjust(startDate, Following);
425✔
76
        }
77

78
        // OIS end of month default
79
        bool fixedEndOfMonth, overnightEndOfMonth;
80
        if (isDefaultEOM_)
1,605✔
81
            fixedEndOfMonth = overnightEndOfMonth = overnightCalendar_.isEndOfMonth(startDate);
1,605✔
82
        else {
UNCOV
83
            fixedEndOfMonth = fixedEndOfMonth_;
×
UNCOV
84
            overnightEndOfMonth = overnightEndOfMonth_;
×
85
        }
86

87
        Date endDate = terminationDate_;
1,605✔
88
        if (endDate == Date()) {
1,605✔
89
            if (overnightEndOfMonth)
1,597✔
UNCOV
90
                endDate = overnightCalendar_.advance(startDate,
×
UNCOV
91
                                                     swapTenor_,
×
92
                                                     ModifiedFollowing,
93
                                                     overnightEndOfMonth);
94
            else
95
                endDate = startDate + swapTenor_;
1,597✔
96
        }
97

98
        Frequency fixedPaymentFrequency, overnightPaymentFrequency;
99
        DateGeneration::Rule fixedRule, overnightRule;
100
        if (fixedPaymentFrequency_ == Once || fixedRule_ == DateGeneration::Zero) {
1,605✔
101
            fixedPaymentFrequency = Once;
102
            fixedRule = DateGeneration::Zero;
103
        } else {
104
            fixedPaymentFrequency = fixedPaymentFrequency_;
105
            fixedRule = fixedRule_;
106
        }
107
        if (overnightPaymentFrequency_ == Once || overnightRule_ == DateGeneration::Zero) {
1,605✔
108
            overnightPaymentFrequency = Once;
109
            overnightRule = DateGeneration::Zero;
110
        } else {
111
            overnightPaymentFrequency = overnightPaymentFrequency_;
112
            overnightRule = overnightRule_;
113
        }
114

115
        Schedule fixedSchedule(startDate, endDate,
116
                               Period(fixedPaymentFrequency),
3,210✔
117
                               fixedCalendar_,
118
                               fixedConvention_,
1,605✔
119
                               fixedTerminationDateConvention_,
1,605✔
120
                               fixedRule,
121
                               fixedEndOfMonth);
3,210✔
122

123
        Schedule overnightSchedule(startDate, endDate,
124
                                   Period(overnightPaymentFrequency),
3,210✔
125
                                   overnightCalendar_,
126
                                   overnightConvention_,
1,605✔
127
                                   overnightTerminationDateConvention_,
1,605✔
128
                                   overnightRule,
129
                                   overnightEndOfMonth);
3,210✔
130

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

UNCOV
154
            usedFixedRate = temp.fairRate();
×
155
        }
×
156

157
        ext::shared_ptr<OvernightIndexedSwap> ois(new
158
            OvernightIndexedSwap(type_, nominal_,
1,605✔
159
                                 fixedSchedule,
160
                                 usedFixedRate, fixedDayCount_,
161
                                 overnightSchedule,
162
                                 overnightIndex_, overnightSpread_,
1,605✔
163
                                 paymentLag_, paymentAdjustment_,
1,605✔
164
                                 paymentCalendar_, telescopicValueDates_, 
1,605✔
165
                                 averagingMethod_, lookbackDays_,
1,605✔
166
                                 lockoutDays_, applyObservationShift_));
4,817✔
167

168
        if (engine_ == nullptr) {
1,603✔
169
            Handle<YieldTermStructure> disc =
170
                                overnightIndex_->forwardingTermStructure();
582✔
171
            bool includeSettlementDateFlows = false;
172
            ext::shared_ptr<PricingEngine> engine(new
173
                DiscountingSwapEngine(disc, includeSettlementDateFlows));
582✔
174
            ois->setPricingEngine(engine);
582✔
175
        } else
176
            ois->setPricingEngine(engine_);
1,021✔
177

178
        return ois;
1,603✔
179
    }
1,607✔
180

UNCOV
181
    MakeOIS& MakeOIS::receiveFixed(bool flag) {
×
UNCOV
182
        type_ = flag ? Swap::Receiver : Swap::Payer ;
×
UNCOV
183
        return *this;
×
184
    }
185

186
    MakeOIS& MakeOIS::withType(Swap::Type type) {
576✔
187
        type_ = type;
576✔
188
        return *this;
576✔
189
    }
190

191
    MakeOIS& MakeOIS::withNominal(Real n) {
595✔
192
        nominal_ = n;
595✔
193
        return *this;
595✔
194
    }
195

196
    MakeOIS& MakeOIS::withSettlementDays(Natural settlementDays) {
429✔
197
        settlementDays_ = settlementDays;
429✔
198
        effectiveDate_ = Date();
429✔
199
        return *this;
429✔
200
    }
201

202
    MakeOIS& MakeOIS::withEffectiveDate(const Date& effectiveDate) {
1,600✔
203
        effectiveDate_ = effectiveDate;
1,600✔
204
        return *this;
1,600✔
205
    }
206

207
    MakeOIS& MakeOIS::withTerminationDate(const Date& terminationDate) {
428✔
208
        terminationDate_ = terminationDate;
428✔
209
        if (terminationDate != Date())
428✔
210
            swapTenor_ = Period();
8✔
211
        return *this;
428✔
212
    }
213

214
    MakeOIS& MakeOIS::withPaymentFrequency(Frequency f) {
1,004✔
215
        return withFixedLegPaymentFrequency(f).withOvernightLegPaymentFrequency(f);
1,004✔
216
    }
217

218
    MakeOIS& MakeOIS::withFixedLegPaymentFrequency(Frequency f) {
1,004✔
219
        fixedPaymentFrequency_ = f;
1,004✔
220
        return *this;
1,004✔
221
    }
222

223
    MakeOIS& MakeOIS::withOvernightLegPaymentFrequency(Frequency f) {
1,004✔
224
        overnightPaymentFrequency_ = f;
1,004✔
225
        return *this;
1,004✔
226
    }
227

228
    MakeOIS& MakeOIS::withPaymentAdjustment(BusinessDayConvention convention) {
427✔
229
        paymentAdjustment_ = convention;
427✔
230
        return *this;
427✔
231
    }
232

233
    MakeOIS& MakeOIS::withPaymentLag(Integer lag) {
1,022✔
234
        paymentLag_ = lag;
1,022✔
235
        return *this;
1,022✔
236
    }
237

238
    MakeOIS& MakeOIS::withPaymentCalendar(const Calendar& cal) {
427✔
239
        paymentCalendar_ = cal;
240
        return *this;
427✔
241
    }
242

UNCOV
243
    MakeOIS& MakeOIS::withCalendar(const Calendar& cal) {
×
UNCOV
244
        return withFixedLegCalendar(cal).withOvernightLegCalendar(cal);
×
245
    }
246

247
    MakeOIS& MakeOIS::withFixedLegCalendar(const Calendar& cal) {
3✔
248
        fixedCalendar_ = cal;
249
        return *this;
3✔
250
    }
251

252
    MakeOIS& MakeOIS::withOvernightLegCalendar(const Calendar& cal) {
3✔
253
        overnightCalendar_ = cal;
254
        return *this;
3✔
255
    }
256

257
    MakeOIS& MakeOIS::withRule(DateGeneration::Rule r) {
427✔
258
        return withFixedLegRule(r).withOvernightLegRule(r);
427✔
259
    }
260

261
    MakeOIS& MakeOIS::withFixedLegRule(DateGeneration::Rule r) {
427✔
262
        fixedRule_ = r;
427✔
263
        return *this;
427✔
264
    }
265

266
    MakeOIS& MakeOIS::withOvernightLegRule(DateGeneration::Rule r) {
427✔
267
        overnightRule_ = r;
427✔
268
        return *this;
427✔
269
    }
270

271
    MakeOIS& MakeOIS::withDiscountingTermStructure(
1,023✔
272
                                        const Handle<YieldTermStructure>& d) {
273
        bool includeSettlementDateFlows = false;
274
        engine_ = ext::shared_ptr<PricingEngine>(new
3,069✔
275
            DiscountingSwapEngine(d, includeSettlementDateFlows));
2,046✔
276
        return *this;
1,023✔
277
    }
278

UNCOV
279
    MakeOIS& MakeOIS::withPricingEngine(
×
280
                             const ext::shared_ptr<PricingEngine>& engine) {
UNCOV
281
        engine_ = engine;
×
282
        return *this;
×
283
    }
284

285
    MakeOIS& MakeOIS::withFixedLegDayCount(const DayCounter& dc) {
577✔
286
        fixedDayCount_ = dc;
287
        return *this;
577✔
288
    }
289

UNCOV
290
    MakeOIS& MakeOIS::withConvention(BusinessDayConvention bdc) {
×
UNCOV
291
        return withFixedLegConvention(bdc).withOvernightLegConvention(bdc);
×
292
    }
293

294
    MakeOIS& MakeOIS::withFixedLegConvention(BusinessDayConvention bdc) {
×
UNCOV
295
        fixedConvention_ = bdc;
×
UNCOV
296
        return *this;
×
297
    }
298

299
    MakeOIS& MakeOIS::withOvernightLegConvention(BusinessDayConvention bdc) {
×
UNCOV
300
        overnightConvention_ = bdc;
×
UNCOV
301
        return *this;
×
302
    }
303

304
    MakeOIS& MakeOIS::withTerminationDateConvention(BusinessDayConvention bdc) {
×
UNCOV
305
        withFixedLegTerminationDateConvention(bdc);
×
UNCOV
306
        return withOvernightLegTerminationDateConvention(bdc);
×
307
    }
308

309
    MakeOIS& MakeOIS::withFixedLegTerminationDateConvention(BusinessDayConvention bdc) {
×
UNCOV
310
        fixedTerminationDateConvention_ = bdc;
×
UNCOV
311
        return *this;
×
312
    }
313

314
    MakeOIS& MakeOIS::withOvernightLegTerminationDateConvention(BusinessDayConvention bdc) {
×
UNCOV
315
        overnightTerminationDateConvention_ = bdc;
×
UNCOV
316
        return *this;
×
317
    }
318

319
    MakeOIS& MakeOIS::withEndOfMonth(bool flag) {
×
UNCOV
320
        return withFixedLegEndOfMonth(flag).withOvernightLegEndOfMonth(flag);
×
321
    }
322

323
    MakeOIS& MakeOIS::withFixedLegEndOfMonth(bool flag) {
×
UNCOV
324
        fixedEndOfMonth_ = flag;
×
UNCOV
325
        isDefaultEOM_ = false;
×
326
        return *this;
×
327
    }
328

329
    MakeOIS& MakeOIS::withOvernightLegEndOfMonth(bool flag) {
×
UNCOV
330
        overnightEndOfMonth_ = flag;
×
UNCOV
331
        isDefaultEOM_ = false;
×
332
        return *this;
×
333
    }
334

335
    MakeOIS& MakeOIS::withOvernightLegSpread(Spread sp) {
397✔
336
        overnightSpread_ = sp;
397✔
337
        return *this;
397✔
338
    }
339

340
    MakeOIS& MakeOIS::withTelescopicValueDates(bool telescopicValueDates) {
1,022✔
341
        telescopicValueDates_ = telescopicValueDates;
1,022✔
342
        return *this;
1,022✔
343
    }
344

345
    MakeOIS& MakeOIS::withAveragingMethod(RateAveraging::Type averagingMethod) {
824✔
346
        averagingMethod_ = averagingMethod;
824✔
347
        return *this;
824✔
348
    }
349

350
    MakeOIS& MakeOIS::withLookbackDays(Natural lookbackDays) {
625✔
351
        lookbackDays_ = lookbackDays;
625✔
352
        return *this;
625✔
353
    }
354

355
    MakeOIS& MakeOIS::withLockoutDays(Natural lockoutDays) {
625✔
356
        lockoutDays_ = lockoutDays;
625✔
357
        return *this;
625✔
358
    }
359

360
    MakeOIS& MakeOIS::withObservationShift(bool applyObservationShift) {
625✔
361
        applyObservationShift_ = applyObservationShift;
625✔
362
        return *this;
625✔
363
    }
364

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