QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
interpolatedsimplezerocurve.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) 2003, 2004, 2005, 2006, 2007, 2008 StatPro Italia srl
5 Copyright (C) 2009 Ferdinando Ametrano
6 Copyright (C) 2019 SoftSolutions! S.r.l.
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22/*! \file interpolatedsimplezerocurve.hpp
23 \brief interpolated simply-compounded zero-rates structure
24*/
25
26#ifndef quantlib_zero_curve_simple_hpp
27#define quantlib_zero_curve_simple_hpp
28
34#include <utility>
35
36namespace QuantLib {
37
38//! YieldTermStructure based on interpolation of zero rates
39/*! \ingroup yieldtermstructures */
40template <class Interpolator>
41class InterpolatedSimpleZeroCurve : public YieldTermStructure, protected InterpolatedCurve<Interpolator> {
42 public:
43 // constructor
44 InterpolatedSimpleZeroCurve(const std::vector<Date> &dates, const std::vector<Rate> &yields,
46 const std::vector<Handle<Quote> > &jumps = {},
47 const std::vector<Date> &jumpDates = {},
48 const Interpolator &interpolator = {});
49 InterpolatedSimpleZeroCurve(const std::vector<Date> &dates, const std::vector<Rate> &yields,
51 const Interpolator &interpolator);
52 InterpolatedSimpleZeroCurve(const std::vector<Date> &dates, const std::vector<Rate> &yields,
53 const DayCounter &dayCounter, const Interpolator &interpolator);
54 //! \name TermStructure interface
55 //@{
56 Date maxDate() const override;
57 //@}
58 //! \name other inspectors
59 //@{
60 const std::vector<Time> &times() const;
61 const std::vector<Date> &dates() const;
62 const std::vector<Real> &data() const;
63 const std::vector<Rate> &zeroRates() const;
64 std::vector<std::pair<Date, Real> > nodes() const;
65 //@}
66 protected:
68 const Interpolator &interpolator = {});
70 const std::vector<Handle<Quote> > &jumps = {},
71 const std::vector<Date> &jumpDates = {},
72 const Interpolator &interpolator = {});
74 const std::vector<Handle<Quote> > &jumps = {},
75 const std::vector<Date> &jumpDates = {},
76 const Interpolator &interpolator = {});
77
78 //! \name YieldTermStructure implementation
79 //@{
81 //@}
82 mutable std::vector<Date> dates_;
83
84 private:
85 void initialize();
86};
87
88
89// inline definitions
90
91template <class T> inline Date InterpolatedSimpleZeroCurve<T>::maxDate() const { return dates_.back(); }
92
93template <class T> inline const std::vector<Time> &InterpolatedSimpleZeroCurve<T>::times() const {
94 return this->times_;
95}
96
97template <class T> inline const std::vector<Date> &InterpolatedSimpleZeroCurve<T>::dates() const { return dates_; }
98
99template <class T> inline const std::vector<Real> &InterpolatedSimpleZeroCurve<T>::data() const { return this->data_; }
100
101template <class T> inline const std::vector<Rate> &InterpolatedSimpleZeroCurve<T>::zeroRates() const {
102 return this->data_;
103}
104
105template <class T> inline std::vector<std::pair<Date, Real> > InterpolatedSimpleZeroCurve<T>::nodes() const {
106 std::vector<std::pair<Date, Real> > results(dates_.size());
107 for (Size i = 0; i < dates_.size(); ++i)
108 results[i] = std::make_pair(dates_[i], this->data_[i]);
109 return results;
110}
111
112#ifndef __DOXYGEN__
113
114// template definitions
115
117 Rate R;
118 if (t <= this->times_.back()) {
119 R = this->interpolation_(t, true);
120 } else {
121 // flat fwd extrapolation after last pillar,
122 // Notice that bbg uses flat extrapolation of non-annualized zero instead
123 Time tMax = this->times_.back();
124 Rate zMax = this->data_.back();
125 Rate instFwdMax = zMax + tMax * this->interpolation_.derivative(tMax);
126 R = (zMax * tMax + instFwdMax * (t - tMax)) / t;
127 }
128
129 return DiscountFactor(1.0 / (1.0 + R * t));
130}
131
132template <class T>
133InterpolatedSimpleZeroCurve<T>::InterpolatedSimpleZeroCurve(const DayCounter &dayCounter, const T &interpolator)
134 : YieldTermStructure(dayCounter), InterpolatedCurve<T>(interpolator) {}
135
136template <class T>
137InterpolatedSimpleZeroCurve<T>::InterpolatedSimpleZeroCurve(const Date &referenceDate, const DayCounter &dayCounter,
138 const std::vector<Handle<Quote> > &jumps,
139 const std::vector<Date> &jumpDates, const T &interpolator)
140 : YieldTermStructure(referenceDate, Calendar(), dayCounter, jumps, jumpDates), InterpolatedCurve<T>(interpolator) {}
141
142template <class T>
143InterpolatedSimpleZeroCurve<T>::InterpolatedSimpleZeroCurve(Natural settlementDays, const Calendar &calendar,
144 const DayCounter &dayCounter,
145 const std::vector<Handle<Quote> > &jumps,
146 const std::vector<Date> &jumpDates, const T &interpolator)
147 : YieldTermStructure(settlementDays, calendar, dayCounter, jumps, jumpDates), InterpolatedCurve<T>(interpolator) {}
148
149template <class T>
151 const std::vector<Rate> &yields,
152 const DayCounter &dayCounter, const Calendar &calendar,
153 const std::vector<Handle<Quote> > &jumps,
154 const std::vector<Date> &jumpDates, const T &interpolator)
155 : YieldTermStructure(dates.at(0), calendar, dayCounter, jumps, jumpDates),
156 InterpolatedCurve<T>(std::vector<Time>(), yields, interpolator), dates_(dates) {
157 initialize();
158}
159
160template <class T>
162 const std::vector<Rate> &yields,
163 const DayCounter &dayCounter, const Calendar &calendar,
164 const T &interpolator)
165 : YieldTermStructure(dates.at(0), calendar, dayCounter), InterpolatedCurve<T>(std::vector<Time>(), yields,
166 interpolator),
167 dates_(dates) {
168 initialize();
169}
170
171template <class T>
173 const std::vector<Rate> &yields,
174 const DayCounter &dayCounter, const T &interpolator)
175 : YieldTermStructure(dates.at(0), Calendar(), dayCounter), InterpolatedCurve<T>(std::vector<Time>(), yields,
176 interpolator),
177 dates_(dates) {
178 initialize();
179}
180
181#endif
182
184 QL_REQUIRE(dates_.size() >= T::requiredPoints,
185 "not enough input dates given");
186 QL_REQUIRE(this->data_.size() == dates_.size(),
187 "dates/data count mismatch");
188
189 this->setupTimes(dates_, dates_[0], dayCounter());
190 this->setupInterpolation();
191 this->interpolation_.update();
192}
193
194} // namespace QuantLib
195
196#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
Helper class to build interpolated term structures.
YieldTermStructure based on interpolation of zero rates.
DiscountFactor discountImpl(Time t) const override
discount factor calculation
const std::vector< Date > & dates() const
InterpolatedSimpleZeroCurve(Natural settlementDays, const Calendar &, const DayCounter &, const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
const std::vector< Rate > & zeroRates() const
const std::vector< Real > & data() const
std::vector< std::pair< Date, Real > > nodes() const
InterpolatedSimpleZeroCurve(const std::vector< Date > &dates, const std::vector< Rate > &yields, const DayCounter &dayCounter, const Calendar &calendar, const Interpolator &interpolator)
const std::vector< Time > & times() const
Date maxDate() const override
the latest date for which the curve can return values
InterpolatedSimpleZeroCurve(const DayCounter &, const Interpolator &interpolator={})
InterpolatedSimpleZeroCurve(const Date &referenceDate, const DayCounter &, const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
InterpolatedSimpleZeroCurve(const std::vector< Date > &dates, const std::vector< Rate > &yields, const DayCounter &dayCounter, const Calendar &calendar=Calendar(), const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
InterpolatedSimpleZeroCurve(const std::vector< Date > &dates, const std::vector< Rate > &yields, const DayCounter &dayCounter, const Interpolator &interpolator)
virtual Natural settlementDays() const
the settlementDays used for reference date calculation
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
Interest-rate term structure.
const std::vector< Date > & jumpDates() const
floating-point comparisons
output manipulators
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Helper class to build interpolated term structures.
linear interpolation between discrete points
Definition: any.hpp:35
STL namespace.
Interest-rate term structure.