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

lballabio / QuantLib / 18080105039

28 Sep 2025 09:31PM UTC coverage: 73.913% (-0.002%) from 73.915%
18080105039

push

github

web-flow
Explicit return type for lambdas to work with expression templates (#2338)

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

2 existing lines in 1 file now uncovered.

57060 of 77199 relevant lines covered (73.91%)

8757084.38 hits per line

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

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

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

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

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

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

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

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

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

117
        Schedule fixedSchedule(startDate, endDate,
118
                               Period(fixedPaymentFrequency),
3,248✔
119
                               fixedCalendar_,
120
                               fixedConvention_,
1,624✔
121
                               fixedTerminationDateConvention_,
1,624✔
122
                               fixedRule,
123
                               fixedEndOfMonth);
3,248✔
124

125
        Schedule overnightSchedule(startDate, endDate,
126
                                   Period(overnightPaymentFrequency),
3,248✔
127
                                   overnightCalendar_,
128
                                   overnightConvention_,
1,624✔
129
                                   overnightTerminationDateConvention_,
1,624✔
130
                                   overnightRule,
131
                                   overnightEndOfMonth);
3,248✔
132

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

156
            usedFixedRate = temp.fairRate();
×
157
        }
×
158

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

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

180
        return ois;
1,622✔
181
    }
1,626✔
182

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

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

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

198
    MakeOIS& MakeOIS::withSettlementDays(Natural settlementDays) {
435✔
199
        settlementDays_ = settlementDays;
435✔
200
        effectiveDate_ = Date();
435✔
201
        return *this;
435✔
202
    }
203

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

321
    MakeOIS& MakeOIS::withEndOfMonth(bool flag) {
×
322
        return withFixedLegEndOfMonth(flag).withOvernightLegEndOfMonth(flag);
×
323
    }
324

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

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

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

342
    MakeOIS& MakeOIS::withTelescopicValueDates(bool telescopicValueDates) {
1,017✔
343
        telescopicValueDates_ = telescopicValueDates;
1,017✔
344
        return *this;
1,017✔
345
    }
346

347
    MakeOIS& MakeOIS::withAveragingMethod(RateAveraging::Type averagingMethod) {
819✔
348
        averagingMethod_ = averagingMethod;
819✔
349
        return *this;
819✔
350
    }
351

352
    MakeOIS& MakeOIS::withLookbackDays(Natural lookbackDays) {
620✔
353
        lookbackDays_ = lookbackDays;
620✔
354
        return *this;
620✔
355
    }
356

357
    MakeOIS& MakeOIS::withLockoutDays(Natural lockoutDays) {
620✔
358
        lockoutDays_ = lockoutDays;
620✔
359
        return *this;
620✔
360
    }
361

362
    MakeOIS& MakeOIS::withObservationShift(bool applyObservationShift) {
620✔
363
        applyObservationShift_ = applyObservationShift;
620✔
364
        return *this;
620✔
365
    }
366

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