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

lballabio / QuantLib / 20336157418

18 Dec 2025 11:57AM UTC coverage: 74.15% (-0.1%) from 74.295%
20336157418

Pull #2368

github

web-flow
Merge 856b09650 into c15a6fecb
Pull Request #2368: Fx options utils - `BlackVolatilitySurfaceDelta` class

109 of 170 new or added lines in 5 files covered. (64.12%)

423 existing lines in 23 files now uncovered.

57618 of 77705 relevant lines covered (74.15%)

8752879.52 hits per line

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

81.82
/ql/termstructures/inflationtermstructure.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

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 inflationtermstructure.hpp
21
    \brief Base classes for inflation term structures.
22
*/
23

24
#ifndef quantlib_inflation_termstructure_hpp
25
#define quantlib_inflation_termstructure_hpp
26

27
#include <ql/termstructures/yieldtermstructure.hpp>
28
#include <ql/termstructures/inflation/seasonality.hpp>
29

30
namespace QuantLib {
31

32
    class InflationIndex;
33

34
    //! Interface for inflation term structures.
35
    /*! \ingroup inflationtermstructures */
36
    class InflationTermStructure : public TermStructure {
37
      public:
38
        //! \name Constructors
39
        //@{
40
        InflationTermStructure(Date baseDate,
41
                               Frequency frequency,
42
                               const DayCounter& dayCounter = DayCounter(),
43
                               ext::shared_ptr<Seasonality> seasonality = {},
44
                               Rate baseRate = Null<Rate>());
45

46
        InflationTermStructure(const Date& referenceDate,
47
                               Date baseDate,
48
                               Frequency frequency,
49
                               const DayCounter& dayCounter = DayCounter(),
50
                               ext::shared_ptr<Seasonality> seasonality = {},
51
                               Rate baseRate = Null<Rate>());
52

53
        InflationTermStructure(Natural settlementDays,
54
                               const Calendar& calendar,
55
                               Date baseDate,
56
                               Frequency frequency,
57
                               const DayCounter& dayCounter = DayCounter(),
58
                               ext::shared_ptr<Seasonality> seasonality = {},
59
                               Rate baseRate = Null<Rate>());
60
        //@}
61

62
        QL_DEPRECATED_DISABLE_WARNING
63
        ~InflationTermStructure() override = default;
30✔
64
        QL_DEPRECATED_ENABLE_WARNING
65

66
        //! \name Inflation interface
67
        //@{
68
        /*! \deprecated Do not use; inflation curves always have an explicit
69
                        base date now.
70
                        Deprecated in version 1.39.
71
        */
72
        [[deprecated("Do not use; inflation curves always have an explicit base date now.")]]
73
        virtual Period observationLag() const;
74

75
        virtual Frequency frequency() const;
76
        virtual Rate baseRate() const;
77

78
        //! minimum (base) date
79
        /*! The last date for which we have information. */
80
        virtual Date baseDate() const;
81

82
        /*! \deprecated Do not use; inflation curves always have an explicit
83
                        base date now.
84
                        Deprecated in version 1.39.
85
        */
86
        [[deprecated("Do not use; inflation curves always have an explicit base date now.")]]
87
        bool hasExplicitBaseDate() const {
88
            return true;
89
        }
90
        //@}
91

92
        //! \name Seasonality
93
        //@{
94
        void setSeasonality(const ext::shared_ptr<Seasonality>& seasonality);
95
        ext::shared_ptr<Seasonality> seasonality() const;
96
        bool hasSeasonality() const;
97
        //@}
98

99
      protected:
100
        void checkRange(const Date&,
101
                        bool extrapolate) const;
102
        void checkRange(Time t,
103
                        bool extrapolate) const;
104

105
        ext::shared_ptr<Seasonality> seasonality_;
106

107
        /*! \deprecated Do not use; inflation curves always have an explicit
108
                        base date now.
109
                        Deprecated in version 1.39.
110
        */
111
        [[deprecated("Do not use; inflation curves always have an explicit base date now.")]]
112
        Period observationLag_;
113

114
        Frequency frequency_;
115
        mutable Rate baseRate_;
116
        // Can be set by subclasses that don't have baseDate available in constructors.
117
        Date baseDate_;
118
    };
119

120
    //! Interface for zero inflation term structures.
121
    class ZeroInflationTermStructure : public InflationTermStructure {
122
      public:
123
        //! \name Constructors
124
        //@{
125
        ZeroInflationTermStructure(Date baseDate,
126
                                   Frequency frequency,
127
                                   const DayCounter& dayCounter,
128
                                   const ext::shared_ptr<Seasonality>& seasonality = {});
129

130
        ZeroInflationTermStructure(const Date& referenceDate,
131
                                   Date baseDate,
132
                                   Frequency frequency,
133
                                   const DayCounter& dayCounter,
134
                                   const ext::shared_ptr<Seasonality>& seasonality = {});
135

136
        ZeroInflationTermStructure(Natural settlementDays,
137
                                   const Calendar& calendar,
138
                                   Date baseDate,
139
                                   Frequency frequency,
140
                                   const DayCounter& dayCounter,
141
                                   const ext::shared_ptr<Seasonality>& seasonality = {});
142
        //@}
143

144
        //! \name Inspectors
145
        //@{
146
        //! zero-coupon inflation rate.
147
        /*! The zero term structure uses yearly compounding, which is
148
            assumed for ZCIIS instrument quotes.
149

150
            If you want to get predictions of RPI/CPI/etc. use the
151
            corresponding index instead; if you need a ZCIIS rate,
152
            retrieve it from the instrument.
153
        */
154
        Rate zeroRate(const Date& d, bool extrapolate = false) const;
155

156
        /*! \deprecated Use the overload without a lag instead.
157
                        Deprecated in version 1.41.
158
        */
159
        [[deprecated("Use the overload without a lag instead")]]
160
        Rate zeroRate(const Date& d, const Period& instObsLag,
161
                      bool forceLinearInterpolation = false,
162
                      bool extrapolate = false) const;
163

164
        //! zero-coupon inflation rate.
165
        /*! \warning Since inflation is highly linked to dates (lags,
166
                     interpolation, months for seasonality, etc) this
167
                     method cannot account for all effects.  If you
168
                     call it, You'll have to manage lag, seasonality
169
                     etc. yourself.
170
        */
171
        Rate zeroRate(Time t,
172
                      bool extrapolate = false) const;
173
        //@}
174
      protected:
175
        //! to be defined in derived classes
176
        virtual Rate zeroRateImpl(Time t) const = 0;
177
    };
178

179

180
    //! Base class for year-on-year inflation term structures.
181
    class YoYInflationTermStructure : public InflationTermStructure {
182
      public:
183
        //! \name Constructors
184
        //@{
185
        YoYInflationTermStructure(Date baseDate,
186
                                  Rate baseYoYRate,
187
                                  Frequency frequency,
188
                                  const DayCounter& dayCounter,
189
                                  const ext::shared_ptr<Seasonality>& seasonality = {});
190

191
        YoYInflationTermStructure(const Date& referenceDate,
192
                                  Date baseDate,
193
                                  Rate baseYoYRate,
194
                                  Frequency frequency,
195
                                  const DayCounter& dayCounter,
196
                                  const ext::shared_ptr<Seasonality>& seasonality = {});
197

198
        YoYInflationTermStructure(Natural settlementDays,
199
                                  const Calendar& calendar,
200
                                  Date baseDate,
201
                                  Rate baseYoYRate,
202
                                  Frequency frequency,
203
                                  const DayCounter& dayCounter,
204
                                  const ext::shared_ptr<Seasonality>& seasonality = {});
205

206
        /*! \deprecated Use an overload with an explicit base date and without indexIsInterpolated.
207
                        Deprecated in version 1.37.
208
        */
209
        [[deprecated("Use an overload with an explicit base date and without indexIsInterpolated")]]
210
        YoYInflationTermStructure(Date baseDate,
211
                                  Rate baseYoYRate,
212
                                  Frequency frequency,
213
                                  bool indexIsInterpolated,
214
                                  const DayCounter& dayCounter,
215
                                  const ext::shared_ptr<Seasonality>& seasonality = {});
216

217
        /*! \deprecated Use an overload with an explicit base date and without indexIsInterpolated.
218
                        Deprecated in version 1.37.
219
        */
220
        [[deprecated("Use an overload with an explicit base date and without indexIsInterpolated")]]
221
        YoYInflationTermStructure(const Date& referenceDate,
222
                                  Date baseDate,
223
                                  Rate baseYoYRate,
224
                                  Frequency frequency,
225
                                  bool indexIsInterpolated,
226
                                  const DayCounter& dayCounter,
227
                                  const ext::shared_ptr<Seasonality>& seasonality = {});
228

229
        /*! \deprecated Use an overload with an explicit base date and without indexIsInterpolated.
230
                        Deprecated in version 1.37.
231
        */
232
        [[deprecated("Use an overload with an explicit base date and without indexIsInterpolated")]]
233
        YoYInflationTermStructure(Natural settlementDays,
234
                                  const Calendar& calendar,
235
                                  Date baseDate,
236
                                  Rate baseYoYRate,
237
                                  Frequency frequency,
238
                                  bool indexIsInterpolated,
239
                                  const DayCounter& dayCounter,
240
                                  const ext::shared_ptr<Seasonality>& seasonality = {});
241
        //@}
242

243
        QL_DEPRECATED_DISABLE_WARNING
244
        ~YoYInflationTermStructure() override = default;
11✔
245
        QL_DEPRECATED_ENABLE_WARNING
246

247
        //! \name Inspectors
248
        //@{
249
        //! year-on-year inflation rate.
250
        /*! This does not return the year-on-year swap (YYIIS) rate.
251
            If you need that rate, retrieve it from the corresponding
252
            instrument instead.
253
        */
254
        Rate yoyRate(const Date& d, bool extrapolate = false) const;
255

256
        /*! \deprecated Use the overload without a lag instead.
257
                        Deprecated in version 1.41.
258
        */
259
        [[deprecated("Use the overload without a lag instead")]]
260
        Rate yoyRate(const Date& d, const Period& instObsLag,
261
                     bool forceLinearInterpolation = false,
262
                     bool extrapolate = false) const;
263

264
        //! year-on-year inflation rate.
265
        /*! \warning Since inflation is highly linked to dates (lags,
266
                     interpolation, months for seasonality, etc) this
267
                     method cannot account for all effects.  If you
268
                     call it, You'll have to manage lag, seasonality
269
                     etc. yourself.
270
        */
271
        Rate yoyRate(Time t,
272
                     bool extrapolate = false) const;
273
        //@}
274

275
        /*! \deprecated This method will disappear. When it does, the curve will behave as if it returned false.
276
                        Deprecated in version 1.37.
277
        */
278
        [[deprecated("This method will disappear. When it does, the curve will behave as if it returned false")]]
279
        virtual bool indexIsInterpolated() const;
280
      protected:
281
        //! to be defined in derived classes
282
        virtual Rate yoyRateImpl(Time time) const = 0;
283

284
        /*! \deprecated This data member will disappear. When it does, the curve will behave as if it was false.
285
                        Deprecated in version 1.37.
286
        */
287
        [[deprecated("This data member will disappear. When it does, the curve will behave as if it was false")]]
288
        bool indexIsInterpolated_ = false;
289
    };
290

291

292
    //! utility function giving the inflation period for a given date
293
    std::pair<Date,Date> inflationPeriod(const Date&,
294
                                         Frequency);
295

296
    //! utility function giving the time between two dates depending on
297
    //! index frequency and interpolation, and a day counter
298
    Time inflationYearFraction(Frequency ,
299
                               bool indexIsInterpolated,
300
                               const DayCounter&,
301
                               const Date&, const Date&);
302

303

304
    // inline
305

UNCOV
306
    inline Period InflationTermStructure::observationLag() const {
×
307
        QL_DEPRECATED_DISABLE_WARNING
UNCOV
308
        return observationLag_;
×
309
        QL_DEPRECATED_ENABLE_WARNING
310
    }
311

312
    inline Frequency InflationTermStructure::frequency() const {
240,218✔
313
        return frequency_;
240,218✔
314
    }
315

316
    inline Rate InflationTermStructure::baseRate() const {
9✔
317
        QL_REQUIRE(baseRate_ != Null<Real>(), "base rate not available");
9✔
318
        return baseRate_;
9✔
319
    }
320

321
    inline ext::shared_ptr<Seasonality> InflationTermStructure::seasonality() const {
322
        return seasonality_;
323
    }
324

325
    inline bool InflationTermStructure::hasSeasonality() const {
326
        return static_cast<bool>(seasonality_);
327
    }
328

329
    inline bool YoYInflationTermStructure::indexIsInterpolated() const {
235,315✔
330
        QL_DEPRECATED_DISABLE_WARNING
331
        return indexIsInterpolated_;
235,315✔
332
        QL_DEPRECATED_ENABLE_WARNING
333
    }
334

335
}
336

337
#endif
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

© 2026 Coveralls, Inc