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

lballabio / QuantLib / 15995313367

01 Jul 2025 09:24AM UTC coverage: 73.816%. Remained the same
15995313367

push

github

web-flow
Optionlet frequency optional param support in `OptionletStripper`  (#2253)

10 of 11 new or added lines in 3 files covered. (90.91%)

2 existing lines in 1 file now uncovered.

56511 of 76557 relevant lines covered (73.82%)

8807317.87 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,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
      settlementDays_(Null<Natural>()),
1,624✔
39
      fixedCalendar_(overnightIndex->fixingCalendar()),
1,624✔
40
      overnightCalendar_(overnightIndex->fixingCalendar()),
1,624✔
41
      fixedDayCount_(overnightIndex->dayCounter()) {}
4,872✔
42

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

199
    MakeOIS& MakeOIS::withSettlementDays(Natural settlementDays) {
435✔
200
        settlementDays_ = settlementDays;
435✔
201
        effectiveDate_ = Date();
435✔
202
        return *this;
435✔
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) {
423✔
211
        terminationDate_ = terminationDate;
423✔
212
        if (terminationDate != Date())
423✔
213
            swapTenor_ = Period();
8✔
214
        return *this;
423✔
215
    }
216

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

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

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

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

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

241
    MakeOIS& MakeOIS::withPaymentCalendar(const Calendar& cal) {
422✔
242
        paymentCalendar_ = cal;
243
        return *this;
422✔
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) {
422✔
261
        return withFixedLegRule(r).withOvernightLegRule(r);
422✔
262
    }
263

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

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

274
    MakeOIS& MakeOIS::withDiscountingTermStructure(
1,018✔
275
                                        const Handle<YieldTermStructure>& d) {
276
        bool includeSettlementDateFlows = false;
277
        engine_ = ext::shared_ptr<PricingEngine>(new
3,054✔
278
            DiscountingSwapEngine(d, includeSettlementDateFlows));
2,036✔
279
        return *this;
1,018✔
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) {
×
294
        return withFixedLegConvention(bdc).withOvernightLegConvention(bdc);
×
295
    }
296

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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