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

lballabio / QuantLib / 12584830276

02 Jan 2025 03:34PM UTC coverage: 73.176% (+0.003%) from 73.173%
12584830276

push

github

web-flow
deal with removable singularity (#2126)

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

2 existing lines in 1 file now uncovered.

56073 of 76628 relevant lines covered (73.18%)

8672535.02 hits per line

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

66.09
/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

28
namespace QuantLib {
29

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

40
    MakeOIS::operator OvernightIndexedSwap() const {
×
41
        ext::shared_ptr<OvernightIndexedSwap> ois = *this;
×
42
        return *ois;
×
43
    }
44

45
    MakeOIS::operator ext::shared_ptr<OvernightIndexedSwap>() const {
1,592✔
46

47
        Date startDate;
1,592✔
48
        if (effectiveDate_ != Date())
1,592✔
49
            startDate = effectiveDate_;
1,180✔
50
        else {
51
            Date refDate = Settings::instance().evaluationDate();
412✔
52
            // if the evaluation date is not a business day
53
            // then move to the next business day
54
            refDate = overnightCalendar_.adjust(refDate);
412✔
55
            Date spotDate = overnightCalendar_.advance(refDate,
412✔
56
                                                       settlementDays_*Days);
412✔
57
            startDate = spotDate+forwardStart_;
412✔
58
            if (forwardStart_.length()<0)
412✔
59
                startDate = overnightCalendar_.adjust(startDate, Preceding);
×
60
            else
61
                startDate = overnightCalendar_.adjust(startDate, Following);
412✔
62
        }
63

64
        // OIS end of month default
65
        bool fixedEndOfMonth, overnightEndOfMonth;
66
        if (isDefaultEOM_)
1,592✔
67
            fixedEndOfMonth = overnightEndOfMonth = overnightCalendar_.isEndOfMonth(startDate);
1,592✔
68
        else {
69
            fixedEndOfMonth = fixedEndOfMonth_;
×
70
            overnightEndOfMonth = overnightEndOfMonth_;
×
71
        }
72

73
        Date endDate = terminationDate_;
1,592✔
74
        if (endDate == Date()) {
1,592✔
75
            if (overnightEndOfMonth)
1,584✔
UNCOV
76
                endDate = overnightCalendar_.advance(startDate,
×
UNCOV
77
                                                     swapTenor_,
×
78
                                                     ModifiedFollowing,
79
                                                     overnightEndOfMonth);
80
            else
81
                endDate = startDate + swapTenor_;
1,584✔
82
        }
83

84
        Frequency fixedPaymentFrequency, overnightPaymentFrequency;
85
        DateGeneration::Rule fixedRule, overnightRule;
86
        if (fixedPaymentFrequency_ == Once || fixedRule_ == DateGeneration::Zero) {
1,592✔
87
            fixedPaymentFrequency = Once;
88
            fixedRule = DateGeneration::Zero;
89
        } else {
90
            fixedPaymentFrequency = fixedPaymentFrequency_;
91
            fixedRule = fixedRule_;
92
        }
93
        if (overnightPaymentFrequency_ == Once || overnightRule_ == DateGeneration::Zero) {
1,592✔
94
            overnightPaymentFrequency = Once;
95
            overnightRule = DateGeneration::Zero;
96
        } else {
97
            overnightPaymentFrequency = overnightPaymentFrequency_;
98
            overnightRule = overnightRule_;
99
        }
100

101
        Schedule fixedSchedule(startDate, endDate,
102
                               Period(fixedPaymentFrequency),
3,184✔
103
                               fixedCalendar_,
104
                               fixedConvention_,
1,592✔
105
                               fixedTerminationDateConvention_,
1,592✔
106
                               fixedRule,
107
                               fixedEndOfMonth);
3,184✔
108

109
        Schedule overnightSchedule(startDate, endDate,
110
                                   Period(overnightPaymentFrequency),
3,184✔
111
                                   overnightCalendar_,
112
                                   overnightConvention_,
1,592✔
113
                                   overnightTerminationDateConvention_,
1,592✔
114
                                   overnightRule,
115
                                   overnightEndOfMonth);
3,184✔
116

117
        Rate usedFixedRate = fixedRate_;
1,592✔
118
        if (fixedRate_ == Null<Rate>()) {
1,592✔
119
            OvernightIndexedSwap temp(type_, nominal_,
×
120
                                      fixedSchedule,
121
                                      0.0, // fixed rate
122
                                      fixedDayCount_,
123
                                      overnightSchedule,
124
                                      overnightIndex_, overnightSpread_,
×
125
                                      paymentLag_, paymentAdjustment_,
×
126
                                      paymentCalendar_, telescopicValueDates_);
×
127
            if (engine_ == nullptr) {
×
128
                Handle<YieldTermStructure> disc =
129
                                    overnightIndex_->forwardingTermStructure();
×
130
                QL_REQUIRE(!disc.empty(),
×
131
                           "null term structure set to this instance of " <<
132
                           overnightIndex_->name());
133
                bool includeSettlementDateFlows = false;
134
                ext::shared_ptr<PricingEngine> engine(new
135
                    DiscountingSwapEngine(disc, includeSettlementDateFlows));
×
136
                temp.setPricingEngine(engine);
×
137
            } else
138
                temp.setPricingEngine(engine_);
×
139

140
            usedFixedRate = temp.fairRate();
×
141
        }
×
142

143
        ext::shared_ptr<OvernightIndexedSwap> ois(new
144
            OvernightIndexedSwap(type_, nominal_,
1,592✔
145
                                 fixedSchedule,
146
                                 usedFixedRate, fixedDayCount_,
147
                                 overnightSchedule,
148
                                 overnightIndex_, overnightSpread_,
1,592✔
149
                                 paymentLag_, paymentAdjustment_,
1,592✔
150
                                 paymentCalendar_, telescopicValueDates_, 
1,592✔
151
                                 averagingMethod_, lookbackDays_,
1,592✔
152
                                 lockoutDays_, applyObservationShift_));
4,778✔
153

154
        if (engine_ == nullptr) {
1,590✔
155
            Handle<YieldTermStructure> disc =
156
                                overnightIndex_->forwardingTermStructure();
577✔
157
            bool includeSettlementDateFlows = false;
158
            ext::shared_ptr<PricingEngine> engine(new
159
                DiscountingSwapEngine(disc, includeSettlementDateFlows));
577✔
160
            ois->setPricingEngine(engine);
577✔
161
        } else
162
            ois->setPricingEngine(engine_);
1,013✔
163

164
        return ois;
1,590✔
165
    }
1,594✔
166

167
    MakeOIS& MakeOIS::receiveFixed(bool flag) {
×
168
        type_ = flag ? Swap::Receiver : Swap::Payer ;
×
169
        return *this;
×
170
    }
171

172
    MakeOIS& MakeOIS::withType(Swap::Type type) {
576✔
173
        type_ = type;
576✔
174
        return *this;
576✔
175
    }
176

177
    MakeOIS& MakeOIS::withNominal(Real n) {
595✔
178
        nominal_ = n;
595✔
179
        return *this;
595✔
180
    }
181

182
    MakeOIS& MakeOIS::withSettlementDays(Natural settlementDays) {
419✔
183
        settlementDays_ = settlementDays;
419✔
184
        effectiveDate_ = Date();
419✔
185
        return *this;
419✔
186
    }
187

188
    MakeOIS& MakeOIS::withEffectiveDate(const Date& effectiveDate) {
1,592✔
189
        effectiveDate_ = effectiveDate;
1,592✔
190
        return *this;
1,592✔
191
    }
192

193
    MakeOIS& MakeOIS::withTerminationDate(const Date& terminationDate) {
420✔
194
        terminationDate_ = terminationDate;
420✔
195
        if (terminationDate != Date())
420✔
196
            swapTenor_ = Period();
8✔
197
        return *this;
420✔
198
    }
199

200
    MakeOIS& MakeOIS::withPaymentFrequency(Frequency f) {
996✔
201
        return withFixedLegPaymentFrequency(f).withOvernightLegPaymentFrequency(f);
996✔
202
    }
203

204
    MakeOIS& MakeOIS::withFixedLegPaymentFrequency(Frequency f) {
996✔
205
        fixedPaymentFrequency_ = f;
996✔
206
        return *this;
996✔
207
    }
208

209
    MakeOIS& MakeOIS::withOvernightLegPaymentFrequency(Frequency f) {
996✔
210
        overnightPaymentFrequency_ = f;
996✔
211
        return *this;
996✔
212
    }
213

214
    MakeOIS& MakeOIS::withPaymentAdjustment(BusinessDayConvention convention) {
419✔
215
        paymentAdjustment_ = convention;
419✔
216
        return *this;
419✔
217
    }
218

219
    MakeOIS& MakeOIS::withPaymentLag(Integer lag) {
1,014✔
220
        paymentLag_ = lag;
1,014✔
221
        return *this;
1,014✔
222
    }
223

224
    MakeOIS& MakeOIS::withPaymentCalendar(const Calendar& cal) {
419✔
225
        paymentCalendar_ = cal;
226
        return *this;
419✔
227
    }
228

229
    MakeOIS& MakeOIS::withCalendar(const Calendar& cal) {
×
230
        return withFixedLegCalendar(cal).withOvernightLegCalendar(cal);
×
231
    }
232

233
    MakeOIS& MakeOIS::withFixedLegCalendar(const Calendar& cal) {
×
234
        fixedCalendar_ = cal;
235
        return *this;
×
236
    }
237

238
    MakeOIS& MakeOIS::withOvernightLegCalendar(const Calendar& cal) {
×
239
        overnightCalendar_ = cal;
240
        return *this;
×
241
    }
242

243
    MakeOIS& MakeOIS::withRule(DateGeneration::Rule r) {
419✔
244
        return withFixedLegRule(r).withOvernightLegRule(r);
419✔
245
    }
246

247
    MakeOIS& MakeOIS::withFixedLegRule(DateGeneration::Rule r) {
419✔
248
        fixedRule_ = r;
419✔
249
        return *this;
419✔
250
    }
251

252
    MakeOIS& MakeOIS::withOvernightLegRule(DateGeneration::Rule r) {
419✔
253
        overnightRule_ = r;
419✔
254
        return *this;
419✔
255
    }
256

257
    MakeOIS& MakeOIS::withDiscountingTermStructure(
1,015✔
258
                                        const Handle<YieldTermStructure>& d) {
259
        bool includeSettlementDateFlows = false;
260
        engine_ = ext::shared_ptr<PricingEngine>(new
3,045✔
261
            DiscountingSwapEngine(d, includeSettlementDateFlows));
2,030✔
262
        return *this;
1,015✔
263
    }
264

265
    MakeOIS& MakeOIS::withPricingEngine(
×
266
                             const ext::shared_ptr<PricingEngine>& engine) {
267
        engine_ = engine;
×
268
        return *this;
×
269
    }
270

271
    MakeOIS& MakeOIS::withFixedLegDayCount(const DayCounter& dc) {
577✔
272
        fixedDayCount_ = dc;
273
        return *this;
577✔
274
    }
275

276
    MakeOIS& MakeOIS::withConvention(BusinessDayConvention bdc) {
×
277
        return withFixedLegConvention(bdc).withOvernightLegConvention(bdc);
×
278
    }
279

280
    MakeOIS& MakeOIS::withFixedLegConvention(BusinessDayConvention bdc) {
×
281
        fixedConvention_ = bdc;
×
282
        return *this;
×
283
    }
284

285
    MakeOIS& MakeOIS::withOvernightLegConvention(BusinessDayConvention bdc) {
×
286
        overnightConvention_ = bdc;
×
287
        return *this;
×
288
    }
289

290
    MakeOIS& MakeOIS::withTerminationDateConvention(BusinessDayConvention bdc) {
×
291
        withFixedLegTerminationDateConvention(bdc);
×
292
        return withOvernightLegTerminationDateConvention(bdc);
×
293
    }
294

295
    MakeOIS& MakeOIS::withFixedLegTerminationDateConvention(BusinessDayConvention bdc) {
×
296
        fixedTerminationDateConvention_ = bdc;
×
297
        return *this;
×
298
    }
299

300
    MakeOIS& MakeOIS::withOvernightLegTerminationDateConvention(BusinessDayConvention bdc) {
×
301
        overnightTerminationDateConvention_ = bdc;
×
302
        return *this;
×
303
    }
304

305
    MakeOIS& MakeOIS::withEndOfMonth(bool flag) {
×
306
        return withFixedLegEndOfMonth(flag).withOvernightLegEndOfMonth(flag);
×
307
    }
308

309
    MakeOIS& MakeOIS::withFixedLegEndOfMonth(bool flag) {
×
310
        fixedEndOfMonth_ = flag;
×
311
        isDefaultEOM_ = false;
×
312
        return *this;
×
313
    }
314

315
    MakeOIS& MakeOIS::withOvernightLegEndOfMonth(bool flag) {
×
316
        overnightEndOfMonth_ = flag;
×
317
        isDefaultEOM_ = false;
×
318
        return *this;
×
319
    }
320

321
    MakeOIS& MakeOIS::withOvernightLegSpread(Spread sp) {
816✔
322
        overnightSpread_ = sp;
816✔
323
        return *this;
816✔
324
    }
325

326
    MakeOIS& MakeOIS::withTelescopicValueDates(bool telescopicValueDates) {
1,014✔
327
        telescopicValueDates_ = telescopicValueDates;
1,014✔
328
        return *this;
1,014✔
329
    }
330

331
    MakeOIS& MakeOIS::withAveragingMethod(RateAveraging::Type averagingMethod) {
816✔
332
        averagingMethod_ = averagingMethod;
816✔
333
        return *this;
816✔
334
    }
335

336
    MakeOIS& MakeOIS::withLookbackDays(Natural lookbackDays) {
617✔
337
        lookbackDays_ = lookbackDays;
617✔
338
        return *this;
617✔
339
    }
340

341
    MakeOIS& MakeOIS::withLockoutDays(Natural lockoutDays) {
617✔
342
        lockoutDays_ = lockoutDays;
617✔
343
        return *this;
617✔
344
    }
345

346
    MakeOIS& MakeOIS::withObservationShift(bool applyObservationShift) {
617✔
347
        applyObservationShift_ = applyObservationShift;
617✔
348
        return *this;
617✔
349
    }
350

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