Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
SurvivalProbabilityCurve< Interpolator > Class Template Reference

DefaultProbabilityTermStructure based on interpolation of survival probability quotes. More...

#include <qle/termstructures/survivalprobabilitycurve.hpp>

+ Inheritance diagram for SurvivalProbabilityCurve< Interpolator >:
+ Collaboration diagram for SurvivalProbabilityCurve< Interpolator >:

Public Types

enum class  Extrapolation { flatFwd , flatZero }
 

Public Member Functions

 SurvivalProbabilityCurve (const std::vector< Date > &dates, const std::vector< Handle< Quote > > &quotes, const DayCounter &dayCounter, const Calendar &calendar=Calendar(), const std::vector< Handle< Quote > > &jumps=std::vector< Handle< Quote > >(), const std::vector< Date > &jumpDates=std::vector< Date >(), const Interpolator &interpolator=Interpolator(), const Extrapolation extrpolation=Extrapolation::flatFwd)
 
TermStructure interface
Date maxDate () const override
 
other inspectors
const std::vector< Time > & times () const
 
const std::vector< Date > & dates () const
 
const std::vector< Real > & data () const
 
const std::vector< Probability > & survivalProbabilities () const
 
const std::vector< Handle< Quote > > & quotes () const
 
std::vector< std::pair< Date, Real > > nodes () const
 

Private Member Functions

LazyObject interface
void performCalculations () const override
 

DefaultProbabilityTermStructure implementation

std::vector< Date > dates_
 
std::vector< Handle< Quote > > quotes_
 
Extrapolation extrapolation_
 
Probability survivalProbabilityImpl (Time) const override
 
Real defaultDensityImpl (Time t) const override
 

Observer interface

void update () override
 
void initialize ()
 

Detailed Description

template<class Interpolator>
class QuantExt::SurvivalProbabilityCurve< Interpolator >

DefaultProbabilityTermStructure based on interpolation of survival probability quotes.

Definition at line 38 of file survivalprobabilitycurve.hpp.

Member Enumeration Documentation

◆ Extrapolation

enum class Extrapolation
strong

Constructor & Destructor Documentation

◆ SurvivalProbabilityCurve()

SurvivalProbabilityCurve ( const std::vector< Date > &  dates,
const std::vector< Handle< Quote > > &  quotes,
const DayCounter &  dayCounter,
const Calendar &  calendar = Calendar(),
const std::vector< Handle< Quote > > &  jumps = std::vector<Handle<Quote>>(),
const std::vector< Date > &  jumpDates = std::vector<Date>(),
const Interpolator &  interpolator = Interpolator(),
const Extrapolation  extrpolation = Extrapolation::flatFwd 
)

Definition at line 139 of file survivalprobabilitycurve.hpp.

145 : SurvivalProbabilityStructure(dates.front(), calendar, dayCounter, jumps, jumpDates),
146 InterpolatedCurve<T>(std::vector<Time>(), std::vector<Real>(), interpolator), dates_(dates), quotes_(quotes),
147 extrapolation_(extrapolation) {
148 QL_REQUIRE(dates_.size() >= T::requiredPoints, "not enough input dates given");
149 QL_REQUIRE(quotes_.size() == dates_.size(), "dates/data count mismatch");
150 for (Size i = 0; i < quotes_.size(); i++)
151 registerWith(quotes_[i]);
152 initialize();
153}
const std::vector< Date > & dates() const
const std::vector< Handle< Quote > > & quotes() const
std::vector< Handle< Quote > > quotes_
+ Here is the call graph for this function:

Member Function Documentation

◆ maxDate()

Date maxDate
override

Definition at line 85 of file survivalprobabilitycurve.hpp.

85{ return dates_.back(); }

◆ times()

const std::vector< Time > & times

Definition at line 87 of file survivalprobabilitycurve.hpp.

87{ return this->times_; }

◆ dates()

const std::vector< Date > & dates

Definition at line 89 of file survivalprobabilitycurve.hpp.

89{ return dates_; }

◆ data()

const std::vector< Real > & data

Definition at line 91 of file survivalprobabilitycurve.hpp.

91{ return this->data_; }

◆ survivalProbabilities()

const std::vector< Probability > & survivalProbabilities

Definition at line 93 of file survivalprobabilitycurve.hpp.

