QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
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 //! \name InflationTermStructure interface
52 //@{
53 Date maxDate() const override;
54 //@}
55
56 //! \name Inspectors
57 //@{
58 const std::vector<Date>& dates() const;
59 const std::vector<Time>& times() const;
60 const std::vector<Real>& data() const;
61 const std::vector<Rate>& rates() const;
62 std::vector<std::pair<Date,Rate> > nodes() const;
63 //@}
64
65 protected:
66 //! \name ZeroInflationTermStructure Interface
67 //@{
68 Rate zeroRateImpl(Time t) const override;
69 //@}
70 mutable std::vector<Date> dates_;
71
72 /*! Protected version for use when descendents don't want to
73 (or can't) provide the points for interpolation on
74 construction.
75 */
80 const ext::shared_ptr<Seasonality>& seasonality = {},
81 const Interpolator &interpolator = Interpolator());
82 };
83
85
86
87
88 // template definitions
89
90 template <class Interpolator>
92 const Date& referenceDate,
93 std::vector<Date> dates,
94 const std::vector<Rate>& rates,
95 Frequency frequency,
96 const DayCounter& dayCounter,
97 const ext::shared_ptr<Seasonality>& seasonality,
98 const Interpolator& interpolator)
99 : ZeroInflationTermStructure(referenceDate, dates.at(0), frequency, dayCounter, seasonality),
100 InterpolatedCurve<Interpolator>(std::vector<Time>(), rates, interpolator),
101 dates_(std::move(dates)) {
102
103 QL_REQUIRE(dates_.size() > 1, "too few dates: " << dates_.size());
104
105 QL_REQUIRE(this->data_.size() == dates_.size(),
106 "indices/dates count mismatch: " << this->data_.size() << " vs "
107 << dates_.size());
108 for (Size i = 1; i < dates_.size(); i++) {
109 // must be greater than -1
110 QL_REQUIRE(this->data_[i] > -1.0, "zero inflation data < -100 %");
111 }
112
113 this->setupTimes(dates_, referenceDate, dayCounter);
114 this->setupInterpolation();
115 this->interpolation_.update();
116 }
117
118 template <class Interpolator>
120 InterpolatedZeroInflationCurve(const Date& referenceDate,
121 Date baseDate,
122 Frequency frequency,
123 const DayCounter& dayCounter,
124 const ext::shared_ptr<Seasonality>& seasonality,
125 const Interpolator& interpolator)
126 : ZeroInflationTermStructure(referenceDate, baseDate, frequency, dayCounter, seasonality),
127 InterpolatedCurve<Interpolator>(interpolator) {
128 }
129
130 template <class T>
132 return dates_.back();
133 }
134
135 template <class T>
137 return this->interpolation_(t, true);
138 }
139
140 template <class T>
141 inline const std::vector<Time>&
143 return this->times_;
144 }
145
146 template <class T>
147 inline const std::vector<Date>&
149 return dates_;
150 }
151
152 template <class T>
153 inline const std::vector<Rate>&
155 return this->data_;
156 }
157
158 template <class T>
159 inline const std::vector<Real>&
161 return this->data_;
162 }
163
164 template <class T>
165 inline std::vector<std::pair<Date,Rate> >
167 std::vector<std::pair<Date,Rate> > results(dates_.size());
168 for (Size i=0; i<dates_.size(); ++i)
169 results[i] = std::make_pair(dates_[i],this->data_[i]);
170 return results;
171 }
172
173}
174
175
176#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 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
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
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:37
InterpolatedZeroInflationCurve< Linear > ZeroInflationCurve
STL namespace.