• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lballabio / QuantLib / 18905857194

29 Oct 2025 11:09AM UTC coverage: 74.32% (+0.4%) from 73.914%
18905857194

Pull #2344

github

web-flow
Merge d353587bf into d823f4ecb
Pull Request #2344: add multicurve bootstrap

99 of 103 new or added lines in 8 files covered. (96.12%)

216 existing lines in 13 files now uncovered.

57072 of 76792 relevant lines covered (74.32%)

8781066.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.81
/ql/instruments/yearonyearinflationswap.hpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
/*
4
 Copyright (C) 2007, 2009 Chris Kenyon
5
 Copyright (C) 2009 StatPro Italia srl
6

7
 This file is part of QuantLib, a free-software/open-source library
8
 for financial quantitative analysts and developers - http://quantlib.org/
9

10
 QuantLib is free software: you can redistribute it and/or modify it
11
 under the terms of the QuantLib license.  You should have received a
12
 copy of the license along with this program; if not, please email
13
 <quantlib-dev@lists.sf.net>. The license is also available online at
14
 <https://www.quantlib.org/license.shtml>.
15

16
 This program is distributed in the hope that it will be useful, but WITHOUT
17
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 FOR A PARTICULAR PURPOSE.  See the license for more details.
19
 */
20

21
/*! \file yearonyearinflationswap.hpp
22
 \brief Year-on-year inflation-indexed swap
23
 */
24

25
#ifndef quantlib_yyiis_hpp
26
#define quantlib_yyiis_hpp
27

28
#include <ql/instruments/swap.hpp>
29
#include <ql/indexes/inflationindex.hpp>
30
#include <ql/time/calendar.hpp>
31
#include <ql/time/daycounter.hpp>
32
#include <ql/time/schedule.hpp>
33