93 {
94 return this->data_;
95}

◆ quotes()

const std::vector< Handle< Quote > > & quotes ( ) const

◆ nodes()

std::vector< std::pair< Date, Real > > nodes

Definition at line 97 of file survivalprobabilitycurve.hpp.

97 {
98 std::vector<std::pair<Date, Real>> results(dates_.size());
99 for (Size i = 0; i < dates_.size(); ++i)
100 results[i] = std::make_pair(dates_[i], this->data_[i]);
101 return results;
102}

◆ update()

void update
override

Definition at line 155 of file survivalprobabilitycurve.hpp.

155 {
156 LazyObject::update();
157 DefaultProbabilityTermStructure::update();
158}

◆ initialize()

void initialize
private

Definition at line 169 of file survivalprobabilitycurve.hpp.

169 {
170 QL_REQUIRE(dates_.size() >= T::requiredPoints, "not enough input dates given");
171 QL_REQUIRE(quotes_.size() == dates_.size(), "dates/data count mismatch");
172
173 this->times_.resize(dates_.size());
174 this->data_.resize(dates_.size());
175 this->times_[0] = 0.0;
176 for (Size i = 1; i < dates_.size(); ++i) {
177 QL_REQUIRE(dates_[i] > dates_[i - 1], "invalid date (" << dates_[i] << ", vs " << dates_[i - 1] << ")");
178 this->times_[i] = dayCounter().yearFraction(dates_[0], dates_[i]);
179 QL_REQUIRE(!close(this->times_[i], this->times_[i - 1]), "two dates correspond to the same time "
180 "under this curve's day count convention");
181 // QL_REQUIRE(this->data_[i] > 0.0, "negative probability");
182 // QL_REQUIRE(this->data_[i] <= this->data_[i-1],
183 // "negative hazard rate implied by the survival "
184 // "probability " <<
185 // this->data_[i] << " at " << dates_[i] <<
186 // " (t=" << this->times_[i] << ") after the survival "
187 // "probability " <<
188 // this->data_[i-1] << " at " << dates_[i-1] <<
189 // " (t=" << this->times_[i-1] << ")");
190 }
191}
+ Here is the caller graph for this function:

◆ performCalculations()

void performCalculations
overrideprivate

Definition at line 160 of file survivalprobabilitycurve.hpp.

160 {
161 for (Size i = 0; i < dates_.size(); ++i)
162 this->data_[i] = quotes_[i]->value();
163
164 this->interpolation_ =
165 this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->data_.begin());
166 this->interpolation_.update();
167}

◆ survivalProbabilityImpl()

Probability survivalProbabilityImpl ( Time  t) const
overrideprivate

Definition at line 106 of file survivalprobabilitycurve.hpp.

106 {
107 calculate();
108 if (t <= this->times_.back())
109 return this->interpolation_(t, true);
110
111 // flat hazard rate extrapolation
112 Time tMax = this->times_.back();
113 Probability sMax = this->data_.back();
115 Rate hazardMax = -this->interpolation_.derivative(tMax) / sMax;
116 return sMax * std::exp(-hazardMax * (t - tMax));
117 } else {
118 return std::pow(sMax, t / tMax);
119 }
120}

◆ defaultDensityImpl()

Real defaultDensityImpl ( Time  t) const
overrideprivate

Definition at line 122 of file survivalprobabilitycurve.hpp.

122 {
123 calculate();
124 if (t <= this->times_.back())
125 return -this->interpolation_.derivative(t, true);
126
127 // flat hazard rate extrapolation
128 Time tMax = this->times_.back();
129 Probability sMax = this->data_.back();
131 Rate hazardMax = -this->interpolation_.derivative(tMax) / sMax;
132 return sMax * hazardMax * std::exp(-hazardMax * (t - tMax));
133 } else {
134 return -std::log(sMax) / tMax * std::pow(sMax, t / tMax);
135 }
136}

Member Data Documentation

◆ dates_

std::vector<Date> dates_
mutableprivate

Definition at line 78 of file survivalprobabilitycurve.hpp.

◆ quotes_

std::vector<Handle<Quote> > quotes_
private

Definition at line 79 of file survivalprobabilitycurve.hpp.

◆ extrapolation_

Extrapolation extrapolation_
private

Definition at line 80 of file survivalprobabilitycurve.hpp.