Loading [MathJax]/jax/output/HTML-CSS/config.js
QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
piecewiseyieldcurve.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) 2005, 2006, 2007, 2008 StatPro Italia srl
5 Copyright (C) 2007, 2008, 2009 Ferdinando Ametrano
6 Copyright (C) 2007 Chris Kenyon
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 piecewiseyieldcurve.hpp
23 \brief piecewise-interpolated term structure
24*/
25
26#ifndef quantlib_piecewise_yield_curve_hpp
27#define quantlib_piecewise_yield_curve_hpp
28
33#include <utility>
34
35namespace QuantLib {
36
37 //! Piecewise yield term structure
38 /*! This term structure is bootstrapped on a number of interest
39 rate instruments which are passed as a vector of pointers to
40 RateHelper instances. Their maturities mark the boundaries of
41 the interpolated segments.
42
43 Each segment is determined sequentially starting from the
44 earliest period to the latest and is chosen so that the
45 instrument whose maturity marks the end of such segment is
46 correctly repriced on the curve.
47
48 \warning The bootstrapping algorithm will raise an exception if
49 any two instruments have the same maturity date.
50
51 \ingroup yieldtermstructures
52
53 \test
54 - the correctness of the returned values is tested by
55 checking them against the original inputs.
56 - the observability of the term structure is tested.
57 */
58 template <class Traits, class Interpolator,
59 template <class> class Bootstrap = IterativeBootstrap>
61 : public Traits::template curve<Interpolator>::type,
62 public LazyObject {
63 private:
64 typedef typename Traits::template curve<Interpolator>::type base_curve;
66 public:
67 typedef Traits traits_type;
68 typedef Interpolator interpolator_type;
70
71 //! \name Constructors
72 //@{
74 const Date& referenceDate,
75 std::vector<ext::shared_ptr<typename Traits::helper> > instruments,
76 const DayCounter& dayCounter,
77 const std::vector<Handle<Quote> >& jumps = {},
78 const std::vector<Date>& jumpDates = {},
79 const Interpolator& i = {},
80 bootstrap_type bootstrap = {})
81 : base_curve(referenceDate, dayCounter, jumps, jumpDates, i),
82 instruments_(std::move(instruments)), accuracy_(1.0e-12),
83 bootstrap_(std::move(bootstrap)) {
84 bootstrap_.setup(this);
85 }
86
87 PiecewiseYieldCurve(const Date& referenceDate,
88 std::vector<ext::shared_ptr<typename Traits::helper> > instruments,
89 const DayCounter& dayCounter,
90 const Interpolator& i,
91 bootstrap_type bootstrap = bootstrap_type())
92 : base_curve(
93 referenceDate, dayCounter, {}, {}, i),
94 instruments_(std::move(instruments)), accuracy_(1.0e-12),
95 bootstrap_(std::move(bootstrap)) {
96 bootstrap_.setup(this);
97 }
98
99 PiecewiseYieldCurve(const Date& referenceDate,
100 std::vector<ext::shared_ptr<typename Traits::helper> > instruments,
101 const DayCounter& dayCounter,
102 bootstrap_type bootstrap)
103 : base_curve(referenceDate,
104 dayCounter),
105 instruments_(std::move(instruments)), accuracy_(1.0e-12),
106 bootstrap_(std::move(bootstrap)) {
107 bootstrap_.setup(this);
108 }
109
111 Natural settlementDays,
112 const Calendar& calendar,
113 std::vector<ext::shared_ptr<typename Traits::helper> > instruments,
114 const DayCounter& dayCounter,
115 const std::vector<Handle<Quote> >& jumps = {},
116 const std::vector<Date>& jumpDates = {},
117 const Interpolator& i = {},
118 bootstrap_type bootstrap = {})
119 : base_curve(settlementDays, calendar, dayCounter, jumps, jumpDates, i),
120 instruments_(std::move(instruments)), accuracy_(1.0e-12),
121 bootstrap_(std::move(bootstrap)) {
122 bootstrap_.setup(this);
123 }
124
126 const Calendar& calendar,
127 std::vector<ext::shared_ptr<typename Traits::helper> > instruments,
128 const DayCounter& dayCounter,
129 const Interpolator& i,
130 bootstrap_type bootstrap = bootstrap_type())
131 : base_curve(settlementDays,
132 calendar,
133 dayCounter,
134 {},
135 {},
136 i),
137 instruments_(std::move(instruments)), accuracy_(1.0e-12),
138 bootstrap_(std::move(bootstrap)) {
139 bootstrap_.setup(this);
140 }
141
143 Natural settlementDays,
144 const Calendar& calendar,
145 const std::vector<ext::shared_ptr<typename Traits::helper> >&
146 instruments,
147 const DayCounter& dayCounter,
148 const bootstrap_type& bootstrap)
149 : base_curve(settlementDays, calendar, dayCounter),
150 instruments_(instruments),
151 accuracy_(1.0e-12), bootstrap_(bootstrap) {
152 bootstrap_.setup(this);
153 }
154 //@}
155 //! \name TermStructure interface
156 //@{
157 Date maxDate() const override;
158 //@}
159 //! \name base_curve interface
160 //@{
161 const std::vector<Time>& times() const;
162 const std::vector<Date>& dates() const;
163 const std::vector<Real>& data() const;
164 std::vector<std::pair<Date, Real> > nodes() const;
165 //@}
166 //! \name Observer interface
167 //@{
168 void update() override;
169 //@}
170 private:
171 //! \name LazyObject interface
172 //@{
173 void performCalculations() const override;
174 //@}
175 // methods
176 DiscountFactor discountImpl(Time) const override;
177 // data members
178 std::vector<ext::shared_ptr<typename Traits::helper> > instruments_;
180
181 // bootstrapper classes are declared as friend to manipulate
182 // the curve data. They might be passed the data instead, but
183 // it would increase the complexity---which is high enough
184 // already.
185 friend class Bootstrap<this_curve>;
186 friend class BootstrapError<this_curve> ;
187 friend class PenaltyFunction<this_curve>;
189 };
190
191
192 // inline definitions
193
194 template <class C, class I, template <class> class B>
196 calculate();
197 return base_curve::maxDate();
198 }
199
200 template <class C, class I, template <class> class B>
201 inline const std::vector<Time>& PiecewiseYieldCurve<C,I,B>::times() const {
202 calculate();
203 return base_curve::times();
204 }
205
206 template <class C, class I, template <class> class B>
207 inline const std::vector<Date>& PiecewiseYieldCurve<C,I,B>::dates() const {
208 calculate();
209 return base_curve::dates();
210 }
211
212 template <class C, class I, template <class> class B>
213 inline const std::vector<Real>& PiecewiseYieldCurve<C,I,B>::data() const {
214 calculate();
215 return base_curve::data();
216 }
217
218 template <class C, class I, template <class> class B>
219 inline std::vector<std::pair<Date, Real> >
221 calculate();
222 return base_curve::nodes();
223 }
224
225 template <class C, class I, template <class> class B>
227
228 // it dispatches notifications only if (!calculated_ && !frozen_)
230
231 // do not use base_curve::update() as it would always notify observers
232
233 // TermStructure::update() update part
234 if (this->moving_)
235 this->updated_ = false;
236
237 }
238
239 template <class C, class I, template <class> class B>
240 inline
242 calculate();
243 return base_curve::discountImpl(t);
244 }
245
246 template <class C, class I, template <class> class B>
248 // just delegate to the bootstrapper
249 bootstrap_.calculate();
250 }
251
252}
253
254#endif
bootstrap traits
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
Framework for calculation on demand and result caching.
Definition: lazyobject.hpp:35
void update() override
Definition: lazyobject.hpp:188
Piecewise yield term structure.
void performCalculations() const override
PiecewiseYieldCurve(Natural settlementDays, const Calendar &calendar, const std::vector< ext::shared_ptr< typename Traits::helper > > &instruments, const DayCounter &dayCounter, const bootstrap_type &bootstrap)
PiecewiseYieldCurve(const Date &referenceDate, std::vector< ext::shared_ptr< typename Traits::helper > > instruments, const DayCounter &dayCounter, const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &i={}, bootstrap_type bootstrap={})
PiecewiseYieldCurve(const Date &referenceDate, std::vector< ext::shared_ptr< typename Traits::helper > > instruments, const DayCounter &dayCounter, bootstrap_type bootstrap)
PiecewiseYieldCurve< Traits, Interpolator, Bootstrap > this_curve
Traits::template curve< Interpolator >::type base_curve
Bootstrap< this_curve > bootstrap_
PiecewiseYieldCurve(Natural settlementDays, const Calendar &calendar, std::vector< ext::shared_ptr< typename Traits::helper > > instruments, const DayCounter &dayCounter, const Interpolator &i, bootstrap_type bootstrap=bootstrap_type())
const std::vector< Date > & dates() const
const std::vector< Real > & data() const
std::vector< std::pair< Date, Real > > nodes() const
const std::vector< Time > & times() const
std::vector< ext::shared_ptr< typename Traits::helper > > instruments_
DiscountFactor discountImpl(Time) const override
PiecewiseYieldCurve(Natural settlementDays, const Calendar &calendar, std::vector< ext::shared_ptr< typename Traits::helper > > instruments, const DayCounter &dayCounter, const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &i={}, bootstrap_type bootstrap={})
PiecewiseYieldCurve(const Date &referenceDate, std::vector< ext::shared_ptr< typename Traits::helper > > instruments, const DayCounter &dayCounter, const Interpolator &i, bootstrap_type bootstrap=bootstrap_type())
Bootstrap< this_curve > bootstrap_type
const DefaultType & t
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
universal piecewise-term-structure boostrapper.
framework for calculation on demand and result caching
localised-term-structure bootstrapper for most curve types.
Definition: any.hpp:37
STL namespace.