34
namespace QuantLib {
35

36
    //! Year-on-year inflation-indexed swap
37
    /*! Quoted as a fixed rate \f$ K \f$.  At start:
38
        \f[
39
        \sum_{i=1}^{M} P_n(0,t_i) N K =
40
        \sum_{i=1}^{M} P_n(0,t_i) N \left[ \frac{I(t_i)}{I(t_i-1)} - 1 \right]
41
        \f]
42
        where \f$ t_M \f$ is the maturity time, \f$ P_n(0,t) \f$ is the
43
        nominal discount factor at time \f$ t \f$, \f$ N \f$ is the
44
        notional, and \f$ I(t) \f$ is the inflation index value at
45
        time \f$ t \f$.
46
    */
47
    class YearOnYearInflationSwap : public Swap {
48
    public:
49
        class arguments;
50
        class results;
51
        class engine;
52
        YearOnYearInflationSwap(
53
            Type type,
54
            Real nominal,
55
            Schedule fixedSchedule,
56
            Rate fixedRate,
57
            DayCounter fixedDayCount,
58
            Schedule yoySchedule,
59
            ext::shared_ptr<YoYInflationIndex> yoyIndex,
60
            const Period& observationLag,
61
            CPI::InterpolationType interpolation,
62
            Spread spread,
63
            DayCounter yoyDayCount,
64
            Calendar paymentCalendar, // inflation index does not have a calendar
65
            BusinessDayConvention paymentConvention = ModifiedFollowing);
66

67
        // results
68
        virtual Real fixedLegNPV() const;
69
        virtual Rate fairRate() const;
70

71
        virtual Real yoyLegNPV() const;
72
        virtual Spread fairSpread() const;
73
        // inspectors
74
        virtual Type type() const;
75
        virtual Real nominal() const;
76

77
        virtual const Schedule& fixedSchedule() const;
78
        virtual Rate fixedRate() const;
79
        virtual const DayCounter& fixedDayCount() const;
80

81
        virtual const Schedule& yoySchedule() const;
82
        virtual const ext::shared_ptr<YoYInflationIndex>& yoyInflationIndex() const;
UNCOV
83
        virtual Period observationLag() const { return observationLag_; }
×
84
        virtual Spread spread() const;
85
        virtual const DayCounter& yoyDayCount() const;
86

UNCOV
87
        virtual Calendar paymentCalendar() const { return paymentCalendar_; }
×
88
        virtual BusinessDayConvention paymentConvention() const;
89

90
        virtual const Leg& fixedLeg() const;
91
        virtual const Leg& yoyLeg() const;
92

93
        // other
94
        void setupArguments(PricingEngine::arguments* args) const override;
95
        void fetchResults(const PricingEngine::results*) const override;
96
        ~YearOnYearInflationSwap() override = default;
5,619✔
97

98
      private:
99
        void setupExpired() const override;
100
        Type type_;
101
        Real nominal_;
102
        Schedule fixedSchedule_;
103
        Rate fixedRate_;
104
        DayCounter fixedDayCount_;
105
        Schedule yoySchedule_;
106
        ext::shared_ptr<YoYInflationIndex> yoyIndex_;
107
        Period observationLag_;
108
        Spread spread_;
109
        DayCounter yoyDayCount_;
110
        Calendar paymentCalendar_;
111
        BusinessDayConvention paymentConvention_;
112
        // results
113
        mutable Rate fairRate_;
114
        mutable Spread fairSpread_;
115
    };
116

117

118
    //! %Arguments for YoY swap calculation
119
    class YearOnYearInflationSwap::arguments : public Swap::arguments {
120
    public:
121
      arguments() : nominal(Null<Real>()) {}
122
      Type type = Receiver;
123
      Real nominal;
124

125
      std::vector<Date> fixedResetDates;
126
      std::vector<Date> fixedPayDates;
127
      std::vector<Time> yoyAccrualTimes;
128
      std::vector<Date> yoyResetDates;
129
      std::vector<Date> yoyFixingDates;
130
      std::vector<Date> yoyPayDates;
131

132
      std::vector<Real> fixedCoupons;
133
      std::vector<Spread> yoySpreads;
134
      std::vector<Real> yoyCoupons;
135
      void validate() const override;
136
    };
137

138
    //! %Results from YoY swap calculation
139
    class YearOnYearInflationSwap::results : public Swap::results {
140
    public:
141
        Rate fairRate;
142
        Spread fairSpread;
143
        void reset() override;
144
    };
145

146
    class YearOnYearInflationSwap::engine : public GenericEngine<YearOnYearInflationSwap::arguments,
147
                                                                 YearOnYearInflationSwap::results> {};
148

149

150
    // inline definitions
151

UNCOV
152
    inline Swap::Type YearOnYearInflationSwap::type() const {
×
UNCOV
153
        return type_;
×
154
    }
155

UNCOV
156
    inline Real YearOnYearInflationSwap::nominal() const {
×
UNCOV
157
        return nominal_;
×
158
    }
159

UNCOV
160
    inline const Schedule& YearOnYearInflationSwap::fixedSchedule() const {
×
UNCOV
161
        return fixedSchedule_;
×
162
    }
163

UNCOV
164
    inline Rate YearOnYearInflationSwap::fixedRate() const {
×
UNCOV
165
        return fixedRate_;
×
166
    }
167

168
    inline const DayCounter& YearOnYearInflationSwap::fixedDayCount() const {
×
169
        return fixedDayCount_;
×
170
    }
171

172
    inline const Schedule& YearOnYearInflationSwap::yoySchedule() const {
×
173
        return yoySchedule_;
×
174
    }
175

176
    inline const ext::shared_ptr<YoYInflationIndex>& YearOnYearInflationSwap::yoyInflationIndex() const {
×
177
        return yoyIndex_;
×
178
    }
179

180
    inline Spread YearOnYearInflationSwap::spread() const {
×
181
        return spread_;
×
182
    }
183

184
    inline const DayCounter& YearOnYearInflationSwap::yoyDayCount() const {
×
185
        return yoyDayCount_;
×
186
    }
187

188
    inline BusinessDayConvention YearOnYearInflationSwap::paymentConvention() const {
×
189
        return paymentConvention_;
14✔
190
    }
191

192
    inline const Leg& YearOnYearInflationSwap::fixedLeg() const {
×
193
        return legs_[0];
×
194
    }
195

196
    inline const Leg& YearOnYearInflationSwap::yoyLeg() const {
1✔
197
        return legs_[1];
1✔
198
    }
199

200
}
201

202
#endif
203

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc