QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
interpolatedzeroinflationcurve.hpp
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
25#ifndef quantlib_interpolated_zeroinflationcurve_hpp
26#define quantlib_interpolated_zeroinflationcurve_hpp
27
28#include <ql/termstructures/inflationtermstructure.hpp>
29#include <ql/termstructures/interpolatedcurve.hpp>
30#include <ql/math/interpolations/linearinterpolation.hpp>
31#include <ql/math/comparison.hpp>
32#include <utility>
33
34namespace QuantLib {
35
37
38 template<class Interpolator>
41 protected InterpolatedCurve<Interpolator> {
42 public:
44 const Calendar& calendar,
46 const Period& lag,
48 std::vector<Date> dates,
49 const std::vector<Rate>& rates,
50 const Interpolator& interpolator = Interpolator());
51
53
54 Date baseDate() const override;
55 Date maxDate() const override;
57
59
60 const std::vector<Date>& dates() const;
61 const std::vector<Time>& times() const;
62 const std::vector<Real>& data() const;
63 const std::vector<Rate>& rates() const;
64 std::vector<std::pair<Date,Rate> > nodes() const;
66
67 protected:
69
70 Rate zeroRateImpl(Time t) const override;
72 mutable std::vector<Date> dates_;
73
79 const Calendar& calendar,
81 const Period& lag,
83 Rate baseZeroRate,
84 const Interpolator &interpolator = Interpolator());
85 };
86
88
89
90
91 // template definitions
92
93 template <class Interpolator>
95 const Date& referenceDate,
96 const Calendar& calendar,
97 const DayCounter& dayCounter,
98 const Period& lag,
99 Frequency frequency,
100 std::vector<Date> dates,
101 const std::vector<Rate>& rates,
102 const Interpolator& interpolator)
103 : ZeroInflationTermStructure(referenceDate, calendar, dayCounter, rates[0], lag, frequency),
104 InterpolatedCurve<Interpolator>(std::vector<Time>(), rates, interpolator),
105 dates_(std::move(dates)) {
106
107 QL_REQUIRE(dates_.size() > 1, "too few dates: " << dates_.size());
108
109 // check that the data starts from the beginning,
110 // i.e. referenceDate - lag, at least must be in the relevant
111 // period
112 std::pair<Date, Date> lim =
113 inflationPeriod(referenceDate - this->observationLag(), frequency);
114 QL_REQUIRE(lim.first <= dates_[0] && dates_[0] <= lim.second,
115 "first data date is not in base period, date: "
116 << dates_[0] << " not within [" << lim.first << "," << lim.second << "]");
117
118 QL_REQUIRE(this->data_.size() == dates_.size(),
119 "indices/dates count mismatch: " << this->data_.size() << " vs "
120 << dates_.size());
121 for (Size i = 1; i < dates_.size(); i++) {
122 // must be greater than -1
123 QL_REQUIRE(this->data_[i] > -1.0, "zero inflation data < -100 %");
124 }
125
126 this->setupTimes(dates_, referenceDate, dayCounter);
127 this->setupInterpolation();
128 this->interpolation_.update();
129 }
130
131 template <class Interpolator>
133 InterpolatedZeroInflationCurve(const Date& referenceDate,
134 const Calendar& calendar,
135 const DayCounter& dayCounter,
136 const Period& lag,
137 Frequency frequency,
138 Rate baseZeroRate,
139 const Interpolator& interpolator)
140 : ZeroInflationTermStructure(referenceDate, calendar, dayCounter,
141 baseZeroRate, lag, frequency),
142 InterpolatedCurve<Interpolator>(interpolator) {
143 }
144
145 template <class T>
147 return dates_.front();
148 }
149
150 template <class T>
152 return inflationPeriod(dates_.back(), frequency()).second;
153 }
154
155 template <class T>
157 return this->interpolation_(t, true);
158 }
159
160 template <class T>
161 inline const std::vector<Time>&
163 return this->times_;
164 }
165
166 template <class T>
167 inline const std::vector<Date>&
169 return dates_;
170 }
171
172 template <class T>
173 inline const std::vector<Rate>&
175 return this->data_;
176 }
177
178 template <class T>
179 inline const std::vector<Real>&
181 return this->data_;
182 }
183
184 template <class T>
185 inline std::vector<std::pair<Date,Rate> >
187 std::vector<std::pair<Date,Rate> > results(dates_.size());
188 for (Size i=0; i<dates_.size(); ++i)
189 results[i] = std::make_pair(dates_[i],this->data_[i]);
190 return results;
191 }
192
193}
194
195
196#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 the interpolation of zero rates.
Rate zeroRateImpl(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
InterpolatedZeroInflationCurve(const Date &referenceDate, const Calendar &calendar, const DayCounter &dayCounter, const Period &lag, Frequency frequency, 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
Interface for zero 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
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.