Coverage Report

Created: 2026-06-23 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/cashflows/capflooredinflationcoupon.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2009 Chris Kenyon
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 capflooredinflationcoupon.hpp
21
 \brief caplet and floorlet pricing for YoY inflation coupons
22
 */
23
24
#ifndef quantlib_capfloored_inflation_coupon_hpp
25
#define quantlib_capfloored_inflation_coupon_hpp
26
27
#include <ql/cashflows/yoyinflationcoupon.hpp>
28
29
namespace QuantLib {
30
31
    //! Capped or floored inflation coupon.
32
    /*! Essentially a copy of the nominal version but taking a
33
        different index and a set of pricers (not just one).
34
35
        The payoff \f$ P \f$ of a capped inflation-rate coupon
36
        with paysWithin = true is:
37
38
        \f[ P = N \times T \times \min(a L + b, C). \f]
39
40
        where \f$ N \f$ is the notional, \f$ T \f$ is the accrual
41
        time, \f$ L \f$ is the inflation rate, \f$ a \f$ is its
42
        gearing, \f$ b \f$ is the spread, and \f$ C \f$ and \f$ F \f$
43
        the strikes.
44
45
        The payoff of a floored inflation-rate coupon is:
46
47
        \f[ P = N \times T \times \max(a L + b, F). \f]
48
49
        The payoff of a collared inflation-rate coupon is:
50
51
        \f[ P = N \times T \times \min(\max(a L + b, F), C). \f]
52
53
        If paysWithin = false then the inverse is returned
54
        (this provides for instrument cap and caplet prices).
55
56
        They can be decomposed in the following manner.  Decomposition
57
        of a capped floating rate coupon when paysWithin = true:
58
        \f[
59
        R = \min(a L + b, C) = (a L + b) + \min(C - b - \xi |a| L, 0)
60
        \f]
61
        where \f$ \xi = sgn(a) \f$. Then:
62
        \f[
63
        R = (a L + b) + |a| \min(\frac{C - b}{|a|} - \xi L, 0)
64
        \f]
65
     */
66
    class CappedFlooredYoYInflationCoupon : public YoYInflationCoupon {
67
      public:
68
        // we may watch an underlying coupon ...
69
        CappedFlooredYoYInflationCoupon(
70
                const ext::shared_ptr<YoYInflationCoupon>& underlying,
71
                Rate cap = Null<Rate>(),
72
                Rate floor = Null<Rate>());
73
74
        // ... or not
75
        CappedFlooredYoYInflationCoupon(const Date& paymentDate,
76
                                        Real nominal,
77
                                        const Date& startDate,
78
                                        const Date& endDate,
79
                                        Natural fixingDays,
80
                                        const ext::shared_ptr<YoYInflationIndex>& index,
81
                                        const Period& observationLag,
82
                                        const CPI::InterpolationType interpolation,
83
                                        const DayCounter& dayCounter,
84
                                        Real gearing = 1.0,
85
                                        Spread spread = 0.0,
86
                                        const Rate cap = Null<Rate>(),
87
                                        const Rate floor = Null<Rate>(),
88
                                        const Date& refPeriodStart = Date(),
89
                                        const Date& refPeriodEnd = Date())
90
0
        : YoYInflationCoupon(paymentDate, nominal, startDate, endDate,
91
0
                             fixingDays, index, observationLag, interpolation,
92
0
                             dayCounter, gearing, spread,
93
0
                             refPeriodStart, refPeriodEnd),
94
0
          isFloored_(false), isCapped_(false) {
95
0
            setCommon(cap, floor);
96
0
        }
97
98
        //! \name augmented Coupon interface
99
        //@{
100
        //! swap(let) rate
101
        Rate rate() const override;
102
        //! cap
103
        Rate cap() const;
104
        //! floor
105
        Rate floor() const;
106
        //! effective cap of fixing
107
        Rate effectiveCap() const;
108
        //! effective floor of fixing
109
        Rate effectiveFloor() const;
110
        //@}
111
112
        //! \name Observer interface
113
        //@{
114
        void update() override;
115
        //@}
116
117
        //! \name Visitability
118
        //@{
119
        void accept(AcyclicVisitor& v) override;
120
        //@}
121
122
        //! this returns the expected rate before cap and floor are applied
123
        Rate underlyingRate() const;
124
125
0
        bool isCapped() const { return isCapped_; }
126
0
        bool isFloored() const { return isFloored_; }
127
128
        void setPricer(const ext::shared_ptr<YoYInflationCouponPricer>&);
129
130
      protected:
131
        // data, we only use underlying_ if it was constructed that way,
132
        // generally we use the shared_ptr conversion to boolean to test
133
        ext::shared_ptr<YoYInflationCoupon> underlying_;
134
        bool isFloored_, isCapped_;
135
        Rate cap_, floor_;
136
      private:
137
        void setCommon(Rate cap, Rate floor);
138
    };
139
140
}
141
142
#endif
143