Coverage Report

Created: 2026-08-14 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/overnightindexedswap.cpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2009 Roland Lichters
5
 Copyright (C) 2009 Ferdinando Ametrano
6
 Copyright (C) 2017 Joseph Jeisman
7
 Copyright (C) 2017 Fabrice Lecuyer
8
 Copyright (C) 2026 Sergio Araujo
9
10
 This file is part of QuantLib, a free-software/open-source library
11
 for financial quantitative analysts and developers - http://quantlib.org/
12
13
 QuantLib is free software: you can redistribute it and/or modify it
14
 under the terms of the QuantLib license.  You should have received a
15
 copy of the license along with this program; if not, please email
16
 <quantlib-dev@lists.sf.net>. The license is also available online at
17
 <https://www.quantlib.org/license.shtml>.
18
19
 This program is distributed in the hope that it will be useful, but WITHOUT
20
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21
 FOR A PARTICULAR PURPOSE.  See the license for more details.
22
*/
23
24
#include <ql/cashflows/fixedratecoupon.hpp>
25
#include <ql/cashflows/overnightindexedcoupon.hpp>
26
#include <ql/instruments/overnightindexedswap.hpp>
27
#include <utility>
28
29
namespace QuantLib {
30
31
    OvernightIndexedSwap::OvernightIndexedSwap(Type type,
32
                                               Real nominal,
33
                                               const Schedule& schedule,
34
                                               Rate fixedRate,
35
                                               DayCounter fixedDC,
36
                                               const ext::shared_ptr<OvernightIndex>& overnightIndex,
37
                                               Spread spread,
38
                                               Integer paymentLag,
39
                                               BusinessDayConvention paymentAdjustment,
40
                                               const Calendar& paymentCalendar,
41
                                               bool telescopicValueDates,
42
                                               RateAveraging::Type averagingMethod,
43
                                               Natural lookbackDays,
44
                                               Natural lockoutDays,
45
                                               bool applyObservationShift,
46
                                               const std::optional<Integer>& roundingPrecision)
47
0
    : OvernightIndexedSwap(type,
48
0
                           std::vector<Real>(1, nominal),
49
0
                           schedule,
50
0
                           fixedRate,
51
0
                           std::move(fixedDC),
52
0
                           overnightIndex,
53
0
                           spread,
54
0
                           paymentLag,
55
0
                           paymentAdjustment,
56
0
                           paymentCalendar,
57
0
                           telescopicValueDates,
58
0
                           averagingMethod,
59
0
                           lookbackDays,
60
0
                           lockoutDays,
61
0
                           applyObservationShift,
62
0
                           roundingPrecision) {}
Unexecuted instantiation: QuantLib::OvernightIndexedSwap::OvernightIndexedSwap(QuantLib::Swap::Type, double, QuantLib::Schedule const&, double, QuantLib::DayCounter, boost::shared_ptr<QuantLib::OvernightIndex> const&, double, int, QuantLib::BusinessDayConvention, QuantLib::Calendar const&, bool, QuantLib::RateAveraging::Type, unsigned int, unsigned int, bool, std::__1::optional<int> const&)
Unexecuted instantiation: QuantLib::OvernightIndexedSwap::OvernightIndexedSwap(QuantLib::Swap::Type, double, QuantLib::Schedule const&, double, QuantLib::DayCounter, boost::shared_ptr<QuantLib::OvernightIndex> const&, double, int, QuantLib::BusinessDayConvention, QuantLib::Calendar const&, bool, QuantLib::RateAveraging::Type, unsigned int, unsigned int, bool, std::__1::optional<int> const&)
63
64
    OvernightIndexedSwap::OvernightIndexedSwap(Type type,
65
                                               const std::vector<Real>& nominals,
66
                                               const Schedule& schedule,
67
                                               Rate fixedRate,
68
                                               DayCounter fixedDC,
69
                                               const ext::shared_ptr<OvernightIndex>& overnightIndex,
70
                                               Spread spread,
71
                                               Integer paymentLag,
72
                                               BusinessDayConvention paymentAdjustment,
73
                                               const Calendar& paymentCalendar,
74
                                               bool telescopicValueDates,
75
                                               RateAveraging::Type averagingMethod,
76
                                               Natural lookbackDays,
77
                                               Natural lockoutDays,
78
                                               bool applyObservationShift,
79
                                               const std::optional<Integer>& roundingPrecision)
80
0
    : OvernightIndexedSwap(type,
81
0
                           nominals,
82
0
                           schedule,
83
0
                           fixedRate,
84
0
                           std::move(fixedDC),
85
0
                           nominals,
86
0
                           schedule,
87
0
                           overnightIndex,
88
0
                           spread,
89
0
                           paymentLag,
90
0
                           paymentAdjustment,
91
0
                           paymentCalendar,
92
0
                           telescopicValueDates,
93
0
                           averagingMethod,
94
0
                           lookbackDays,
95
0
                           lockoutDays,
96
0
                           applyObservationShift,
97
0
                           roundingPrecision) {}
Unexecuted instantiation: QuantLib::OvernightIndexedSwap::OvernightIndexedSwap(QuantLib::Swap::Type, std::__1::vector<double, std::__1::allocator<double> > const&, QuantLib::Schedule const&, double, QuantLib::DayCounter, boost::shared_ptr<QuantLib::OvernightIndex> const&, double, int, QuantLib::BusinessDayConvention, QuantLib::Calendar const&, bool, QuantLib::RateAveraging::Type, unsigned int, unsigned int, bool, std::__1::optional<int> const&)
Unexecuted instantiation: QuantLib::OvernightIndexedSwap::OvernightIndexedSwap(QuantLib::Swap::Type, std::__1::vector<double, std::__1::allocator<double> > const&, QuantLib::Schedule const&, double, QuantLib::DayCounter, boost::shared_ptr<QuantLib::OvernightIndex> const&, double, int, QuantLib::BusinessDayConvention, QuantLib::Calendar const&, bool, QuantLib::RateAveraging::Type, unsigned int, unsigned int, bool, std::__1::optional<int> const&)
98
99
    OvernightIndexedSwap::OvernightIndexedSwap(Type type,
100
                                               Real nominal,
101
                                               Schedule fixedSchedule,
102
                                               Rate fixedRate,
103
                                               DayCounter fixedDC,
104
                                               Schedule overnightSchedule,
105
                                               const ext::shared_ptr<OvernightIndex>& overnightIndex,
106
                                               Spread spread,
107
                                               Integer paymentLag,
108
                                               BusinessDayConvention paymentAdjustment,
109
                                               const Calendar& paymentCalendar,
110
                                               bool telescopicValueDates,
111
                                               RateAveraging::Type averagingMethod,
112
                                               Natural lookbackDays,
113
                                               Natural lockoutDays,
114
                                               bool applyObservationShift,
115
                                               const std::optional<Integer>& roundingPrecision)
116
0
    : OvernightIndexedSwap(type,
117
0
                           std::vector<Real>(1, nominal),
118
0
                           std::move(fixedSchedule),
119
0
                           fixedRate,
120
0
                           std::move(fixedDC),
121
0
                           std::vector<Real>(1, nominal),
122
0
                           std::move(overnightSchedule),
123
0
                           overnightIndex,
124
0
                           spread,
125
0
                           paymentLag,
126
0
                           paymentAdjustment,
127
0
                           paymentCalendar,
128
0
                           telescopicValueDates,
129
0
                           averagingMethod,
130
0
                           lookbackDays,
131
0
                           lockoutDays,
132
0
                           applyObservationShift,
133
0
                           roundingPrecision) {}
Unexecuted instantiation: QuantLib::OvernightIndexedSwap::OvernightIndexedSwap(QuantLib::Swap::Type, double, QuantLib::Schedule, double, QuantLib::DayCounter, QuantLib::Schedule, boost::shared_ptr<QuantLib::OvernightIndex> const&, double, int, QuantLib::BusinessDayConvention, QuantLib::Calendar const&, bool, QuantLib::RateAveraging::Type, unsigned int, unsigned int, bool, std::__1::optional<int> const&)
Unexecuted instantiation: QuantLib::OvernightIndexedSwap::OvernightIndexedSwap(QuantLib::Swap::Type, double, QuantLib::Schedule, double, QuantLib::DayCounter, QuantLib::Schedule, boost::shared_ptr<QuantLib::OvernightIndex> const&, double, int, QuantLib::BusinessDayConvention, QuantLib::Calendar const&, bool, QuantLib::RateAveraging::Type, unsigned int, unsigned int, bool, std::__1::optional<int> const&)
134
135
    OvernightIndexedSwap::OvernightIndexedSwap(Type type,
136
                                               std::vector<Real> fixedNominals,
137
                                               Schedule fixedSchedule,
138
                                               Rate fixedRate,
139
                                               DayCounter fixedDC,
140
                                               const std::vector<Real>& overnightNominals,
141
                                               Schedule overnightSchedule,
142
                                               const ext::shared_ptr<OvernightIndex>& overnightIndex,
143
                                               Spread spread,
144
                                               Integer paymentLag,
145
                                               BusinessDayConvention paymentAdjustment,
146
                                               const Calendar& paymentCalendar,
147
                                               bool telescopicValueDates,
148
                                               RateAveraging::Type averagingMethod,
149
                                               Natural lookbackDays,
150
                                               Natural lockoutDays,
151
                                               bool applyObservationShift,
152
                                               const std::optional<Integer>& roundingPrecision)
153
0
    : FixedVsFloatingSwap(type, std::move(fixedNominals), std::move(fixedSchedule), fixedRate, std::move(fixedDC),
154
0
                          overnightNominals, std::move(overnightSchedule), overnightIndex,
155
0
                          spread, DayCounter(), paymentAdjustment, paymentLag, paymentCalendar),
156
0
                          overnightIndex_(overnightIndex),
157
0
                          paymentLag_(paymentLag), paymentCalendar_(paymentCalendar),
158
0
                          telescopicValueDates_(telescopicValueDates),
159
0
                          averagingMethod_(averagingMethod),
160
0
                          lookbackDays_(lookbackDays), lockoutDays_(lockoutDays),
161
0
                          applyObservationShift_(applyObservationShift),
162
0
                          roundingPrecision_(roundingPrecision) {
163
0
        OvernightLeg leg(floatingSchedule(), overnightIndex_);
164
0
        leg
165
0
                .withNotionals(overnightNominals)
166
0
                .withSpreads(spread)
167
0
                .withTelescopicValueDates(telescopicValueDates)
168
0
                .withPaymentLag(paymentLag)
169
0
                .withPaymentAdjustment(paymentAdjustment)
170
0
                .withPaymentCalendar(paymentCalendar.empty() ?
171
0
                                     floatingSchedule().calendar() :
172
0
                                     paymentCalendar)
173
0
                .withAveragingMethod(averagingMethod_)
174
0
                .withLookbackDays(lookbackDays_)
175
0
                .withLockoutDays(lockoutDays_)
176
0
                .withObservationShift(applyObservationShift_);
177
0
        if (roundingPrecision_.has_value()) {
178
0
            QL_REQUIRE(*roundingPrecision_ >= 0 && *roundingPrecision_ <= 16,
179
0
                       "rounding precision (" << *roundingPrecision_ <<
180
0
                       ") must be between 0 and 16");
181
0
            leg.withRoundingPrecision(*roundingPrecision_);
182
0
        }
183
0
        legs_[1] = leg;
184
0
        for (const auto& c : legs_[1])
185
0
            registerWith(c);
186
0
    }
Unexecuted instantiation: QuantLib::OvernightIndexedSwap::OvernightIndexedSwap(QuantLib::Swap::Type, std::__1::vector<double, std::__1::allocator<double> >, QuantLib::Schedule, double, QuantLib::DayCounter, std::__1::vector<double, std::__1::allocator<double> > const&, QuantLib::Schedule, boost::shared_ptr<QuantLib::OvernightIndex> const&, double, int, QuantLib::BusinessDayConvention, QuantLib::Calendar const&, bool, QuantLib::RateAveraging::Type, unsigned int, unsigned int, bool, std::__1::optional<int> const&)
Unexecuted instantiation: QuantLib::OvernightIndexedSwap::OvernightIndexedSwap(QuantLib::Swap::Type, std::__1::vector<double, std::__1::allocator<double> >, QuantLib::Schedule, double, QuantLib::DayCounter, std::__1::vector<double, std::__1::allocator<double> > const&, QuantLib::Schedule, boost::shared_ptr<QuantLib::OvernightIndex> const&, double, int, QuantLib::BusinessDayConvention, QuantLib::Calendar const&, bool, QuantLib::RateAveraging::Type, unsigned int, unsigned int, bool, std::__1::optional<int> const&)
187
188
0
    void OvernightIndexedSwap::setupFloatingArguments(arguments* args) const {
189
0
        const Leg& floatingCoupons = floatingLeg();
190
0
        Size n = floatingCoupons.size();
191
192
0
        args->floatingResetDates = args->floatingPayDates = args->floatingFixingDates = std::vector<Date>(n);
193
0
        args->floatingAccrualTimes = std::vector<Time>(n);
194
0
        args->floatingSpreads = std::vector<Spread>(n);
195
0
        args->floatingCoupons = args->floatingNominals = std::vector<Real>(n);
196
197
0
        for (Size i=0; i<n; ++i) {
198
0
            auto coupon = ext::dynamic_pointer_cast<OvernightIndexedCoupon>(floatingCoupons[i]);
199
200
0
            args->floatingResetDates[i] = coupon->accrualStartDate();
201
0
            args->floatingPayDates[i] = coupon->date();
202
0
            args->floatingNominals[i] = coupon->nominal();
203
204
0
            args->floatingFixingDates[i] = coupon->fixingDate();
205
0
            args->floatingAccrualTimes[i] = coupon->accrualPeriod();
206
0
            args->floatingSpreads[i] = coupon->spread();
207
0
            try {
208
0
                args->floatingCoupons[i] = coupon->amount();
209
0
            } catch (Error&) {
210
0
                args->floatingCoupons[i] = Null<Real>();
211
0
            }
212
0
        }
213
0
    }
214
215
}