24#ifndef quantlib_interpolated_survival_probability_curve_hpp
25#define quantlib_interpolated_survival_probability_curve_hpp
35 template <
class Interpolator>
41 const std::vector<Date>&
dates,
42 const std::vector<Probability>& probabilities,
47 const Interpolator& interpolator = {});
49 const std::vector<Date>&
dates,
50 const std::vector<Probability>& probabilities,
53 const Interpolator& interpolator);
55 const std::vector<Date>&
dates,
56 const std::vector<Probability>& probabilities,
58 const Interpolator& interpolator);
65 const std::vector<Time>&
times()
const;
66 const std::vector<Date>&
dates()
const;
67 const std::vector<Real>&
data()
const;
69 std::vector<std::pair<Date, Real> >
nodes()
const;
76 const Interpolator& interpolator = {});
82 const Interpolator& interpolator = {});
89 const Interpolator& interpolator = {});
104 return dates_.back();
108 inline const std::vector<Time>&
114 inline const std::vector<Date>&
120 inline const std::vector<Real>&
126 inline const std::vector<Probability>&
132 inline std::vector<std::pair<Date,Real> >
134 std::vector<std::pair<Date,Real> >
results(dates_.size());
135 for (
Size i=0; i<dates_.size(); ++i)
136 results[i] = std::make_pair(dates_[i],this->data_[i]);
148 if (t <= this->times_.back())
149 return this->interpolation_(
t,
true);
152 Time tMax = this->times_.back();
154 Rate hazardMax = - this->interpolation_.derivative(tMax) / sMax;
155 return sMax * std::exp(- hazardMax * (
t-tMax));
161 if (t <= this->times_.back())
162 return -this->interpolation_.derivative(
t,
true);
165 Time tMax = this->times_.back();
167 Rate hazardMax = - this->interpolation_.derivative(tMax) / sMax;
168 return sMax * hazardMax * std::exp(- hazardMax * (
t-tMax));
173 const DayCounter& dayCounter,
174 const std::vector<Handle<Quote> >& jumps,
175 const std::vector<Date>& jumpDates,
176 const T& interpolator)
177 : SurvivalProbabilityStructure(dayCounter, jumps, jumpDates),
178 InterpolatedCurve<
T>(interpolator) {}
182 const Date& referenceDate,
183 const DayCounter& dayCounter,
184 const std::vector<Handle<Quote> >& jumps,
185 const std::vector<Date>& jumpDates,
186 const T& interpolator)
187 : SurvivalProbabilityStructure(referenceDate, Calendar(), dayCounter, jumps, jumpDates),
188 InterpolatedCurve<
T>(interpolator) {}
193 const Calendar& calendar,
194 const DayCounter& dayCounter,
195 const std::vector<Handle<Quote> >& jumps,
196 const std::vector<Date>& jumpDates,
197 const T& interpolator)
198 : SurvivalProbabilityStructure(settlementDays, calendar, dayCounter, jumps, jumpDates),
199 InterpolatedCurve<
T>(interpolator) {}
203 const std::vector<Date>& dates,
204 const std::vector<Probability>& probabilities,
205 const DayCounter& dayCounter,
206 const Calendar& calendar,
207 const std::vector<Handle<Quote> >& jumps,
208 const std::vector<Date>& jumpDates,
209 const T& interpolator)
210 : SurvivalProbabilityStructure(dates.at(0), calendar, dayCounter, jumps, jumpDates),
211 InterpolatedCurve<
T>(
std::vector<
Time>(), probabilities, interpolator),
219 const std::vector<Date>& dates,
220 const std::vector<Probability>& probabilities,
221 const DayCounter& dayCounter,
222 const Calendar& calendar,
223 const T& interpolator)
224 : SurvivalProbabilityStructure(dates.at(0), calendar, dayCounter),
225 InterpolatedCurve<
T>(
std::vector<
Time>(), probabilities, interpolator),
233 const std::vector<Date>& dates,
234 const std::vector<Probability>& probabilities,
235 const DayCounter& dayCounter,
236 const T& interpolator)
237 : SurvivalProbabilityStructure(dates.at(0), Calendar(), dayCounter),
238 InterpolatedCurve<
T>(
std::vector<
Time>(), probabilities, interpolator),
251 QL_REQUIRE(dates_.size() >= T::requiredPoints,
252 "not enough input dates given");
253 QL_REQUIRE(this->data_.size() == dates_.size(),
254 "dates/data count mismatch");
256 "the first probability must be == 1.0 "
257 "to flag the corresponding date as reference date");
259 this->setupTimes(dates_, dates_[0], dayCounter());
261 for (
Size i=1; i<dates_.size(); ++i) {
262 QL_REQUIRE(this->data_[i] > 0.0,
"negative probability");
263 QL_REQUIRE(this->data_[i] <= this->data_[i-1],
264 "negative hazard rate implied by the survival "
266 this->data_[i] <<
" at " << dates_[i] <<
267 " (t=" << this->times_[i] <<
") after the survival "
269 this->data_[i-1] <<
" at " << dates_[i-1] <<
270 " (t=" << this->times_[i-1] <<
")");
273 this->setupInterpolation();
274 this->interpolation_.update();
const std::vector< Date > & jumpDates() const
Shared handle to an observable.
Helper class to build interpolated term structures.
DefaultProbabilityTermStructure based on interpolation of survival probabilities.
Real defaultDensityImpl(Time) const override
default density calculation
const std::vector< Probability > & survivalProbabilities() const
InterpolatedSurvivalProbabilityCurve(const DayCounter &, const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
std::vector< Date > dates_
InterpolatedSurvivalProbabilityCurve(const std::vector< Date > &dates, const std::vector< Probability > &probabilities, const DayCounter &dayCounter, const Calendar &calendar, const Interpolator &interpolator)
const std::vector< Date > & dates() const
const std::vector< Real > & data() const
std::vector< std::pair< Date, Real > > nodes() const
const std::vector< Time > & times() const
Probability survivalProbabilityImpl(Time) const override
survival probability calculation
InterpolatedSurvivalProbabilityCurve(Natural settlementDays, const Calendar &, const DayCounter &, const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
Date maxDate() const override
the latest date for which the curve can return values
InterpolatedSurvivalProbabilityCurve(const std::vector< Date > &dates, const std::vector< Probability > &probabilities, const DayCounter &dayCounter, const Calendar &calendar=Calendar(), const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
InterpolatedSurvivalProbabilityCurve(const std::vector< Date > &dates, const std::vector< Probability > &probabilities, const DayCounter &dayCounter, const Interpolator &interpolator)
InterpolatedSurvivalProbabilityCurve(const Date &referenceDate, const DayCounter &, const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
Hazard-rate term structure.
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
virtual DayCounter dayCounter() const
the day counter used for date/time conversion
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Real Time
continuous quantity with 1-year units
unsigned QL_INTEGER Natural
positive integer
Real Probability
probability
std::size_t Size
size of a container
Helper class to build interpolated term structures.
survival-probability term structure