QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
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,
52 const ext::shared_ptr<Seasonality>& seasonality = {},
53 const Interpolator& interpolator = Interpolator());
54
55 /*! \deprecated Use the overload without indexIsInterpolated.
56 Deprecated in version 1.37.
57 */
58 [[deprecated("Use the overload without indexIsInterpolated")]]
60 std::vector<Date> dates,
61 const std::vector<Rate>& rates,
65 const ext::shared_ptr<Seasonality>& seasonality = {},
66 const Interpolator& interpolator = Interpolator());
67
68 //! \name InflationTermStructure interface
69 //@{
70 Date maxDate() const override;
71 //@}
72
73 //! \name Inspectors
74 //@{
75 const std::vector<Date>& dates() const;
76 const std::vector<Time>& times() const;
77 const std::vector<Real>& data() const;
78 const std::vector<Rate>& rates() const;
79 std::vector<std::pair<Date,Rate> > nodes() const;
80 //@}
81
82 protected:
83 //! \name YoYInflationTermStructure interface
84 //@{
85 Rate yoyRateImpl(Time t) const override;
86 //@}
87 mutable std::vector<Date> dates_;
88
89 /*! Protected version for use when descendents don't want to
90 (or can't) provide the points for interpolation on
91 construction.
92 */
95 Rate baseYoYRate,
98 const ext::shared_ptr<Seasonality>& seasonality = {},
99 const Interpolator& interpolator = Interpolator());
100
101 /*! \deprecated Use the overload without indexIsInterpolated.
102 Deprecated in version 1.37.
103 */
104 [[deprecated("Use the overload without indexIsInterpolated")]]
107 Rate baseYoYRate,
110 const DayCounter& dayCounter,
111 const ext::shared_ptr<Seasonality>& seasonality = {},
112 const Interpolator& interpolator = Interpolator());
113 };
114
116
117
118
119 // template definitions
120
121 template <class Interpolator>
123 const Date& referenceDate,
124 std::vector<Date> dates,
125 const std::vector<Rate>& rates,
126 Frequency frequency,
127 const DayCounter& dayCounter,
128 const ext::shared_ptr<Seasonality>& seasonality,
129 const Interpolator& interpolator)
130 : YoYInflationTermStructure(referenceDate, dates.at(0), rates[0],
131 frequency, dayCounter, seasonality),
132 InterpolatedCurve<Interpolator>(std::vector<Time>(), rates, interpolator),
133 dates_(std::move(dates)) {
134
135 QL_REQUIRE(dates_.size()>1, "too few dates: " << dates_.size());
136
137 QL_REQUIRE(this->data_.size() == dates_.size(),
138 "indices/dates count mismatch: "
139 << this->data_.size() << " vs " << dates_.size());
140
141 for (Size i = 1; i < dates_.size(); i++) {
142 // YoY inflation data may be positive or negative
143 // but must be greater than -1
144 QL_REQUIRE(this->data_[i] > -1.0,
145 "year-on-year inflation data < -100 %");
146 }
147
148 this->setupTimes(dates_, referenceDate, dayCounter);
149 this->setupInterpolation();
150 this->interpolation_.update();
151 }
152
153 template <class Interpolator>
155 const Date& referenceDate,
156 std::vector<Date> dates,
157 const std::vector<Rate>& rates,
158 Frequency frequency,
159 bool indexIsInterpolated,
160 const DayCounter& dayCounter,
161 const ext::shared_ptr<Seasonality>& seasonality,
162 const Interpolator& interpolator)
163 : InterpolatedYoYInflationCurve(referenceDate, dates, rates, frequency,
164 dayCounter, seasonality, interpolator) {
168 }
169
170 template <class Interpolator>
172 InterpolatedYoYInflationCurve(const Date& referenceDate,
173 Date baseDate,
174 Rate baseYoYRate,
175 Frequency frequency,
176 const DayCounter& dayCounter,
177 const ext::shared_ptr<Seasonality>& seasonality,
178 const Interpolator& interpolator)
179 : YoYInflationTermStructure(referenceDate, baseDate, baseYoYRate,
180 frequency, dayCounter, seasonality),
181 InterpolatedCurve<Interpolator>(interpolator) {}
182
183 template <class Interpolator>
185 InterpolatedYoYInflationCurve(const Date& referenceDate,
186 Date baseDate,
187 Rate baseYoYRate,
188 Frequency frequency,
189 bool indexIsInterpolated,
190 const DayCounter& dayCounter,
191 const ext::shared_ptr<Seasonality>& seasonality,
192 const Interpolator& interpolator)
193 : InterpolatedYoYInflationCurve(referenceDate, baseDate, baseYoYRate, frequency,
194 dayCounter, seasonality, interpolator) {
198 }
199
200
201 template <class T>
203 return dates_.back();
204 }
205
206
207 template <class T>
209 return this->interpolation_(t, true);
210 }
211
212 template <class T>
213 inline const std::vector<Time>&
215 return this->times_;
216 }
217
218 template <class T>
219 inline const std::vector<Date>&
221 return dates_;
222 }
223
224 template <class T>
225 inline const std::vector<Rate>&
227 return this->data_;
228 }
229
230 template <class T>
231 inline const std::vector<Real>&
233 return this->data_;
234 }
235
236 template <class T>
237 inline std::vector<std::pair<Date,Rate> >
239 std::vector<std::pair<Date,Rate> > results(dates_.size());
240 for (Size i=0; i<dates_.size(); ++i)
241 results[i] = std::make_pair(dates_[i],this->data_[i]);
242 return results;
243 }
244
245}
246
247
248#endif
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
InterpolatedYoYInflationCurve(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())
std::vector< std::pair< Date, Rate > > nodes() const
Date maxDate() const override
the latest date for which the curve can return values
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
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:37
InterpolatedYoYInflationCurve< Linear > YoYInflationCurve
STL namespace.
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217