QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
interpolatedyoyinflationcurve.hpp
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
26#ifndef quantlib_interpolated_yoy_inflationcurve_hpp
27#define quantlib_interpolated_yoy_inflationcurve_hpp
28
29#include <ql/termstructures/inflationtermstructure.hpp>
30#include <ql/termstructures/interpolatedcurve.hpp>
31#include <ql/math/interpolations/linearinterpolation.hpp>
32#include <ql/math/comparison.hpp>
33#include <utility>
34
35namespace QuantLib {
36
38
42 template<class Interpolator>
45 protected InterpolatedCurve<Interpolator> {
46 public:
48 const Calendar& calendar,
50 const Period& lag,
53 std::vector<Date> dates,
54 const std::vector<Rate>& rates,
55 const Interpolator& interpolator = Interpolator());
56
58
59 Date baseDate() const override;
60 Date maxDate() const override;
62
64
65 const std::vector<Date>& dates() const;
66 const std::vector<Time>& times() const;
67 const std::vector<Real>& data() const;
68 const std::vector<Rate>& rates() const;
69 std::vector<std::pair<Date,Rate> > nodes() const;
71
72 protected:
74
75 Rate yoyRateImpl(Time t) const override;
77 mutable std::vector<Date> dates_;
78
84 const Calendar& calendar,
86 Rate baseYoYRate,
87 const Period& lag,
90 const Interpolator& interpolator
91 = Interpolator());
92 };
93
95
96
97
98 // template definitions
99
100 template <class Interpolator>
102 const Date& referenceDate,
103 const Calendar& calendar,
104 const DayCounter& dayCounter,
105 const Period& lag,
106 Frequency frequency,
107 bool indexIsInterpolated,
108 std::vector<Date> dates,
109 const std::vector<Rate>& rates,
110 const Interpolator& interpolator)
112 referenceDate, calendar, dayCounter, rates[0], lag, frequency, indexIsInterpolated),
113 InterpolatedCurve<Interpolator>(std::vector<Time>(), rates, interpolator),
114 dates_(std::move(dates)) {
115
116 QL_REQUIRE(dates_.size()>1, "too few dates: " << dates_.size());
117
118 // check that the data starts from the beginning,
119 // i.e. referenceDate - lag, at least must be in the relevant
120 // period
121 std::pair<Date,Date> lim =
122 inflationPeriod(referenceDate - this->observationLag(), frequency);
123 QL_REQUIRE(lim.first <= dates_[0] && dates_[0] <= lim.second,
124 "first data date is not in base period, date: " << dates_[0]
125 << " not within [" << lim.first << "," << lim.second << "]");
126
127 QL_REQUIRE(this->data_.size() == dates_.size(),
128 "indices/dates count mismatch: "
129 << this->data_.size() << " vs " << dates_.size());
130
131 for (Size i = 1; i < dates_.size(); i++) {
132 // YoY inflation data may be positive or negative
133 // but must be greater than -1
134 QL_REQUIRE(this->data_[i] > -1.0,
135 "year-on-year inflation data < -100 %");
136 }
137
138 this->setupTimes(dates_, referenceDate, dayCounter);
139 this->setupInterpolation();
140 this->interpolation_.update();
141 }
142
143 template <class Interpolator>
145 InterpolatedYoYInflationCurve(const Date& referenceDate,
146 const Calendar& calendar,
147 const DayCounter& dayCounter,
148 Rate baseYoYRate,
149 const Period& lag,
150 Frequency frequency,
151 bool indexIsInterpolated,
152 const Interpolator& interpolator)
153 : YoYInflationTermStructure(referenceDate, calendar, dayCounter, baseYoYRate,
154 lag, frequency, indexIsInterpolated),
155 InterpolatedCurve<Interpolator>(interpolator) {}
156
157
158 template <class T>
160 return dates_.front();
161 }
162
163 template <class T>
165 return dates_.back();
166 }
167
168
169 template <class T>
171 return this->interpolation_(t, true);
172 }
173
174 template <class T>
175 inline const std::vector<Time>&
177 return this->times_;
178 }
179
180 template <class T>
181 inline const std::vector<Date>&
183 return dates_;
184 }
185
186 template <class T>
187 inline const std::vector<Rate>&
189 return this->data_;
190 }
191
192 template <class T>
193 inline const std::vector<Real>&
195 return this->data_;
196 }
197
198 template <class T>
199 inline std::vector<std::pair<Date,Rate> >
201 std::vector<std::pair<Date,Rate> > results(dates_.size());
202 for (Size i=0; i<dates_.size(); ++i)
203 results[i] = std::make_pair(dates_[i],this->data_[i]);
204 return results;
205 }
206
207}
208
209
210#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
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
Date baseDate() const override
minimum (base) date
std::vector< std::pair< Date, Rate > > nodes() const
Date maxDate() const override
the latest date for which the curve can return values
InterpolatedYoYInflationCurve(const Date &referenceDate, const Calendar &calendar, const DayCounter &dayCounter, const Period &lag, Frequency frequency, bool indexIsInterpolated, std::vector< Date > dates, const std::vector< Rate > &rates, const Interpolator &interpolator=Interpolator())
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.
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
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.