Coverage Report

Created: 2026-10-31 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/overnightindexedswap.hpp
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
/*! \file overnightindexedswap.hpp
25
    \brief Overnight index swap paying compounded overnight vs. fixed
26
*/
27
28
#ifndef quantlib_overnight_indexed_swap_hpp
29
#define quantlib_overnight_indexed_swap_hpp
30
31
#include <ql/cashflows/rateaveraging.hpp>
32
#include <ql/instruments/fixedvsfloatingswap.hpp>
33
#include <ql/optional.hpp>
34
#include <ql/time/businessdayconvention.hpp>
35
#include <ql/time/calendar.hpp>
36
#include <ql/time/daycounter.hpp>
37
#include <ql/time/schedule.hpp>
38
39
namespace QuantLib {
40
41
    class OvernightIndex;
42
43
    //! Overnight indexed swap: fix vs compounded overnight rate
44
    class OvernightIndexedSwap : public FixedVsFloatingSwap {
45
      public:
46
        OvernightIndexedSwap(Type type,
47
                             Real nominal,
48
                             const Schedule& schedule,
49
                             Rate fixedRate,
50
                             DayCounter fixedDC,
51
                             const ext::shared_ptr<OvernightIndex>& overnightIndex,
52
                             Spread spread = 0.0,
53
                             Integer paymentLag = 0,
54
                             BusinessDayConvention paymentAdjustment = Following,
55
                             const Calendar& paymentCalendar = Calendar(),
56
                             bool telescopicValueDates = false,
57
                             RateAveraging::Type averagingMethod = RateAveraging::Compound,
58
                             Natural lookbackDays = Null<Natural>(),
59
                             Natural lockoutDays = 0,
60
                             bool applyObservationShift = false,
61
                             const std::optional<Integer>& roundingPrecision = std::nullopt);
62
63
        OvernightIndexedSwap(Type type,
64
                             const std::vector<Real>& nominals,
65
                             const Schedule& schedule,
66
                             Rate fixedRate,
67
                             DayCounter fixedDC,
68
                             const ext::shared_ptr<OvernightIndex>& overnightIndex,
69
                             Spread spread = 0.0,
70
                             Integer paymentLag = 0,
71
                             BusinessDayConvention paymentAdjustment = Following,
72
                             const Calendar& paymentCalendar = Calendar(),
73
                             bool telescopicValueDates = false,
74
                             RateAveraging::Type averagingMethod = RateAveraging::Compound,
75
                             Natural lookbackDays = Null<Natural>(),
76
                             Natural lockoutDays = 0,
77
                             bool applyObservationShift = false,
78
                             const std::optional<Integer>& roundingPrecision = std::nullopt);
79
80
        OvernightIndexedSwap(Type type,
81
                             Real nominal,
82
                             Schedule fixedSchedule,
83
                             Rate fixedRate,
84
                             DayCounter fixedDC,
85
                             Schedule overnightSchedule,
86
                             const ext::shared_ptr<OvernightIndex>& overnightIndex,
87
                             Spread spread = 0.0,
88
                             Integer paymentLag = 0,
89
                             BusinessDayConvention paymentAdjustment = Following,
90
                             const Calendar& paymentCalendar = Calendar(),
91
                             bool telescopicValueDates = false,
92
                             RateAveraging::Type averagingMethod = RateAveraging::Compound,
93
                             Natural lookbackDays = Null<Natural>(),
94
                             Natural lockoutDays = 0,
95
                             bool applyObservationShift = false,
96
                             const std::optional<Integer>& roundingPrecision = std::nullopt);
97
98
        OvernightIndexedSwap(Type type,
99
                             std::vector<Real> fixedNominals,
100
                             Schedule fixedSchedule,
101
                             Rate fixedRate,
102
                             DayCounter fixedDC,
103
                             const std::vector<Real>& overnightNominals,
104
                             Schedule overnightSchedule,
105
                             const ext::shared_ptr<OvernightIndex>& overnightIndex,
106
                             Spread spread = 0.0,
107
                             Integer paymentLag = 0,
108
                             BusinessDayConvention paymentAdjustment = Following,
109
                             const Calendar& paymentCalendar = Calendar(),
110
                             bool telescopicValueDates = false,
111
                             RateAveraging::Type averagingMethod = RateAveraging::Compound,
112
                             Natural lookbackDays = Null<Natural>(),
113
                             Natural lockoutDays = 0,
114
                             bool applyObservationShift = false,
115
                             const std::optional<Integer>& roundingPrecision = std::nullopt);
116
117
        //! \name Inspectors
118
        //@{
119
0
        Frequency paymentFrequency() const {
120
0
            return std::max(fixedSchedule().tenor().frequency(),
121
0
                            floatingSchedule().tenor().frequency());
122
0
        }
123
124
0
        const std::vector<Real>& overnightNominals() const { return floatingNominals(); }
125
0
        const Schedule& overnightSchedule() const { return floatingSchedule(); }
126
0
        const ext::shared_ptr<OvernightIndex>& overnightIndex() const { return overnightIndex_; }
127
0
        const Leg& overnightLeg() const { return floatingLeg(); }
128
129
0
        Integer paymentLag() const { return paymentLag_; }
130
0
        const Calendar& paymentCalendar() const { return paymentCalendar_; }
131
0
        bool telescopicValueDates() const { return telescopicValueDates_; }
132
133
0
        RateAveraging::Type averagingMethod() const { return averagingMethod_; }
134
0
        Natural lookbackDays() const { return lookbackDays_; }
135
0
        Natural lockoutDays() const { return lockoutDays_; }
136
0
        bool applyObservationShift() const { return applyObservationShift_; }
137
0
        std::optional<Integer> roundingPrecision() const { return roundingPrecision_; }
138
        //@}
139
140
        //! \name Results
141
        //@{
142
0
        Real overnightLegBPS() const { return floatingLegBPS(); }
143
0
        Real overnightLegNPV() const { return floatingLegNPV(); }
144
        //@}
145
      private:
146
        void setupFloatingArguments(arguments* args) const override;
147
148
        ext::shared_ptr<OvernightIndex> overnightIndex_;
149
        Integer paymentLag_;
150
        Calendar paymentCalendar_;
151
        bool telescopicValueDates_;
152
        RateAveraging::Type averagingMethod_;
153
        Natural lookbackDays_;
154
        Natural lockoutDays_;
155
        bool applyObservationShift_;
156
        std::optional<Integer> roundingPrecision_;
157
    };
158
159
}
160
161
#endif