Coverage Report

Created: 2025-11-04 06:12

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
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
 <https://www.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/cashflows/fixedratecoupon.hpp>
24
#include <ql/cashflows/overnightindexedcoupon.hpp>
25
#include <ql/instruments/overnightindexedswap.hpp>
26
#include <utility>
27
28
namespace QuantLib {
29
30
    OvernightIndexedSwap::OvernightIndexedSwap(Type type,
31
                                               Real nominal,
32
                                               const Schedule& schedule,
33
                                               Rate fixedRate,
34
                                               DayCounter fixedDC,
35
                                               const ext::shared_ptr<OvernightIndex>& overnightIndex,
36
                                               Spread spread,
37
                                               Integer paymentLag,
38
                                               BusinessDayConvention paymentAdjustment,
39
                                               const Calendar& paymentCalendar,
40
                                               bool telescopicValueDates,
41
                                               RateAveraging::Type averagingMethod,
42
                                               Natural lookbackDays,
43
                                               Natural lockoutDays,
44
                                               bool applyObservationShift)
45
0
    : OvernightIndexedSwap(type,
46
0
                           std::vector<Real>(1, nominal),
47
0
                           schedule,
48
0
                           fixedRate,
49
0
                           std::move(fixedDC),
50
0
                           overnightIndex,
51
0
                           spread,
52
0
                           paymentLag,
53
0
                           paymentAdjustment,
54
0
                           paymentCalendar,
55
0
                           telescopicValueDates,
56
0
                           averagingMethod,
57
0
                           lookbackDays,
58
0
                           lockoutDays,
59
0
                           applyObservationShift) {}
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)
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)
60
61
    OvernightIndexedSwap::OvernightIndexedSwap(Type type,
62
                                               const std::vector<Real>& nominals,
63
                                               const Schedule& schedule,
64
                                               Rate fixedRate,
65
                                               DayCounter fixedDC,
66
                                               const ext::shared_ptr<OvernightIndex>& overnightIndex,
67
                                               Spread spread,
68
                                               Integer paymentLag,
69
                                               BusinessDayConvention paymentAdjustment,
70
                                               const Calendar& paymentCalendar,
71
                                               bool telescopicValueDates,
72
                                               RateAveraging::Type averagingMethod,
73
                                               Natural lookbackDays,
74
                                               Natural lockoutDays,
75
                                               bool applyObservationShift)
76
0
    : OvernightIndexedSwap(type,
77
0
                           nominals,
78
0
                           schedule,
79
0
                           fixedRate,
80
0
                           std::move(fixedDC),
81
0
                           nominals,
82
0
                           schedule,
83
0
                           overnightIndex,
84
0
                           spread,
85
0
                           paymentLag,
86
0
                           paymentAdjustment,
87
0
                           paymentCalendar,
88
0
                           telescopicValueDates,
89
0
                           averagingMethod, 
90
0
                           lookbackDays, 
91
0
                           lockoutDays, 
92
0
                           applyObservationShift) {}
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)
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)
93
94
    OvernightIndexedSwap::OvernightIndexedSwap(Type type,
95
                                               Real nominal,
96
                                               Schedule fixedSchedule,
97
                                               Rate fixedRate,
98
                                               DayCounter fixedDC,
99
                                               Schedule overnightSchedule,
100
                                               const ext::shared_ptr<OvernightIndex>& overnightIndex,
101
                                               Spread spread,
102
                                               Integer paymentLag,
103
                                               BusinessDayConvention paymentAdjustment,
104
                                               const Calendar& paymentCalendar,
105
                                               bool telescopicValueDates,
106
                                               RateAveraging::Type averagingMethod,
107
                                               Natural lookbackDays,
108
                                               Natural lockoutDays,
109
                                               bool applyObservationShift)
