QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
interpolatedzeroinflationcurve.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 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 interpolatedzeroinflationcurve.hpp
22 \brief Inflation term structure based on the interpolation of zero rates.
23*/
24
25#ifndef quantlib_interpolated_zeroinflationcurve_hpp
26#define quantlib_interpolated_zeroinflationcurve_hpp
27
32#include <utility>
33
34namespace QuantLib {
35
36 //! Inflation term structure based on the interpolation of zero rates.
37 /*! \ingroup inflationtermstructures */
38 template<class Interpolator>
41 protected InterpolatedCurve<Interpolator> {
42 public:
44 std::vector<Date> dates,
45 const std::vector<Rate>& rates,
48 const ext::shared_ptr<Seasonality>& seasonality = {},
49 const Interpolator& interpolator = Interpolator());
50
51 /*! \deprecated Use the other overload and pass the base date directly
52 as the first date in the vector instead of using a lag.
53 Deprecated in version 1.34.
54 */
57 const Calendar& calendar,
59 const Period& lag,
61 std::vector<Date> dates,
62 const std::vector<Rate>& rates,
63 const Interpolator& interpolator = Interpolator());
64
65 //! \name InflationTermStructure interface
66 //@{
67 Date baseDate() const override;
68 Date maxDate() const override;
69 //@}
70
71 //! \name Inspectors
72 //@{
73 const std::vector<Date>& dates() const;
74 const std::vector<Time>& times() const;
75 const std::vector<Real>& data() const;
76 const std::vector<Rate>& rates() const;
77 std::vector<std::pair<Date,Rate> > nodes() const;
78 //@}
79
80 protected:
81 //! \name ZeroInflationTermStructure Interface
82 //@{
83 Rate zeroRateImpl(Time t) const override;
84 //@}
85 mutable std::vector<Date> dates_;
86
87 /*! Protected version for use when descendents don't want to
88 (or can't) provide the points for interpolation on
89 construction.
90 */
95 const ext::shared_ptr<Seasonality>& seasonality = {},
96 const Interpolator &interpolator = Interpolator());
97
98 /*! \deprecated Use the other overload and pass the base date directly
99 instead of using a lag. A base rate should not be needed.
100 Deprecated in version 1.34.
101 */
104 const Calendar& calendar,
105 const DayCounter& dayCounter,
106 const Period& lag,
108 Rate baseZeroRate,
109 const Interpolator &interpolator = Interpolator());
110 };
111
113
114
115
116 // template definitions
117
118 template <class Interpolator>
120 const Date& referenceDate,
121 std::vector<Date> dates,
122 const std::vector<Rate>& rates,
123 Frequency frequency,
124 const DayCounter& dayCounter,
125 const ext::shared_ptr<Seasonality>& seasonality,
126 const Interpolator& interpolator)
127 : ZeroInflationTermStructure(referenceDate, dates.at(0), frequency, dayCounter, seasonality),
128 InterpolatedCurve<Interpolator>(std::vector<Time>(), rates, interpolator),
129 dates_(std::move(dates)) {
130
131 QL_REQUIRE(dates_.size() > 1, "too few dates: " << dates_.size());
132
133 QL_REQUIRE(this->data_.size() == dates_.size(),
134 "indices/dates count mismatch: " << this->data_.size() << " vs "
135 << dates_.size());
136 for (Size i = 1; i < dates_.size(); i++) {
137 // must be greater than -1
138 QL_REQUIRE(this->data_[i] > -1.0, "zero inflation data < -100 %");
139 }
140
141 this->setupTimes(dates_, referenceDate, dayCounter);
142 this->setupInterpolation();
143 this->interpolation_.update();
144 }
145
146 template <class Interpolator>
148 InterpolatedZeroInflationCurve(const Date& referenceDate,
149 Date baseDate,
150 Frequency frequency,
151 const DayCounter& dayCounter,
152 const ext::shared_ptr<Seasonality>& seasonality,
153 const Interpolator& interpolator)
154 : ZeroInflationTermStructure(referenceDate, baseDate, frequency, dayCounter, seasonality),
155 InterpolatedCurve<Interpolator>(interpolator) {
156 }
157
159
160 template <class Interpolator>
162 const Date& referenceDate,
163 const Calendar& calendar,
164 const DayCounter& dayCounter,
165 const Period& lag,
166 Frequency frequency,
167 std::vector<Date> dates,
168 const std::vector<Rate>& rates,
169 const Interpolator& interpolator)
170 : ZeroInflationTermStructure(referenceDate, calendar, dayCounter, rates[0], lag, frequency),
171 InterpolatedCurve<Interpolator>(std::vector<Time>(), rates, interpolator),
172 dates_(std::move(dates)) {
173
174 QL_REQUIRE(dates_.size() > 1, "too few dates: " << dates_.size());
175
176 // check that the data starts from the beginning,
177 // i.e. referenceDate - lag, at least must be in the relevant
178 // period
179 std::pair<Date, Date> lim =
180 inflationPeriod(referenceDate - this->observationLag(), frequency);
181 QL_REQUIRE(lim.first <= dates_[0] && dates_[0] <= lim.second,
182 "first data date is not in base period, date: "
183 << dates_[0] << " not within [" << lim.first << "," << lim.second << "]");
184
185 QL_REQUIRE(this->data_.size() == dates_.size(),
186 "indices/dates count mismatch: " << this->data_.size() << " vs "
187 << dates_.size());
188 for (Size i = 1; i < dates_.size(); i++) {
189 // must be greater than -1
190 QL_REQUIRE(this->data_[i] > -1.0, "zero inflation data < -100 %");
191 }
192
193 this->setupTimes(dates_, referenceDate, dayCounter);
194 this->setupInterpolation();
195 this->interpolation_.update();
196 }
197
198 template <class Interpolator>
200 InterpolatedZeroInflationCurve(const Date& referenceDate,
201 const Calendar& calendar,
202 const DayCounter& dayCounter,
203 const Period& lag,
204 Frequency frequency,
205 Rate baseZeroRate,
206 const Interpolator& interpolator)
207 : ZeroInflationTermStructure(referenceDate, calendar, dayCounter,
208 baseZeroRate, lag, frequency),
209 InterpolatedCurve<Interpolator>(interpolator) {
210 }
211
213
214 template <class T>
216 if (hasExplicitBaseDate())
218 else
219 return dates_.front();
220 }
221
222 template <class T>
224 if (hasExplicitBaseDate())
225 return dates_.back();
226 else
227 return inflationPeriod(dates_.back(), frequency()).second;
228 }
229
230 template <class T>
232 return this->interpolation_(t, true);
233 }
234
235 template <class T>
236 inline const std::vector<Time>&
238 return this->times_;
239 }
240
241 template <class T>
242 inline const std::vector<Date>&
244 return dates_;
245 }
246
247 template <class T>
248 inline const std::vector<Rate>&
250 return this->data_;
251 }
252
253 template <class T>
254 inline const std::vector<Real>&
256 return this->data_;
257 }
258
259 template <class T>
260 inline std::vector<std::pair<Date,Rate> >
262 std::vector<std::pair<Date,Rate> > results(dates_.size());
263 for (Size i=0; i<dates_.size(); ++i)
264 results[i] = std::make_pair(dates_[i],this->data_[i]);
265 return results;
266 }
267
268}
269
270
271#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 the interpolation of zero rates.
Rate zeroRateImpl(Time t) const override
to be defined in derived classes
std::vector< std::pair< Date, Rate > > nodes() const
InterpolatedZeroInflationCurve(const Date &referenceDate, std::vector< Date > dates, const std::vector< Rate > &rates, Frequency frequency, 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
Interface for zero 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
InterpolatedZeroInflationCurve< Linear > ZeroInflationCurve
std::pair< Date, Date > inflationPeriod(const Date &d, Frequency frequency)
utility function giving the inflation period for a given date
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