QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
piecewisedefaultcurve.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008, 2016 Jose Aparicio
5 Copyright (C) 2008 Chris Kenyon
6 Copyright (C) 2008 Roland Lichters
7 Copyright (C) 2008 StatPro Italia srl
8
9 This file is part of QuantLib, a free-software/open-source library
10 for financial quantitative analysts and developers - http://quantlib.org/
11
12 QuantLib is free software: you can redistribute it and/or modify it
13 under the terms of the QuantLib license. You should have received a
14 copy of the license along with this program; if not, please email
15 <quantlib-dev@lists.sf.net>. The license is also available online at
16 <http://quantlib.org/license.shtml>.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the license for more details.
21*/
22
27#ifndef quantlib_piecewise_default_curve_hpp
28#define quantlib_piecewise_default_curve_hpp
29
30#include <ql/models/shortrate/onefactormodel.hpp>
31#include <ql/patterns/lazyobject.hpp>
32#include <ql/quote.hpp>
33#include <ql/termstructures/credit/probabilitytraits.hpp>
34#include <ql/termstructures/iterativebootstrap.hpp>
35#include <utility>
36
37namespace QuantLib {
38
40
53 template <class Traits, class Interpolator,
54 template <class> class Bootstrap = IterativeBootstrap>
56 : public Traits::template curve<Interpolator>::type,
57 public LazyObject {
58 private:
59 typedef typename Traits::template curve<Interpolator>::type base_curve;
61 public:
62 typedef Traits traits_type;
63 typedef Interpolator interpolator_type;
65
67
69 const Date& referenceDate,
70 std::vector<ext::shared_ptr<typename Traits::helper> > instruments,
71 const DayCounter& dayCounter,
72 const std::vector<Handle<Quote> >& jumps = {},
73 const std::vector<Date>& jumpDates = {},
74 const Interpolator& i = {},
75 bootstrap_type bootstrap = {})
76 : base_curve(referenceDate, dayCounter, jumps, jumpDates, i),
77 instruments_(std::move(instruments)), accuracy_(1.0e-12),
78 bootstrap_(std::move(bootstrap)) {
79 bootstrap_.setup(this);
80 }
81
83 const Date& referenceDate,
84 const std::vector<ext::shared_ptr<typename Traits::helper> >&
85 instruments,
86 const DayCounter& dayCounter,
87 const Interpolator& i,
88 const bootstrap_type& bootstrap = bootstrap_type())
89 : base_curve(referenceDate, dayCounter,
90 {}, {}, i),
91 instruments_(instruments), accuracy_(1.0e-12), bootstrap_(bootstrap) {
92 bootstrap_.setup(this);
93 }
94
95 PiecewiseDefaultCurve(const Date& referenceDate,
96 std::vector<ext::shared_ptr<typename Traits::helper> > instruments,
97 const DayCounter& dayCounter,
98 bootstrap_type bootstrap)
99 : base_curve(referenceDate,
100 dayCounter),
101 instruments_(std::move(instruments)), accuracy_(1.0e-12),
102 bootstrap_(std::move(bootstrap)) {
103 bootstrap_.setup(this);
104 }
105
107 Natural settlementDays,
108 const Calendar& calendar,
109 std::vector<ext::shared_ptr<typename Traits::helper> > instruments,
110 const DayCounter& dayCounter,
111 const std::vector<Handle<Quote> >& jumps = {},
112 const std::vector<Date>& jumpDates = {},
113 const Interpolator& i = {},
114 bootstrap_type bootstrap = {})
115 : base_curve(settlementDays, calendar, dayCounter, jumps, jumpDates, i),
116 instruments_(std::move(instruments)), accuracy_(1.0e-12),
117 bootstrap_(std::move(bootstrap)) {
118 bootstrap_.setup(this);
119 }
120
122 Natural settlementDays,
123 const Calendar& calendar,
124 const std::vector<ext::shared_ptr<typename Traits::helper> >&
125 instruments,
126 const DayCounter& dayCounter,
127 const Interpolator& i,
128 const bootstrap_type& bootstrap = bootstrap_type())
129 : base_curve(settlementDays, calendar, dayCounter,
130 {}, {}, i),
131 instruments_(instruments), accuracy_(1.0e-12), bootstrap_(bootstrap) {
132 bootstrap_.setup(this);
133 }
134
136 Natural settlementDays,
137 const Calendar& calendar,
138 const std::vector<ext::shared_ptr<typename Traits::helper> >&
139 instruments,
140 const DayCounter& dayCounter,
141 const bootstrap_type& bootstrap)
142 : base_curve(settlementDays, calendar, dayCounter),
143 instruments_(instruments), accuracy_(1.0e-12), bootstrap_(bootstrap) {
144 bootstrap_.setup(this);
145 }
146
147 /* AffineHazardRate Traits constructor case. Other constructors of
148 base_curve would fail and this would fail for other cases of Traits.
149 This is a case of substitution failure, it might be preferred
150 to specialization of the class.
151 The way the methods are used in the bootstrapping means the target
152 term structure is the deterministic TS to be added to the model
153 passed in order to reproduce instrument market prices.
154
155 \todo Implement the remaining signatures
156 */
158 const Date& referenceDate,
159 const std::vector<ext::shared_ptr<typename Traits::helper> >& instruments,
160 const DayCounter& dayCounter,
161 const ext::shared_ptr<OneFactorAffineModel>& model,
162 const Interpolator& i = {},
163 const bootstrap_type& bootstrap = {})
164 : base_curve(referenceDate,
165 dayCounter,
166 model,
167 {},
168 {},
169 i),
170 instruments_(instruments), accuracy_(1.0e-12), bootstrap_(bootstrap) {
171 bootstrap_.setup(this);
172 }
174
176 Date maxDate() const override;
178
180 const std::vector<Time>& times() const;
181 const std::vector<Date>& dates() const;
182 const std::vector<Real>& data() const;
183 std::vector<std::pair<Date, Real> > nodes() const;
185
187 void update() override;
189 private:
191
192 void performCalculations() const override;
194 // methods
196 Real defaultDensityImpl(Time) const override;
197 Real hazardRateImpl(Time) const override;
198 // data members
199 std::vector<ext::shared_ptr<typename Traits::helper> > instruments_;
201
202 // bootstrapper classes are declared as friend to manipulate
203 // the curve data. They might be passed the data instead, but
204 // it would increase the complexity---which is high enough
205 // already.
206 friend class Bootstrap<this_curve>;
207 friend class BootstrapError<this_curve>;
209 };
210
211
212 // inline definitions
213
214 template <class C, class I, template <class> class B>
216 calculate();
217 return base_curve::maxDate();
218 }
219
220 template <class C, class I, template <class> class B>
221 inline const std::vector<Time>&
223 calculate();
224 return base_curve::times();
225 }
226
227 template <class C, class I, template <class> class B>
228 inline const std::vector<Date>&
230 calculate();
231 return base_curve::dates();
232 }
233
234 template <class C, class I, template <class> class B>
235 inline const std::vector<Real>&
237 calculate();
238 return this->data_;
239 }
240
241 template <class C, class I, template <class> class B>
242 inline std::vector<std::pair<Date, Real> >
244 calculate();
245 return base_curve::nodes();
246 }
247
248 template <class C, class I, template <class> class B>
250 // it dispatches notifications only if (!calculated_ && !frozen_)
252
253 // do not use base_curve::update() as it would always notify observers
254
255 // TermStructure::update() update part
256 if (this->moving_)
257 this->updated_ = false;
258 }
259
260 template <class C, class I, template <class> class B>
261 inline Probability
263 calculate();
264 return base_curve::survivalProbabilityImpl(t);
265 }
266
267 template <class C, class I, template <class> class B>
269 calculate();
270 return base_curve::defaultDensityImpl(t);
271 }
272
273 template <class C, class I, template <class> class B>
275 calculate();
276 return base_curve::hazardRateImpl(t);
277 }
278
279 template <class C, class I, template <class> class B>
281 // just delegate to the bootstrapper
282 bootstrap_.calculate();
283 }
284
285}
286
287#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
Framework for calculation on demand and result caching.
Definition: lazyobject.hpp:35
void update() override
Definition: lazyobject.hpp:188
Piecewise default-probability term structure.
Real defaultDensityImpl(Time) const override
PiecewiseDefaultCurve(Natural settlementDays, const Calendar &calendar, const std::vector< ext::shared_ptr< typename Traits::helper > > &instruments, const DayCounter &dayCounter, const Interpolator &i, const bootstrap_type &bootstrap=bootstrap_type())
Traits::template curve< Interpolator >::type base_curve
Real hazardRateImpl(Time) const override
PiecewiseDefaultCurve< Traits, Interpolator, Bootstrap > this_curve
PiecewiseDefaultCurve(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={})
const std::vector< Date > & dates() const
PiecewiseDefaultCurve(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={})
PiecewiseDefaultCurve(Natural settlementDays, const Calendar &calendar, const std::vector< ext::shared_ptr< typename Traits::helper > > &instruments, const DayCounter &dayCounter, const bootstrap_type &bootstrap)
const std::vector< Real > & data() const
std::vector< std::pair< Date, Real > > nodes() const
PiecewiseDefaultCurve(const Date &referenceDate, const std::vector< ext::shared_ptr< typename Traits::helper > > &instruments, const DayCounter &dayCounter, const Interpolator &i, const bootstrap_type &bootstrap=bootstrap_type())
const std::vector< Time > & times() const
std::vector< ext::shared_ptr< typename Traits::helper > > instruments_
Probability survivalProbabilityImpl(Time) const override
PiecewiseDefaultCurve(const Date &referenceDate, std::vector< ext::shared_ptr< typename Traits::helper > > instruments, const DayCounter &dayCounter, bootstrap_type bootstrap)
PiecewiseDefaultCurve(const Date &referenceDate, const std::vector< ext::shared_ptr< typename Traits::helper > > &instruments, const DayCounter &dayCounter, const ext::shared_ptr< OneFactorAffineModel > &model, const Interpolator &i={}, const bootstrap_type &bootstrap={})
Bootstrap< this_curve > bootstrap_type
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Probability
probability
Definition: types.hpp:82
Definition: any.hpp:35
STL namespace.