QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
defaulttermstructure.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) 2008 Chris Kenyon
5 Copyright (C) 2008 Roland Lichters
6 Copyright (C) 2008 StatPro Italia srl
7 Copyright (C) 2009 Ferdinando Ametrano
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
23/*! \file defaulttermstructure.hpp
24 \brief default-probability term structure
25*/
26
27#ifndef quantlib_default_term_structure_hpp
28#define quantlib_default_term_structure_hpp
29
30#include <ql/termstructure.hpp>
31#include <ql/quote.hpp>
32
33namespace QuantLib {
34
35 //! Default probability term structure
36 /*! This abstract class defines the interface of concrete
37 credit structures which will be derived from this one.
38
39 \ingroup defaultprobabilitytermstructures
40 */
42 public:
43 /*! \name Constructors
44 See the TermStructure documentation for issues regarding
45 constructors.
46 */
47 //@{
49 const DayCounter& dc = DayCounter(),
50 std::vector<Handle<Quote> > jumps = {},
51 const std::vector<Date>& jumpDates = {});
53 const Date& referenceDate,
54 const Calendar& cal = Calendar(),
55 const DayCounter& dc = DayCounter(),
56 std::vector<Handle<Quote> > jumps = {},
57 const std::vector<Date>& jumpDates = {});
60 const Calendar& cal,
61 const DayCounter& dc = DayCounter(),
62 std::vector<Handle<Quote> > jumps = {},
63 const std::vector<Date>& jumpDates = {});
64 //@}
65
66 /*! \name Survival probabilities
67
68 These methods return the survival probability from the reference
69 date until a given date or time. In the latter case, the time
70 is calculated as a fraction of year from the reference date.
71 */
72 //@{
74 bool extrapolate = false) const;
75 /*! The same day-counting rule used by the term structure
76 should be used for calculating the passed time t.
77 */
79 bool extrapolate = false) const;
80 //@}
81
82 /*! \name Default probabilities
83
84 These methods return the default probability from the reference
85 date until a given date or time. In the latter case, the time
86 is calculated as a fraction of year from the reference date.
87 */
88 //@{
90 bool extrapolate = false) const;
91 /*! The same day-counting rule used by the term structure
92 should be used for calculating the passed time t.
93 */
95 bool extrapolate = false) const;
96 //! probability of default between two given dates
98 const Date&,
99 bool extrapolate = false) const;
100 //! probability of default between two given times
102 Time,
103 bool extrapo = false) const;
104 //@}
105
106 /*! \name Default densities
107
108 These methods return the default density at a given date or time.
109 In the latter case, the time is calculated as a fraction of year
110 from the reference date.
111 */
112 //@{
113 Real defaultDensity(const Date& d,
114 bool extrapolate = false) const;
116 bool extrapolate = false) const;
117 //@}
118
119 /*! \name Hazard rates
120
121 These methods returns the hazard rate at a given date or time.
122 In the latter case, the time is calculated as a fraction of year
123 from the reference date.
124
125 Hazard rates are defined with annual frequency and continuous
126 compounding.
127 */
128
129 //@{
131 bool extrapolate = false) const;
133 bool extrapolate = false) const;
134 //@}
135
136 //! \name Jump inspectors
137 //@{
138 const std::vector<Date>& jumpDates() const;
139 const std::vector<Time>& jumpTimes() const;
140 //@}
141
142 //! \name Observer interface
143 //@{
144 void update() override;
145 //@}
146 protected:
147 /*! \name Calculations
148 The first two methods must be implemented in derived classes to
149 perform the actual calculations. When they are called,
150 range check has already been performed; therefore, they
151 must assume that extrapolation is required.
152 The third method has a default implementation which can be
153 overriden with a more efficient implementation in derived
154 classes.
155 */
156 //@{
157 //! survival probability calculation
159 //! default density calculation
160 virtual Real defaultDensityImpl(Time) const = 0;
161 //! hazard rate calculation
162 virtual Real hazardRateImpl(Time) const;
163 //@}
164 private:
165 // methods
166 void setJumps();
167 // data members
168 std::vector<Handle<Quote> > jumps_;
169 std::vector<Date> jumpDates_;
170 std::vector<Time> jumpTimes_;
173 };
174
175 // inline definitions
176
177 inline
179 const Date& d,
180 bool extrapolate) const {
181 return survivalProbability(timeFromReference(d), extrapolate);
182 }
183
184 inline
186 const Date& d,
187 bool extrapolate) const {
188 return 1.0 - survivalProbability(d, extrapolate);
189 }
190
191 inline
193 Time t,
194 bool extrapolate) const {
195 return 1.0 - survivalProbability(t, extrapolate);
196 }
197
198 inline
200 const Date& d,
201 bool extrapolate) const {
202 return defaultDensity(timeFromReference(d), extrapolate);
203 }
204
205 inline
207 Time t,
208 bool extrapolate) const {
209 checkRange(t, extrapolate);
210 return defaultDensityImpl(t);
211 }
212
213 inline
215 bool extrapolate) const {
216 return hazardRate(timeFromReference(d), extrapolate);
217 }
218
219 inline
222 return S == 0.0 ? Rate(0.0) : defaultDensity(t, true)/S;
223 }
224
226 bool extrapolate) const {
227 checkRange(t, extrapolate);
228 return hazardRateImpl(t);
229 }
230
231 inline
232 const std::vector<Date>&
234 return this->jumpDates_;
235 }
236
237 inline
238 const std::vector<Time>&
240 return this->jumpTimes_;
241 }
242
246 setJumps();
247 }
248
249}
250
251#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Default probability term structure.
Probability survivalProbability(const Date &d, bool extrapolate=false) const
virtual Probability survivalProbabilityImpl(Time) const =0
survival probability calculation
virtual Real defaultDensityImpl(Time) const =0
default density calculation
Probability defaultProbability(const Date &d, bool extrapolate=false) const
const std::vector< Time > & jumpTimes() const
Rate hazardRate(const Date &d, bool extrapolate=false) const
Real defaultDensity(const Date &d, bool extrapolate=false) const
const std::vector< Date > & jumpDates() const
virtual Real hazardRateImpl(Time) const
hazard rate calculation
Shared handle to an observable.
Definition: handle.hpp:41
Basic term-structure functionality.
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
void update() override
Time timeFromReference(const Date &date) const
date/time conversion
void checkRange(const Date &d, bool extrapolate) const
date-range check
const DefaultType & t
Date d
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
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
purely virtual base class for market observables
base class for term structures