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

lballabio / QuantLib / 8939411017

03 May 2024 01:02PM UTC coverage: 72.496% (-0.006%) from 72.502%
8939411017

push

github

web-flow
Remove forwardStart from DatedOISRateHelper (#1952)

1 of 4 new or added lines in 1 file covered. (25.0%)

2 existing lines in 1 file now uncovered.

54876 of 75695 relevant lines covered (72.5%)

8664345.14 hits per line

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

58.9
/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✔
UNCOV
76
                endDate = overnightCalendar_.advance(startDate,
×
UNCOV
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_));
3,372✔
152

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

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

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

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

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

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

187
    MakeOIS& MakeOIS::withEffectiveDate(const Date& effectiveDate) {
947✔
188
        effectiveDate_ = effectiveDate;
947✔
189
        return *this;
947✔
190
    }
191

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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