QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
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 /*! \deprecated Use another overload and pass the base date directly
62 instead of using a lag.
63 Deprecated in version 1.34.
64 */
70 ext::shared_ptr<Seasonality> seasonality = {});
71
72 /*! \deprecated Use another overload and pass the base date directly
73 instead of using a lag.
74 Deprecated in version 1.34.
75 */
81 const Calendar& calendar = Calendar(),
83 ext::shared_ptr<Seasonality> seasonality = {});
84
85 /*! \deprecated Use another overload and pass the base date directly
86 instead of using a lag.
87 Deprecated in version 1.34.
88 */
91 const Calendar& calendar,
96 ext::shared_ptr<Seasonality> seasonality = {});
97 //@}
98
99 //! \name Inflation interface
100 //@{
101 virtual Period observationLag() const;
102 virtual Frequency frequency() const;
103 virtual Rate baseRate() const;
104
105 //! minimum (base) date
106 /*! The last date for which we have information.
107
108 When not set directly (the recommended option), it is
109 calculated base on an observation lag relative to today.
110 */
111 virtual Date baseDate() const;
112
113 /*! This can be used temporarily to check whether the term structure
114 was created using one of the new constructors taking a base date
115 or one of the deprecated ones taking an observation lag.
116 */
117 bool hasExplicitBaseDate() const {
119 }
120 //@}
121
122 //! \name Seasonality
123 //@{
124 /*! \deprecated Use the overload taking a pointer and pass an empty one to remove seasonality.
125 Deprecated in version 1.34.
126 */
127 [[deprecated("Use the overload taking a pointer and pass an empty one to remove seasonality.")]]
129 void setSeasonality(const ext::shared_ptr<Seasonality>& seasonality);
130 ext::shared_ptr<Seasonality> seasonality() const;
131 bool hasSeasonality() const;
132 //@}
133
134 protected:
135 /*! \deprecated Do not use; set baseRate_ directly if needed.
136 Deprecated in version 1.34.
137 */
138 [[deprecated("Do not use; set baseRate_ directly if needed.")]]
139 virtual void setBaseRate(const Rate& r) { baseRate_ = r; }
140
141 // range-checking
142 void checkRange(const Date&,
143 bool extrapolate) const;
144 void checkRange(Time t,
145 bool extrapolate) const;
146
147 ext::shared_ptr<Seasonality> seasonality_;
151
152 private:
155 };
156
157 //! Interface for zero inflation term structures.
159 public:
160 //! \name Constructors
161 //@{
164 const DayCounter& dayCounter,
165 const ext::shared_ptr<Seasonality>& seasonality = {});
166
170 const DayCounter& dayCounter,
171 const ext::shared_ptr<Seasonality>& seasonality = {});
172
174 const Calendar& calendar,
177 const DayCounter& dayCounter,
178 const ext::shared_ptr<Seasonality>& seasonality = {});
179
180 /*! \deprecated Use another overload and pass the base date directly
181 instead of using a lag. A base rate should not be needed.
182 Deprecated in version 1.34.
183 */
186 Rate baseZeroRate,
187 const Period& lag,
189 const ext::shared_ptr<Seasonality>& seasonality = {});
190
191 /*! \deprecated Use another overload and pass the base date directly
192 instead of using a lag. A base rate should not be needed.
193 Deprecated in version 1.34.
194 */
197 const Calendar& calendar,
198 const DayCounter& dayCounter,
199 Rate baseZeroRate,
200 const Period& lag,
202 const ext::shared_ptr<Seasonality>& seasonality = {});
203
204 /*! \deprecated Use another overload and pass the base date directly
205 instead of using a lag. A base rate should not be needed.
206 Deprecated in version 1.34.
207 */
210 const Calendar& calendar,
211 const DayCounter& dayCounter,
212 Rate baseZeroRate,
213 const Period& lag,
215 const ext::shared_ptr<Seasonality>& seasonality = {});
216 //@}
217
218 //! \name Inspectors
219 //@{
220 //! zero-coupon inflation rate.
221 /*! Essentially the fair rate for a zero-coupon inflation swap
222 (by definition), i.e. the zero term structure uses yearly
223 compounding, which is assumed for ZCIIS instrument quotes.
224
225 \note by default you get the same as lag and interpolation
226 as the term structure.
227 If you want to get predictions of RPI/CPI/etc then use an
228 index.
229 */
230 Rate zeroRate(const Date& d, const Period& instObsLag = Period(-1,Days),
231 bool forceLinearInterpolation = false,
232 bool extrapolate = false) const;
233 //! zero-coupon inflation rate.
234 /*! \warning Since inflation is highly linked to dates (lags,
235 interpolation, months for seasonality, etc) this
236 method cannot account for all effects. If you
237 call it, You'll have to manage lag, seasonality
238 etc. yourself.
239 */
241 bool extrapolate = false) const;
242 //@}
243 protected:
244 //! to be defined in derived classes
245 virtual Rate zeroRateImpl(Time t) const = 0;
246 };
247
248
249 //! Base class for year-on-year inflation term structures.
251 public:
252 //! \name Constructors
253 //@{
255 Rate baseYoYRate,
258 const DayCounter& dayCounter,
259 const ext::shared_ptr<Seasonality>& seasonality = {});
260
263 Rate baseYoYRate,
266 const DayCounter& dayCounter,
267 const ext::shared_ptr<Seasonality>& seasonality = {});
268
270 const Calendar& calendar,
272 Rate baseYoYRate,
275 const DayCounter& dayCounter,
276 const ext::shared_ptr<Seasonality>& seasonality = {});
277
278 /*! \deprecated Use another overload and pass the base date directly
279 instead of using a lag.
280 Deprecated in version 1.34.
281 */
284 Rate baseYoYRate,
285 const Period& lag,
288 const ext::shared_ptr<Seasonality>& seasonality = {});
289
290 /*! \deprecated Use another overload and pass the base date directly
291 instead of using a lag.
292 Deprecated in version 1.34.
293 */
296 const Calendar& calendar,
297 const DayCounter& dayCounter,
298 Rate baseYoYRate,
299 const Period& lag,
302 const ext::shared_ptr<Seasonality>& seasonality = {});
303
304 /*! \deprecated Use another overload and pass the base date directly
305 instead of using a lag.
306 Deprecated in version 1.34.
307 */
310 const Calendar& calendar,
311 const DayCounter& dayCounter,
312 Rate baseYoYRate,
313 const Period& lag,
316 const ext::shared_ptr<Seasonality>& seasonality = {});
317 //@}
318
319 //! \name Inspectors
320 //@{
321 //! year-on-year inflation rate.
322 /*! The forceLinearInterpolation parameter is relative to the
323 frequency of the TS.
324
325 \note this is not the year-on-year swap (YYIIS) rate.
326 */
327 Rate yoyRate(const Date& d, const Period& instObsLag = Period(-1,Days),
328 bool forceLinearInterpolation = false,
329 bool extrapolate = false) const;
330 //! year-on-year inflation rate.
331 /*! \warning Since inflation is highly linked to dates (lags,
332 interpolation, months for seasonality, etc) this
333 method cannot account for all effects. If you
334 call it, You'll have to manage lag, seasonality
335 etc. yourself.
336 */
338 bool extrapolate = false) const;
339 //@}
340
341 virtual bool indexIsInterpolated() const;
342 protected:
343 //! to be defined in derived classes
344 virtual Rate yoyRateImpl(Time time) const = 0;
345 private:
347 };
348
349
350 //! utility function giving the inflation period for a given date
351 std::pair<Date,Date> inflationPeriod(const Date&,
352 Frequency);
353
354 //! utility function giving the time between two dates depending on
355 //! index frequency and interpolation, and a day counter
357 bool indexIsInterpolated,
358 const DayCounter&,
359 const Date&, const Date&);
360
361
362 // inline
363
365 return observationLag_;
366 }
367
369 return frequency_;
370 }
371
373 QL_REQUIRE(baseRate_ != Null<Real>(), "base rate not available");
374 return baseRate_;
375 }
376
377 inline ext::shared_ptr<Seasonality> InflationTermStructure::seasonality() const {
378 return seasonality_;
379 }
380
382 return static_cast<bool>(seasonality_);
383 }
384
387 }
388
389}
390
391#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_
ext::shared_ptr< Seasonality > seasonality() const
virtual Date baseDate() const
minimum (base) date
virtual void setBaseRate(const Rate &r)
void checkRange(const Date &, bool extrapolate) const
template class providing a null value for a given type.
Definition: null.hpp:76
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
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.
Rate zeroRate(const Date &d, const Period &instObsLag=Period(-1, Days), bool forceLinearInterpolation=false, bool extrapolate=false) const
zero-coupon inflation rate.
virtual Rate zeroRateImpl(Time t) const =0
to be defined in derived classes
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:35
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)
ext::shared_ptr< YieldTermStructure > r
#define QL_DEPRECATED
Definition: qldefines.hpp:215
Interest-rate term structure.