Coverage Report

Created: 2025-08-11 06:28

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