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

lballabio / QuantLib / 10197365829

01 Aug 2024 10:54AM UTC coverage: 72.642% (-0.002%) from 72.644%
10197365829

push

github

lballabio
Check a couple of vector accesses

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

2 existing lines in 1 file now uncovered.

55083 of 75828 relevant lines covered (72.64%)

8643767.52 hits per line

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

61.27
/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,522✔
31
                     const ext::shared_ptr<OvernightIndex>& overnightIndex,
32
                     Rate fixedRate,
33
                     const Period& forwardStart)
1,522✔
34
    : swapTenor_(swapTenor), overnightIndex_(overnightIndex), fixedRate_(fixedRate),
1,522✔
35
      forwardStart_(forwardStart),
1,522✔
36
      fixedCalendar_(overnightIndex->fixingCalendar()),
1,522✔
37
      overnightCalendar_(overnightIndex->fixingCalendar()),
1,522✔
38
      fixedDayCount_(overnightIndex->dayCounter()) {}
4,566✔
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,522✔
46

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

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

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

84
        Frequency fixedPaymentFrequency, overnightPaymentFrequency;
85
        DateGeneration::Rule fixedRule, overnightRule;
86
        if (fixedPaymentFrequency_ == Once || fixedRule_ == DateGeneration::Zero) {
1,522✔
87
            fixedPaymentFrequency = Once;
88
            fixedRule = DateGeneration::Zero;
89
        } else {
90
            fixedPaymentFrequency = fixedPaymentFrequency_;
91
            fixedRule = fixedRule_;
92
        }
93
        if (overnightPaymentFrequency_ == Once || overnightRule_ == DateGeneration::Zero) {
1,522✔
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,044✔
103
                               fixedCalendar_,
104
                               fixedConvention_,
1,522✔
105
                               fixedTerminationDateConvention_,
1,522✔
106
                               fixedRule,
107
                               fixedEndOfMonth);
3,044✔
108

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

117
        Rate usedFixedRate = fixedRate_;
1,522✔
118
        if (fixedRate_ == Null<Rate>()) {
1,522✔
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,522✔
145
                                 fixedSchedule,
146
                                 usedFixedRate, fixedDayCount_,
147
                                 overnightSchedule,
148
                                 overnightIndex_, overnightSpread_,
1,522✔
149
                                 paymentLag_, paymentAdjustment_,
1,522✔
150
                                 paymentCalendar_, telescopicValueDates_, 
1,522✔
151
                                 averagingMethod_, lookbackDays_,
1,522✔
152
                                 lockoutDays_, applyObservationShift_));
4,568✔
153

154
        if (engine_ == nullptr) {
1,520✔
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_);
943✔
163

164
        return ois;
1,520✔
165
    }
1,524✔
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) {
562✔
178
        nominal_ = n;
562✔
179
        return *this;
562✔
180
    }
181

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

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

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

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

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

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

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

218
    MakeOIS& MakeOIS::withPaymentLag(Integer lag) {
945✔
219
        paymentLag_ = lag;
945✔
220
        return *this;
945✔
221
    }
222

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

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

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

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

242
    MakeOIS& MakeOIS::withRule(DateGeneration::Rule r) {
×
243
        return withFixedLegRule(r).withOvernightLegRule(r);
×
244
    }
245

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

325
    MakeOIS& MakeOIS::withTelescopicValueDates(bool telescopicValueDates) {
945✔
326
        telescopicValueDates_ = telescopicValueDates;
945✔
327
        return *this;
945✔
328
    }
329

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

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

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

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

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