Coverage Report

Created: 2025-10-14 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/zerocouponswap.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2021 Marcin Rybacki
5
6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8
9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <https://www.quantlib.org/license.shtml>.
14
15
 This program is distributed in the hope that it will be useful, but WITHOUT
16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 FOR A PARTICULAR PURPOSE.  See the license for more details.
18
 */
19
20
/*! \file zerocouponswap.hpp
21
 \brief Zero-coupon interest rate swap
22
 */
23
24
#ifndef quantlib_zerocouponswap_hpp
25
#define quantlib_zerocouponswap_hpp
26
27
#include <ql/instruments/swap.hpp>
28
#include <ql/time/calendar.hpp>
29
#include <ql/time/daycounter.hpp>
30
31
namespace QuantLib {
32
    class IborIndex;
33
34
    //! Zero-coupon interest rate swap
35
    /*! Quoted in terms of a known fixed cash flow \f$ N^{FIX} \f$ or
36
        a fixed rate \f$ R \f$, where:
37
        \f[
38
        N^{FIX} = N \left[ (1+R)^{\alpha(T_{0}, T_{K})}-1 \right] ,
39
        \f]
40
        with \f$ \alpha(T_{0}, T_{K}) \f$ being the time fraction
41
        between the start date of the contract \f$ T_{0} \f$ and
42
        the end date \f$ T_{K} \f$ - according to a given day count
43
        convention. \f$ N \f$ is the base notional amount prior to
44
        compounding.
45
        The floating leg also pays a single cash flow \f$ N^{FLT} \f$,
46
        which value is determined by periodically averaging (e.g. every
47
        6 months) interest rate index fixings.
48
        Assuming the use of compounded averaging the projected value of
49
        the floating leg becomes:
50
        \f[
51
        N^{FLT} = N \left[ \prod_{k=0}^{K-1} (1+\alpha(T_{k},T_{k+1})
52
                           L(T_{k},T_{k+1})) -1 \right],
53
        \f]
54
        where \f$ L(T_{i}, T_{j})) \f$ are interest rate index fixings
55
        for accrual period \f$ [T_{i}, T_{j}] \f$.
56
        For a par contract, it holds that:
57
        \f[
58
        P_n(0,T) N^{FIX} = P_n(0,T) N^{FLT}
59
        \f]
60
        where \f$ T \f$ is the final payment time, \f$ P_n(0,t) \f$
61
        is the nominal discount factor at time \f$ t \f$.
62
63
        At maturity the two single cashflows are swapped.
64
65
        \note we do not need Schedules on the legs because they use
66
              one or two dates only per leg. Those dates are not
67
              adjusted for potential non-business days. Only the
68
              payment date is subject to adjustment.
69
    */
70
71
    class ZeroCouponSwap : public Swap {
72
      public:
73
        ZeroCouponSwap(Type type,
74
                       Real baseNominal,
75
                       const Date& startDate,
76
                       const Date& maturityDate,
77
                       Real fixedPayment,
78
                       ext::shared_ptr<IborIndex> iborIndex,
79
                       const Calendar& paymentCalendar,
80
                       BusinessDayConvention paymentConvention = Following,
81
                       Natural paymentDelay = 0);
82
83
        ZeroCouponSwap(Type type,
84
                       Real baseNominal,
85
                       const Date& startDate,
86
                       const Date& maturityDate,
87
                       Rate fixedRate,
88
                       const DayCounter& fixedDayCounter,
89
                       ext::shared_ptr<IborIndex> iborIndex,
90
                       const Calendar& paymentCalendar,
91
                       BusinessDayConvention paymentConvention = Following,
92
                       Natural paymentDelay = 0);
93
94
        //! \name Inspectors
95
        //@{
96
        //! "payer" or "receiver" refer to the fixed leg.
97
0
        Type type() const { return type_; }
98
0
        Real baseNominal() const { return baseNominal_; }
99
0
        Date startDate() const override { return startDate_; }
100
0
        Date maturityDate() const override { return maturityDate_; }
101
0
        const ext::shared_ptr<IborIndex>& iborIndex() const { return iborIndex_; }
102
103
        //! just one cashflow in each leg
104
        const Leg& fixedLeg() const;
105
        //! just one cashflow in each leg
106
        const Leg& floatingLeg() const;
107
108
        Real fixedPayment() const;
109
        //@}
110
111
        //! \name Results
112
        //@{
113
        Real fixedLegNPV() const;
114
        Real floatingLegNPV() const;
115
        Real fairFixedPayment() const;
116
        Rate fairFixedRate(const DayCounter& dayCounter) const;
117
        //@}
118
119
      private:
120
        ZeroCouponSwap(Type type,
121
                       Real baseNominal,
122
                       const Date& startDate,
123
                       const Date& maturityDate,
124
                       ext::shared_ptr<IborIndex> iborIndex,
125
                       const Calendar& paymentCalendar,
126
                       BusinessDayConvention paymentConvention,
127
                       Natural paymentDelay);
128
129
        Type type_;
130
        Real baseNominal_;
131
        ext::shared_ptr<IborIndex> iborIndex_;
132
        Date startDate_;
133
        Date maturityDate_;
134
        Date paymentDate_;
135
    };
136
}
137
138
#endif