QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
inflationtermstructure.hpp
Go to the documentation of this file.
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
29
30namespace QuantLib {
31
32 class InflationIndex;
33
34 //! Interface for inflation term structures.
35 /*! \ingroup inflationtermstructures */
37 public:
38 //! \name Constructors
39 //@{
43 ext::shared_ptr<Seasonality> seasonality = {},
45
50 ext::shared_ptr<Seasonality> seasonality = {},
52
54 const Calendar& calendar,
58 ext::shared_ptr<Seasonality> seasonality = {},
60 //@}
61
63 ~InflationTermStructure() override = default;
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.")]]
117
120
121 private:
123 };
124
125 //! Interface for zero inflation term structures.
127 public:
128 //! \name Constructors
129 //@{
132 const DayCounter& dayCounter,
133 const ext::shared_ptr<Seasonality>& seasonality = {});
134
138 const DayCounter& dayCounter,
139 const ext::shared_ptr<Seasonality>& seasonality = {});
140
142 const Calendar& calendar,
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 */
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.
182 public:
183 //! \name Constructors
184 //@{
186 Rate baseYoYRate,
188 const DayCounter& dayCounter,
189 const ext::shared_ptr<Seasonality>& seasonality = {});
190
193 Rate baseYoYRate,
195 const DayCounter& dayCounter,
196 const ext::shared_ptr<Seasonality>& seasonality = {});
197
199 const Calendar& calendar,
201 Rate baseYoYRate,
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")]]
211 Rate baseYoYRate,
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")]]
223 Rate baseYoYRate,
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")]]
234 const Calendar& calendar,
236 Rate baseYoYRate,
239 const DayCounter& dayCounter,
240 const ext::shared_ptr<Seasonality>& seasonality = {});
241 //@}
242
244 ~YoYInflationTermStructure() override = default;
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 */
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")]]
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
293 bool indexIsInterpolated,
294 const DayCounter&,
295 const Date&, const Date&);
296
297
298 // inline
299
302 return observationLag_;
304 }
305
307 return frequency_;
308 }
309
311 QL_REQUIRE(baseRate_ != Null<Real>(), "base rate not available");
312 return baseRate_;
313 }
314
315 inline ext::shared_ptr<Seasonality> InflationTermStructure::seasonality() const {
316 return seasonality_;
317 }
318
320 return static_cast<bool>(seasonality_);
321 }
322
327 }
328
329}
330
331#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Interface for inflation term structures.
ext::shared_ptr< Seasonality > seasonality_
void setSeasonality(const ext::shared_ptr< Seasonality > &seasonality)
ext::shared_ptr< Seasonality > seasonality() const
QL_DEPRECATED_DISABLE_WARNING ~InflationTermStructure() override=default
virtual Date baseDate() const
minimum (base) date
void checkRange(const Date &, bool extrapolate) const
template class providing a null value for a given type.
Definition: null.hpp:59
Basic term-structure functionality.
virtual Natural settlementDays() const
the settlementDays used for reference date calculation
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
virtual Calendar calendar() const
the calendar used for reference and/or option date calculation
virtual DayCounter dayCounter() const
the day counter used for date/time conversion
Base class for year-on-year inflation term structures.
virtual Rate yoyRateImpl(Time time) const =0
to be defined in derived classes
QL_DEPRECATED_DISABLE_WARNING ~YoYInflationTermStructure() override=default
Rate yoyRate(const Date &d, const Period &instObsLag=Period(-1, Days), bool forceLinearInterpolation=false, bool extrapolate=false) const
year-on-year inflation rate.
Interface for zero inflation term structures.
virtual Rate zeroRateImpl(Time t) const =0
to be defined in derived classes
Rate zeroRate(const Date &d, const Period &instObsLag=Period(-1, Days), bool forceLinearInterpolation=false, bool extrapolate=false) const
zero-coupon inflation rate.
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
Frequency
Frequency of events.
Definition: frequency.hpp:37
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:37
std::pair< Date, Date > inflationPeriod(const Date &d, Frequency frequency)
utility function giving the inflation period for a given date
Time inflationYearFraction(Frequency f, bool indexIsInterpolated, const DayCounter &dayCounter, const Date &d1, const Date &d2)
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217
Interest-rate term structure.