Coverage Report

Created: 2026-06-08 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/cashflows/yoyinflationcoupon.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 yoyinflationcoupon.hpp
21
 \brief Coupon paying a yoy inflation index
22
 */
23
24
#ifndef quantlib_newyoy_coupon_hpp
25
#define quantlib_newyoy_coupon_hpp
26
27
#include <ql/cashflows/inflationcoupon.hpp>
28
#include <ql/indexes/inflationindex.hpp>
29
#include <ql/time/schedule.hpp>
30
31
namespace QuantLib {
32
    class YoYInflationCouponPricer;
33
34
    //! %Coupon paying a YoY-inflation type index
35
    class YoYInflationCoupon : public InflationCoupon {
36
      public:
37
        YoYInflationCoupon(const Date& paymentDate,
38
                           Real nominal,
39
                           const Date& startDate,
40
                           const Date& endDate,
41
                           Natural fixingDays,
42
                           const ext::shared_ptr<YoYInflationIndex>& index,
43
                           const Period& observationLag,
44
                           CPI::InterpolationType interpolation,
45
                           const DayCounter& dayCounter,
46
                           Real gearing = 1.0,
47
                           Spread spread = 0.0,
48
                           const Date& refPeriodStart = Date(),
49
                           const Date& refPeriodEnd = Date());
50
51
        //! \name Inspectors
52
        //@{
53
        //! index gearing, i.e. multiplicative coefficient for the index
54
0
        Real gearing() const { return gearing_; }
55
        //! spread paid over the fixing of the underlying index
56
0
        Spread spread() const { return spread_; }
57
58
        Rate indexFixing() const override;
59
60
        Rate adjustedFixing() const;
61
62
        const ext::shared_ptr<YoYInflationIndex>& yoyIndex() const;
63
        CPI::InterpolationType interpolation() const;
64
        //@}
65
66
        //! \name Visitability
67
        //@{
68
        void accept(AcyclicVisitor&) override;
69
        //@}
70
71
      private:
72
        ext::shared_ptr<YoYInflationIndex> yoyIndex_;
73
        CPI::InterpolationType interpolation_;
74
      protected:
75
        Real gearing_;
76
        Spread spread_;
77
        bool checkPricerImpl(const ext::shared_ptr<InflationCouponPricer>&) const override;
78
    };
79
80
    inline const ext::shared_ptr<YoYInflationIndex>&
81
0
    YoYInflationCoupon::yoyIndex() const {
82
0
        return yoyIndex_;
83
0
    }
84
85
0
    inline CPI::InterpolationType YoYInflationCoupon::interpolation() const {
86
0
        return interpolation_;
87
0
    }
88
89
0
    inline Rate YoYInflationCoupon::adjustedFixing() const {
90
0
        return (rate()-spread())/gearing();
91
0
    }
92
93
94
95
96
    //! Helper class building a sequence of capped/floored yoy inflation coupons
97
    class yoyInflationLeg {
98
    public:
99
      yoyInflationLeg(Schedule schedule,
100
                      Calendar cal,
101
                      ext::shared_ptr<YoYInflationIndex> index,
102
                      const Period& observationLag,
103
                      CPI::InterpolationType interpolation);
104
      yoyInflationLeg& withNotionals(Real notional);
105
      yoyInflationLeg& withNotionals(const std::vector<Real>& notionals);
106
      yoyInflationLeg& withPaymentDayCounter(const DayCounter&);
107
      yoyInflationLeg& withPaymentAdjustment(BusinessDayConvention);
108
      yoyInflationLeg& withFixingDays(Natural fixingDays);
109
      yoyInflationLeg& withFixingDays(const std::vector<Natural>& fixingDays);
110
      yoyInflationLeg& withGearings(Real gearing);
111
      yoyInflationLeg& withGearings(const std::vector<Real>& gearings);
112
      yoyInflationLeg& withSpreads(Spread spread);
113
      yoyInflationLeg& withSpreads(const std::vector<Spread>& spreads);
114
      yoyInflationLeg& withCaps(Rate cap);
115
      yoyInflationLeg& withCaps(const std::vector<Rate>& caps);
116
      yoyInflationLeg& withFloors(Rate floor);
117
      yoyInflationLeg& withFloors(const std::vector<Rate>& floors);
118
      operator Leg() const;
119
    private:
120
        Schedule schedule_;
121
        ext::shared_ptr<YoYInflationIndex> index_;
122
        Period observationLag_;
123
        CPI::InterpolationType interpolation_;
124
        std::vector<Real> notionals_;
125
        DayCounter paymentDayCounter_;
126
        BusinessDayConvention paymentAdjustment_ = ModifiedFollowing;
127
        Calendar paymentCalendar_;
128
        std::vector<Natural> fixingDays_;
129
        std::vector<Real> gearings_;
130
        std::vector<Spread> spreads_;
131
        std::vector<Rate> caps_, floors_;
132
    };
133
134
135
136
}
137
138
#endif
139