1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Jose Aparicio
5 Copyright (C) 2008 Chris Kenyon
6 Copyright (C) 2008 Roland Lichters
7 Copyright (C) 2008 StatPro Italia srl
8 Copyright (C) 2009 Ferdinando Ametrano
9
10 This file is part of QuantLib, a free-software/open-source library
11 for financial quantitative analysts and developers - http://quantlib.org/
12
13 QuantLib is free software: you can redistribute it and/or modify it
14 under the terms of the QuantLib license. You should have received a
15 copy of the license along with this program; if not, please email
16 <quantlib-dev@lists.sf.net>. The license is also available online at
17 <http://quantlib.org/license.shtml>.
18
19 This program is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 FOR A PARTICULAR PURPOSE. See the license for more details.
22*/
23
24/*! \file hazardratestructure.hpp
25 \brief hazard-rate term structure
26*/
27
28#ifndef quantlib_hazard_rate_structure_hpp
29#define quantlib_hazard_rate_structure_hpp
30
31#include <ql/termstructures/defaulttermstructure.hpp>
32
33namespace QuantLib {
34
35 //! Hazard-rate term structure
36 /*! This abstract class acts as an adapter to
37 DefaultProbabilityTermStructure allowing the programmer to implement
38 only the <tt>hazardRateImpl(Time)</tt> method in derived classes.
39
40 Survival/default probabilities and default densities are calculated
41 from hazard rates.
42
43 Hazard rates are defined with annual frequency and continuous
44 compounding.
45
46 \ingroup defaultprobabilitytermstructures
47 */
48 class HazardRateStructure : public DefaultProbabilityTermStructure {
49 public:
50 /*! \name Constructors
51 See the TermStructure documentation for issues regarding
52 constructors.
53 */
54 //@{
55 HazardRateStructure(
56 const DayCounter& dayCounter = DayCounter(),
57 const std::vector<Handle<Quote> >& jumps = {},
58 const std::vector<Date>& jumpDates = {});
59 HazardRateStructure(
60 const Date& referenceDate,
61 const Calendar& cal = Calendar(),
62 const DayCounter& dayCounter = DayCounter(),
63 const std::vector<Handle<Quote> >& jumps = {},
64 const std::vector<Date>& jumpDates = {});
65 HazardRateStructure(
66 Natural settlementDays,
67 const Calendar& cal,
68 const DayCounter& dayCounter = DayCounter(),
69 const std::vector<Handle<Quote> >& jumps = {},
70 const std::vector<Date>& jumpDates = {});
71 //@}
72 protected:
73 /*! \name Calculations
74
75 This method must be implemented in derived classes to
76 perform the actual calculations. When it is called,
77 range check has already been performed; therefore, it
78 must assume that extrapolation is required.
79 */
80 //@{
81 //! hazard rate calculation
82 Real hazardRateImpl(Time) const override;
83 //@}
84
85 //! \name DefaultProbabilityTermStructure implementation
86 //@{
87 /*! survival probability calculation
88 implemented in terms of the hazard rate \f$ h(t) \f$ as
89 \f[
90 S(t) = \exp\left( - \int_0^t h(\tau) d\tau \right).
91 \f]
92
93 \warning This default implementation uses numerical integration,
94 which might be inefficient and inaccurate.
95 Derived classes should override it if a more efficient
96 implementation is available.
97 */
98 Probability survivalProbabilityImpl(Time) const override;
99 //! default density calculation
100 Real defaultDensityImpl(Time) const override;
101 //@}
102 };
103
104 // inline definitions
105
106 inline Real HazardRateStructure::defaultDensityImpl(Time t) const {
107 return hazardRateImpl(t)*survivalProbabilityImpl(t);
108 }
109
110}
111
112#endif
113

source code of quantlib/ql/termstructures/credit/hazardratestructure.hpp