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

lballabio / QuantLib / 9648657550

24 Jun 2024 04:06PM UTC coverage: 72.578% (+0.03%) from 72.55%
9648657550

Pull #1781

github

web-flow
Merge 3eac73c93 into da4560c3a
Pull Request #1781: Expose an IBOR coupon's decision about whether it has fixed or not

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

71 existing lines in 5 files now uncovered.

55021 of 75809 relevant lines covered (72.58%)

8593446.37 hits per line

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

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

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

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

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

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

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

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

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

164
        return ois;
1,124✔
165
    }
1,124✔
166

167
    MakeOIS& MakeOIS::receiveFixed(bool flag) {
×
168
        type_ = flag ? Swap::Receiver : Swap::Payer ;
×
UNCOV
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) {
364✔
178
        nominal_ = n;
364✔
179
        return *this;
364✔
180
    }
181

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

188
    MakeOIS& MakeOIS::withEffectiveDate(const Date& effectiveDate) {
947✔
189
        effectiveDate_ = effectiveDate;
947✔
190
        return *this;
947✔
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) {
760✔
200
        return withFixedLegPaymentFrequency(f).withOvernightLegPaymentFrequency(f);
760✔
201
    }
202

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
264
    MakeOIS& MakeOIS::withPricingEngine(
×
265
                             const ext::shared_ptr<PricingEngine>& engine) {
266
        engine_ = engine;
×
UNCOV
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) {
×
UNCOV
276
        return withFixedLegConvention(bdc).withOvernightLegConvention(bdc);
×
277
    }
278

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
345
    MakeOIS& MakeOIS::withObservationShift(bool applyObservationShift) {
×
UNCOV
346
        applyObservationShift_ = applyObservationShift;
×
UNCOV
347
        return *this;
×
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