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

lballabio / QuantLib / 14910176578

08 May 2025 03:28PM UTC coverage: 73.315% (+0.02%) from 73.3%
14910176578

Pull #2195

github

web-flow
Merge 3a61f499c into 5d972fb7b
Pull Request #2195: Added `Handle<Quote>` for spread in `OISRateHelper`

32 of 33 new or added lines in 2 files covered. (96.97%)

277 existing lines in 25 files now uncovered.

56277 of 76761 relevant lines covered (73.31%)

8687029.35 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
 <http://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;
26✔
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

81
            When not set directly (the recommended option), it is
82
            calculated base on an observation lag relative to today.
83
        */
84
        virtual Date baseDate() const;
85

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

96
        //! \name Seasonality
97
        //@{
98
        void setSeasonality(const ext::shared_ptr<Seasonality>& seasonality);
99
        ext::shared_ptr<Seasonality> seasonality() const;
100
        bool hasSeasonality() const;
101
        //@}
102

103
      protected:
104
        void checkRange(const Date&,
105
                        bool extrapolate) const;
106
        void checkRange(Time t,
107
                        bool extrapolate) const;
108

109
        ext::shared_ptr<Seasonality> seasonality_;
110

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

118
        Frequency frequency_;
119
        mutable Rate baseRate_;
120

121
      private:
122
        Date baseDate_;
123
    };
124

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

135
        ZeroInflationTermStructure(const Date& referenceDate,
136
                                   Date baseDate,
137
                                   Frequency frequency,
138
                                   const DayCounter& dayCounter,
139
                                   const ext::shared_ptr<Seasonality>& seasonality = {});
140

141
        ZeroInflationTermStructure(Natural settlementDays,
142
                                   const Calendar& calendar,
143
                                   Date baseDate,
144
                                   Frequency frequency,
145
                                   const DayCounter& dayCounter,
146
                                   const ext::shared_ptr<Seasonality>& seasonality = {});
147
        //@}
148

149
        //! \name Inspectors
150
        //@{
151
        //! zero-coupon inflation rate.
152
        /*! Essentially the fair rate for a zero-coupon inflation swap
153
            (by definition), i.e. the zero term structure uses yearly
154
            compounding, which is assumed for ZCIIS instrument quotes.
155

156
            \note by default you get the same as lag and interpolation
157
            as the term structure.
158
            If you want to get predictions of RPI/CPI/etc then use an
159
            index.
160
        */
161
        Rate zeroRate(const Date& d, const Period& instObsLag = Period(-1,Days),
162
                      bool forceLinearInterpolation = false,
163
                      bool extrapolate = false) const;
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
        /*! The forceLinearInterpolation parameter is relative to the
251
            frequency of the TS.
252

253
            \note this is not the year-on-year swap (YYIIS) rate.
254
        */
255
        Rate yoyRate(const Date& d, const Period& instObsLag = Period(-1,Days),
256
                     bool forceLinearInterpolation = false,
257
                     bool extrapolate = false) const;
258
        //! year-on-year inflation rate.
259
        /*! \warning Since inflation is highly linked to dates (lags,
260
                     interpolation, months for seasonality, etc) this
261
                     method cannot account for all effects.  If you
262
                     call it, You'll have to manage lag, seasonality
263
                     etc. yourself.
264
        */
265
        Rate yoyRate(Time t,
266
                     bool extrapolate = false) const;
267
        //@}
268

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

278
        /*! \deprecated This data member will disappear. When it does, the curve will behave as if it was false.
279
                        Deprecated in version 1.37.
280
        */
281
        [[deprecated("This data member will disappear. When it does, the curve will behave as if it was false")]]
282
        bool indexIsInterpolated_ = false;
283
    };
284

285

286
    //! utility function giving the inflation period for a given date
287
    std::pair<Date,Date> inflationPeriod(const Date&,
288
                                         Frequency);
289

290
    //! utility function giving the time between two dates depending on
291
    //! index frequency and interpolation, and a day counter
292
    Time inflationYearFraction(Frequency ,
293
                               bool indexIsInterpolated,
294
                               const DayCounter&,
295
                               const Date&, const Date&);
296

297

298
    // inline
299

UNCOV
300
    inline Period InflationTermStructure::observationLag() const {
×
301
        QL_DEPRECATED_DISABLE_WARNING
UNCOV
302
        return observationLag_;
×
303
        QL_DEPRECATED_ENABLE_WARNING
304
    }
305

306
    inline Frequency InflationTermStructure::frequency() const {
237,589✔
307
        return frequency_;
237,589✔
308
    }
309

310
    inline Rate InflationTermStructure::baseRate() const {
9✔
311
        QL_REQUIRE(baseRate_ != Null<Real>(), "base rate not available");
9✔
312
        return baseRate_;
9✔
313
    }
314

315
    inline ext::shared_ptr<Seasonality> InflationTermStructure::seasonality() const {
316
        return seasonality_;
317
    }
318

319
    inline bool InflationTermStructure::hasSeasonality() const {
320
        return static_cast<bool>(seasonality_);
321
    }
322

323
    inline bool YoYInflationTermStructure::indexIsInterpolated() const {
234,533✔
324
        QL_DEPRECATED_DISABLE_WARNING
325
        return indexIsInterpolated_;
234,533✔
326
        QL_DEPRECATED_ENABLE_WARNING
327
    }
328

329
}
330

331
#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

© 2025 Coveralls, Inc