QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
interpolatedyoyinflationcurve.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, 2008, 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 <http://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 interpolatedyoyinflationcurve.hpp
22 \brief Inflation term structure based on the interpolation of
23 year-on-year rates.
24*/
25
26#ifndef quantlib_interpolated_yoy_inflationcurve_hpp
27#define quantlib_interpolated_yoy_inflationcurve_hpp
28
33#include <utility>
34
35namespace QuantLib {
36
37 //! Inflation term structure based on interpolated year-on-year rates
38 /*! \note The provided rates are not YY inflation-swap quotes.
39
40 \ingroup inflationtermstructures
41 */
42 template<class Interpolator>
45 protected InterpolatedCurve<Interpolator> {
46 public:
48 std::vector<Date> dates,
49 const std::vector<Rate>& rates,
53 const ext::shared_ptr<Seasonality>& seasonality = {},
54 const Interpolator& interpolator = Interpolator());
55
56 /*! \deprecated Use the other overload and pass the base date directly
57 as the first date in the vector instead of using a lag.
58 Deprecated in version 1.34.
59 */
62 const Calendar& calendar,
64 const Period& lag,
67 std::vector<Date> dates,
68 const std::vector<Rate>& rates,
69 const Interpolator& interpolator = Interpolator());
70
71 //! \name InflationTermStructure interface
72 //@{
73 Date baseDate() const override;
74 Date maxDate() const override;
75 //@}
76
77 //! \name Inspectors
78 //@{
79 const std::vector<Date>& dates() const;
80 const std::vector<Time>& times() const;
81 const std::vector<Real>& data() const;
82 const std::vector<Rate>& rates() const;
83 std::vector<std::pair<Date,Rate> > nodes() const;
84 //@}
85
86 protected:
87 //! \name YoYInflationTermStructure interface
88 //@{
89 Rate yoyRateImpl(Time t) const override;
90 //@}
91 mutable std::vector<Date> dates_;
92
93 /*! Protected version for use when descendents don't want to
94 (or can't) provide the points for interpolation on
95 construction.
96 */
99 Rate baseYoYRate,
102 const DayCounter& dayCounter,
103 const ext::shared_ptr<Seasonality>& seasonality = {},
104 const Interpolator& interpolator = Interpolator());
105
106 /*! \deprecated Use the other overload and pass the base date directly
107 instead of using a lag.
108 Deprecated in version 1.34.
109 */
112 const Calendar& calendar,
113 const DayCounter& dayCounter,
114 Rate baseYoYRate,
115 const Period& lag,
118 const Interpolator& interpolator = Interpolator());
119 };
120
122
123
124
125 // template definitions
126
127 template <class Interpolator>
129 const Date& referenceDate,
130 std::vector<Date> dates,
131 const std::vector<Rate>& rates,
132 Frequency frequency,
133 bool indexIsInterpolated,
134 const DayCounter& dayCounter,
135 const ext::shared_ptr<Seasonality>& seasonality,
136 const Interpolator& interpolator)
137 : YoYInflationTermStructure(referenceDate, dates.at(0), rates[0], frequency,
138 indexIsInterpolated, dayCounter, seasonality),
139 InterpolatedCurve<Interpolator>(std::vector<Time>(), rates, interpolator),
140 dates_(std::move(dates)) {
141
142 QL_REQUIRE(dates_.size()>1, "too few dates: " << dates_.size());
143
144 QL_REQUIRE(this->data_.size() == dates_.size(),
145 "indices/dates count mismatch: "
146 << this->data_.size() << " vs " << dates_.size());
147
148 for (Size i = 1; i < dates_.size(); i++) {
149 // YoY inflation data may be positive or negative
150 // but must be greater than -1
151 QL_REQUIRE(this->data_[i] > -1.0,
152 "year-on-year inflation data < -100 %");
153 }
154
155 this->setupTimes(dates_, referenceDate, dayCounter);
156 this->setupInterpolation();
157 this->interpolation_.update();
158 }
159
160 template <class Interpolator>
162 InterpolatedYoYInflationCurve(const Date& referenceDate,
163 Date baseDate,
164 Rate baseYoYRate,
165 Frequency frequency,
166 bool indexIsInterpolated,
167 const DayCounter& dayCounter,
168 const ext::shared_ptr<Seasonality>& seasonality,
169 const Interpolator& interpolator)
170 : YoYInflationTermStructure(referenceDate, baseDate, baseYoYRate, frequency,
171 indexIsInterpolated, dayCounter, seasonality),
172 InterpolatedCurve<Interpolator>(interpolator) {}
173
174
176
177 template <class Interpolator>
179 const Date& referenceDate,
180 const Calendar& calendar,
181 const DayCounter& dayCounter,
182 const Period& lag,
183 Frequency frequency,
184 bool indexIsInterpolated,
185 std::vector<Date> dates,
186 const std::vector<Rate>& rates,
187 const Interpolator& interpolator)
189 referenceDate, calendar, dayCounter, rates[0], lag, frequency, indexIsInterpolated),
190 InterpolatedCurve<Interpolator>(std::vector<Time>(), rates, interpolator),
191 dates_(std::move(dates)) {
192
193 QL_REQUIRE(dates_.size()>1, "too few dates: " << dates_.size());
194
195 // check that the data starts from the beginning,
196 // i.e. referenceDate - lag, at least must be in the relevant
197 // period
198 std::pair<Date,Date> lim =
199 inflationPeriod(referenceDate - this->observationLag(), frequency);
200 QL_REQUIRE(lim.first <= dates_[0] && dates_[0] <= lim.second,
201 "first data date is not in base period, date: " << dates_[0]
202 << " not within [" << lim.first << "," << lim.second << "]");
203
204 QL_REQUIRE(this->data_.size() == dates_.size(),
205 "indices/dates count mismatch: "
206 << this->data_.size() << " vs " << dates_.size());
207
208 for (Size i = 1; i < dates_.size(); i++) {
209 // YoY inflation data may be positive or negative
210 // but must be greater than -1
211 QL_REQUIRE(this->data_[i] > -1.0,
212 "year-on-year inflation data < -100 %");
213 }
214
215 this->setupTimes(dates_, referenceDate, dayCounter);
216 this->setupInterpolation();
217 this->interpolation_.update();
218 }
219
220 template <class Interpolator>
222 InterpolatedYoYInflationCurve(const Date& referenceDate,
223 const Calendar& calendar,
224 const DayCounter& dayCounter,
225 Rate baseYoYRate,
226 const Period& lag,
227 Frequency frequency,
228 bool indexIsInterpolated,
229 const Interpolator& interpolator)
230 : YoYInflationTermStructure(referenceDate, calendar, dayCounter, baseYoYRate,
231 lag, frequency, indexIsInterpolated),
232 InterpolatedCurve<Interpolator>(interpolator) {}
233
235
236
237 template <class T>
239 if (hasExplicitBaseDate())
241 else
242 return dates_.front();
243 }
244
245 template <class T>
247 return dates_.back();
248 }
249
250
251 template <class T>
253 return this->interpolation_(t, true);
254 }
255
256 template <class T>
257 inline const std::vector<Time>&
259 return this->times_;
260 }
261
262 template <class T>
263 inline const std::vector<Date>&
265 return dates_;
266 }
267
268 template <class T>
269 inline const std::vector<Rate>&
271 return this->data_;
272 }
273
274 template <class T>
275 inline const std::vector<Real>&
277 return this->data_;
278 }
279
280 template <class T>
281 inline std::vector<std::pair<Date,Rate> >
283 std::vector<std::pair<Date,Rate> > results(dates_.size());
284 for (Size i=0; i<dates_.size(); ++i)
285 results[i] = std::make_pair(dates_[i],this->data_[i]);
286 return results;
287 }
288
289}
290
291
292#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
ext::shared_ptr< Seasonality > seasonality() const
virtual Date baseDate() const
minimum (base) date
Helper class to build interpolated term structures.
void setupTimes(const std::vector< Date > &dates, Date referenceDate, const DayCounter &dayCounter)
Inflation term structure based on interpolated year-on-year rates.
Rate yoyRateImpl(Time t) const override
to be defined in derived classes
std::vector< std::pair< Date, Rate > > nodes() const
InterpolatedYoYInflationCurve(const Date &referenceDate, std::vector< Date > dates, const std::vector< Rate > &rates, Frequency frequency, bool indexIsInterpolated, const DayCounter &dayCounter, const ext::shared_ptr< Seasonality > &seasonality={}, const Interpolator &interpolator=Interpolator())
Date maxDate() const override
the latest date for which the curve can return values
Date baseDate() const override
minimum (base) date
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.
floating-point comparisons
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Frequency
Frequency of events.
Definition: frequency.hpp:37
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Base classes for inflation term structures.
Helper class to build interpolated term structures.
linear interpolation between discrete points
Definition: any.hpp:35
std::pair< Date, Date > inflationPeriod(const Date &d, Frequency frequency)
utility function giving the inflation period for a given date
InterpolatedYoYInflationCurve< Linear > YoYInflationCurve
STL namespace.
#define QL_DEPRECATED
Definition: qldefines.hpp:215
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217