110
0
    : OvernightIndexedSwap(type,
111
0
                           std::vector<Real>(1, nominal),
112
0
                           std::move(fixedSchedule),
113
0
                           fixedRate,
114
0
                           std::move(fixedDC),
115
0
                           std::vector<Real>(1, nominal),
116
0
                           std::move(overnightSchedule),
117
0
                           overnightIndex,
118
0
                           spread,
119
0
                           paymentLag,
120
0
                           paymentAdjustment,
121
0
                           paymentCalendar,
122
0
                           telescopicValueDates,
123
0
                           averagingMethod,
124
0
                           lookbackDays,
125
0
                           lockoutDays,
126
0
                           applyObservationShift) {}
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)
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)
127
128
    OvernightIndexedSwap::OvernightIndexedSwap(Type type,
129
                                               std::vector<Real> fixedNominals,
130
                                               Schedule fixedSchedule,
131
                                               Rate fixedRate,
132
                                               DayCounter fixedDC,
133
                                               const std::vector<Real>& overnightNominals,
134
                                               Schedule overnightSchedule,
135
                                               const ext::shared_ptr<OvernightIndex>& overnightIndex,
136
                                               Spread spread,
137
                                               Integer paymentLag,
138
                                               BusinessDayConvention paymentAdjustment,
139
                                               const Calendar& paymentCalendar,
140
                                               bool telescopicValueDates,
141
                                               RateAveraging::Type averagingMethod,
142
                                               Natural lookbackDays,
143
                                               Natural lockoutDays,
144
                                               bool applyObservationShift)
145
0
    : FixedVsFloatingSwap(type, std::move(fixedNominals), std::move(fixedSchedule), fixedRate, std::move(fixedDC),
146
0
                          overnightNominals, std::move(overnightSchedule), overnightIndex,
147
0
                          spread, DayCounter(), ext::nullopt, paymentLag, paymentCalendar),
148
0
                          overnightIndex_(overnightIndex), averagingMethod_(averagingMethod),
149
0
                          lookbackDays_(lookbackDays), lockoutDays_(lockoutDays),
150
0
                          applyObservationShift_(applyObservationShift) {
151
0
        legs_[1] =
152
0
            OvernightLeg(floatingSchedule(), overnightIndex_)
153
0
                .withNotionals(overnightNominals)
154
0
                .withSpreads(spread)
155
0
                .withTelescopicValueDates(telescopicValueDates)
156
0
                .withPaymentLag(paymentLag)
157
0
                .withPaymentAdjustment(paymentAdjustment)
158
0
                .withPaymentCalendar(paymentCalendar.empty() ?
159
0
                                     floatingSchedule().calendar() :
160
0
                                     paymentCalendar)
161
0
                .withAveragingMethod(averagingMethod_)
162
0
                .withLookbackDays(lookbackDays_)
163
0
                .withLockoutDays(lockoutDays_)
164
0
                .withObservationShift(applyObservationShift_);
165
0
        for (const auto& c : legs_[1])
166
0
            registerWith(c);
167
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)
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)
168
169
0
    void OvernightIndexedSwap::setupFloatingArguments(arguments* args) const {
170
0
        const Leg& floatingCoupons = floatingLeg();
171
0
        Size n = floatingCoupons.size();
172
173
0
        args->floatingResetDates = args->floatingPayDates = args->floatingFixingDates = std::vector<Date>(n);
174
0
        args->floatingAccrualTimes = std::vector<Time>(n);
175
0
        args->floatingSpreads = std::vector<Spread>(n);
176
0
        args->floatingCoupons = args->floatingNominals = std::vector<Real>(n);
177
178
0
        for (Size i=0; i<n; ++i) {
179
0
            auto coupon = ext::dynamic_pointer_cast<OvernightIndexedCoupon>(floatingCoupons[i]);
180
181
0
            args->floatingResetDates[i] = coupon->accrualStartDate();
182
0
            args->floatingPayDates[i] = coupon->date();
183
0
            args->floatingNominals[i] = coupon->nominal();
184
185
0
            args->floatingFixingDates[i] = coupon->fixingDate();
186
0
            args->floatingAccrualTimes[i] = coupon->accrualPeriod();
187
0
            args->floatingSpreads[i] = coupon->spread();
188
0
            try {
189
0
                args->floatingCoupons[i] = coupon->amount();
190
0
            } catch (Error&) {
191
0
                args->floatingCoupons[i] = Null<Real>();
192
0
            }
193
0
        }
194
0
    }
195
196
}