QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
onefactoraffinesurvival.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) 2015 Jose Aparicio
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20#ifndef onefactor_affine_survival_hpp
21#define onefactor_affine_survival_hpp
22
26#include <utility>
27
28namespace QuantLib {
29
30 /*! Survival probability term structure based on a one factor stochastic
31 model of the default intensity.
32 */
33 /*
34 While deriving from the hazard rate class the HRTS refers only to the
35 deterministic part of the model. The probabilities depend on this
36 component and the stochastic part and are rewritten here.
37 Derived classes need to specify the deterministic part
38 of the hazard rate if any (the one returned by 'hazardRateImpl'). It
39 is needed for the conditional/forward probabilities.
40 */
42 : public HazardRateStructure {
43 public:
44 // implement remaining constructors.....
46 ext::shared_ptr<OneFactorAffineModel> model,
48 const std::vector<Handle<Quote> >& jumps = std::vector<Handle<Quote> >(),
49 const std::vector<Date>& jumpDates = std::vector<Date>())
50 : HazardRateStructure(dayCounter, jumps, jumpDates), model_(std::move(model)) {}
51
53 ext::shared_ptr<OneFactorAffineModel> model,
54 const Date& referenceDate,
55 const Calendar& cal = Calendar(),
57 const std::vector<Handle<Quote> >& jumps = std::vector<Handle<Quote> >(),
58 const std::vector<Date>& jumpDates = std::vector<Date>())
60 model_(std::move(model)) {}
61
63 ext::shared_ptr<OneFactorAffineModel> model,
65 const Calendar& calendar,
67 const std::vector<Handle<Quote> >& jumps = std::vector<Handle<Quote> >(),
68 const std::vector<Date>& jumpDates = std::vector<Date>())
70 model_(std::move(model)) {}
71
72 //! \name TermStructure interface
73 //@{
74 // overwrite on mkt models (e.g. bootstraps)
75 Date maxDate() const override { return Date::maxDate(); }
76
77 /* Notice this is not calling hazard rate methods, these are
78 stochastic now.
79 */
80 /*!
81 Returns the probability at a future time dTgt, conditional to
82 survival at a prior time dFwd and to the realization of a particular
83 hazard rate value at dFwd.
84 \param dFwd Time of the forward survival calculation and HR
85 realization.
86 \param dTgt Target time of survival probability.
87 \param yVal Realized value of the HR at time dFwd.
88 \param extrapolate Allow curve extrapolation.
89 \return Survival probability.
90
91 \todo turn into a protected method to be called by
92 defaults and survivals
93 */
94 /*
95 Note: curve extrapolation has a different meaning on different curve
96 types; for matched to market structures the credit market curves
97 would be requested for extrapolation; for affine models on top of
98 a static term structure it is this one that will be required for
99 extrapolation.
100 */
102 const Date& dTgt,
103 Real yVal,
104 bool extrapolate = false) const {
106 yVal, extrapolate);
107 }
109 Time tFwd, Time tgt, Real yVal,
110 bool extrapolate = false) const
111 {
112 #if defined(QL_EXTRA_SAFETY_CHECKS)
113 QL_REQUIRE(tgt >= tFwd, "Incorrect dates ordering.");
114 #endif
115 checkRange(tFwd, extrapolate);
116 checkRange(tgt, extrapolate);
117
118 // \todo ADD JUMPS TREATMENT
119
120 return conditionalSurvivalProbabilityImpl(tFwd, tgt, yVal);
121 }
122 //@}
123 // DefaultTermStructure interface
125 Rate hazardRate(Time t, bool extrapolate = false) const {
126 checkRange(t, extrapolate);
127 return hazardRateImpl(t);
128 }
129 protected:
130 //! \name DefaultProbabilityTermStructure implementation
131 //@{
133 Real defaultDensityImpl(Time) const override;
134 //@}
135 // avoid call super
136 // \todo addd date overload
137 virtual Probability conditionalSurvivalProbabilityImpl(Time tFwd, Time tgt, Real yVal) const;
138
139 // HazardRateStructure interface
140 Real hazardRateImpl(Time) const override {
141 // no deterministic component
142 return 0.;
143 }
144
145 ext::shared_ptr<OneFactorAffineModel> model_;
146 };
147
148 inline Probability
150 Time t) const
151 {
152 Real initValHR =
153 model_->dynamics()->shortRate(0.,
154 model_->dynamics()->process()->x0());
155
156 return model_->discountBond(0., t, initValHR);
157 }
158
159 inline Probability
161 Time tFwd, Time tgt, Real yVal) const {
162 return model_->discountBond(tFwd, tgt, yVal);
163 }
164
165 inline Real
167 Real initValHR =
168 model_->dynamics()->shortRate(0.,
169 model_->dynamics()->process()->x0());;
170
172 model_->discountBond(0., t, initValHR);
173 }
174}
175
176#endif
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
static Date maxDate()
latest allowed date
Definition: date.cpp:771
day counter class
Definition: daycounter.hpp:44
Rate hazardRate(const Date &d, bool extrapolate=false) const
const std::vector< Date > & jumpDates() const
Shared handle to an observable.
Definition: handle.hpp:41
Hazard-rate term structure.
Real defaultDensityImpl(Time) const override
default density calculation
OneFactorAffineSurvivalStructure(ext::shared_ptr< OneFactorAffineModel > model, const DayCounter &dayCounter=DayCounter(), const std::vector< Handle< Quote > > &jumps=std::vector< Handle< Quote > >(), const std::vector< Date > &jumpDates=std::vector< Date >())
Probability conditionalSurvivalProbability(const Date &dFwd, const Date &dTgt, Real yVal, bool extrapolate=false) const
Real hazardRateImpl(Time) const override
hazard rate calculation
Probability conditionalSurvivalProbability(Time tFwd, Time tgt, Real yVal, bool extrapolate=false) const
virtual Probability conditionalSurvivalProbabilityImpl(Time tFwd, Time tgt, Real yVal) const
ext::shared_ptr< OneFactorAffineModel > model_
OneFactorAffineSurvivalStructure(ext::shared_ptr< OneFactorAffineModel > model, Natural settlementDays, const Calendar &calendar, const DayCounter &dayCounter=DayCounter(), const std::vector< Handle< Quote > > &jumps=std::vector< Handle< Quote > >(), const std::vector< Date > &jumpDates=std::vector< Date >())
Probability survivalProbabilityImpl(Time) const override
survival probability calculation
Date maxDate() const override
the latest date for which the curve can return values
OneFactorAffineSurvivalStructure(ext::shared_ptr< OneFactorAffineModel > model, const Date &referenceDate, const Calendar &cal=Calendar(), const DayCounter &dayCounter=DayCounter(), const std::vector< Handle< Quote > > &jumps=std::vector< Handle< Quote > >(), const std::vector< Date > &jumpDates=std::vector< Date >())
Rate hazardRate(Time t, bool extrapolate=false) const
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
Time timeFromReference(const Date &date) const
date/time conversion
void checkRange(const Date &d, bool extrapolate) const
date-range check
virtual DayCounter dayCounter() const
the day counter used for date/time conversion
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
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
hazard-rate term structure
Definition: any.hpp:35
STL namespace.
Abstract one-factor interest rate model class.
stochastic processes