20#ifndef quantlib_interpolated_affine_hazard_rate_curve_hpp
21#define quantlib_interpolated_affine_hazard_rate_curve_hpp
60 template <
class Interpolator>
66 const std::vector<Date>&
dates,
69 const ext::shared_ptr<OneFactorAffineModel>& model,
72 const std::vector<Date>&
jumpDates = std::vector<Date>(),
73 const Interpolator& interpolator = Interpolator());
77 const ext::shared_ptr<OneFactorAffineModel>& model,
79 const Interpolator& interpolator);
83 const ext::shared_ptr<OneFactorAffineModel>& model,
84 const Interpolator& interpolator);
91 const std::vector<Time>&
times()
const;
92 const std::vector<Date>&
dates()
const;
93 const std::vector<Real>&
data()
const;
95 std::vector<std::pair<Date, Real> >
nodes()
const;
100 const ext::shared_ptr<OneFactorAffineModel>& model,
102 const std::vector<Date>&
jumpDates = std::vector<Date>(),
103 const Interpolator& interpolator = Interpolator());
107 const ext::shared_ptr<OneFactorAffineModel>& model,
109 const std::vector<Date>&
jumpDates = std::vector<Date>(),
110 const Interpolator& interpolator = Interpolator());
115 const ext::shared_ptr<OneFactorAffineModel>& model,
117 const std::vector<Date>&
jumpDates = std::vector<Date>(),
118 const Interpolator& interpolator = Interpolator());
154 template <
class Interpolator>
185 Date d = c->dates()[i];
191 return c->hazardRate(
d,
true);
202 Real r = *(std::min_element(c->data().begin(),
216 Real r = *(std::max_element(c->data().begin(),
241 return dates_.back();
245 inline const std::vector<Time>&
251 inline const std::vector<Date>&
257 inline const std::vector<Real>&
263 inline const std::vector<Rate>&
269 inline std::vector<std::pair<Date, Real> >
271 std::vector<std::pair<Date, Real> >
results(dates_.size());
272 for (
Size i=0; i<dates_.size(); ++i)
273 results[i] = std::make_pair(dates_[i], this->data_[i]);
283 if (t <= this->times_.back())
284 return this->interpolation_(
t,
true);
287 return this->data_.back();
297 Real initValHR = std::pow(model_->dynamics()->process()->x0(), 2);
300 return model_->discountBond(0.,
t, initValHR);
303 if (t <= this->times_.back()) {
304 integral = this->interpolation_.primitive(
t,
true);
308 this->interpolation_.primitive(this->times_.back(),
true)
309 + this->data_.back()*(
t - this->times_.back());
311 return std::exp(-integral) * model_->discountBond(0.,
t, initValHR);
319 QL_REQUIRE(tFwd <= tTarget,
"Probability time in the past.");
323 #if defined(QL_EXTRA_SAFETY_CHECKS)
325 model_->dynamics()->process()->x0(),
326 "Initial value different to process'.");
328 if (tFwd == 0.)
return survivalProbabilityImpl(tTarget);
329 if (tFwd - tTarget == 0.0)
332 Real integralTFwd, integralTP;
333 if (tFwd <= this->times_.back()) {
334 integralTFwd = this->interpolation_.primitive(tFwd,
true);
338 this->interpolation_.primitive(this->times_.back(),
true)
339 + this->data_.back()*(tFwd - this->times_.back());
341 if (tTarget <= this->times_.back()) {
342 integralTP = this->interpolation_.primitive(tTarget,
true);
346 this->interpolation_.primitive(this->times_.back(),
true)
347 + this->data_.back()*(tTarget - this->times_.back());
350 return std::exp(-(integralTP-integralTFwd)) *
351 model_->discountBond(tFwd, tTarget, yVal );
356 const DayCounter& dayCounter,
357 const ext::shared_ptr<OneFactorAffineModel>& model,
358 const std::vector<Handle<Quote> >& jumps,
359 const std::vector<Date>& jumpDates,
360 const T& interpolator)
361 : OneFactorAffineSurvivalStructure(model, dayCounter, jumps, jumpDates), InterpolatedCurve<
T>(
366 const Date& referenceDate,
367 const DayCounter& dayCounter,
368 const ext::shared_ptr<OneFactorAffineModel>& model,
369 const std::vector<Handle<Quote> >& jumps,
370 const std::vector<Date>& jumpDates,
371 const T& interpolator)
372 : OneFactorAffineSurvivalStructure(
373 model, referenceDate, Calendar(), dayCounter, jumps, jumpDates),
374 InterpolatedCurve<
T>(interpolator) {}
379 const Calendar& calendar,
380 const DayCounter& dayCounter,
381 const ext::shared_ptr<OneFactorAffineModel>& model,
382 const std::vector<Handle<Quote> >& jumps,
383 const std::vector<Date>& jumpDates,
384 const T& interpolator)
385 : OneFactorAffineSurvivalStructure(
386 model, settlementDays, calendar, dayCounter, jumps, jumpDates),
387 InterpolatedCurve<
T>(interpolator) {}
391 const std::vector<Date>& dates,
392 const std::vector<Rate>& hazardRates,
393 const DayCounter& dayCounter,
394 const ext::shared_ptr<OneFactorAffineModel>& model,
395 const Calendar& calendar,
396 const std::vector<Handle<Quote> >& jumps,
397 const std::vector<Date>& jumpDates,
398 const T& interpolator)
399 : OneFactorAffineSurvivalStructure(model, dates.at(0), calendar, dayCounter, jumps, jumpDates),
400 InterpolatedCurve<
T>(
std::vector<
Time>(), hazardRates, interpolator), dates_(dates) {
406 const std::vector<Date>& dates,
407 const std::vector<Rate>& hazardRates,
408 const DayCounter& dayCounter,
409 const ext::shared_ptr<OneFactorAffineModel>& model,
410 const Calendar& calendar,
411 const T& interpolator)
412 : OneFactorAffineSurvivalStructure(model, dates.at(0), calendar, dayCounter),
413 InterpolatedCurve<
T>(
std::vector<
Time>(), hazardRates, interpolator), dates_(dates) {
419 const std::vector<Date>& dates,
420 const std::vector<Rate>& hazardRates,
421 const DayCounter& dayCounter,
422 const ext::shared_ptr<OneFactorAffineModel>& model,
423 const T& interpolator)
424 : OneFactorAffineSurvivalStructure(model, dates.at(0), Calendar(), dayCounter),
425 InterpolatedCurve<
T>(
std::vector<
Time>(), hazardRates, interpolator), dates_(dates) {
432 QL_REQUIRE(dates_.size() >= T::requiredPoints,
433 "not enough input dates given");
434 QL_REQUIRE(this->data_.size() == dates_.size(),
435 "dates/data count mismatch");
437 this->setupTimes(dates_, dates_[0], dayCounter());
438 this->setupInterpolation();
439 this->interpolation_.update();
base helper class used for bootstrapping
Base helper class for bootstrapping.
Default probability term structure.
Rate hazardRate(const Date &d, bool extrapolate=false) const
const std::vector< Date > & jumpDates() const
Shared handle to an observable.
InterpolatedAffineHazardRateCurve(const DayCounter &, const ext::shared_ptr< OneFactorAffineModel > &model, const std::vector< Handle< Quote > > &jumps=std::vector< Handle< Quote > >(), const std::vector< Date > &jumpDates=std::vector< Date >(), const Interpolator &interpolator=Interpolator())
InterpolatedAffineHazardRateCurve(Natural settlementDays, const Calendar &, const DayCounter &, const ext::shared_ptr< OneFactorAffineModel > &model, const std::vector< Handle< Quote > > &jumps=std::vector< Handle< Quote > >(), const std::vector< Date > &jumpDates=std::vector< Date >(), const Interpolator &interpolator=Interpolator())
InterpolatedAffineHazardRateCurve(const std::vector< Date > &dates, const std::vector< Rate > &hazardRates, const DayCounter &dayCounter, const ext::shared_ptr< OneFactorAffineModel > &model, const Calendar &calendar, const Interpolator &interpolator)
Real hazardRateImpl(Time) const override
Returns the deterministic hazard rate component.
std::vector< Date > dates_
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
InterpolatedAffineHazardRateCurve(const std::vector< Date > &dates, const std::vector< Rate > &hazardRates, const DayCounter &dayCounter, const ext::shared_ptr< OneFactorAffineModel > &model, const Calendar &cal=Calendar(), const std::vector< Handle< Quote > > &jumps=std::vector< Handle< Quote > >(), const std::vector< Date > &jumpDates=std::vector< Date >(), const Interpolator &interpolator=Interpolator())
Probability survivalProbabilityImpl(Time) const override
survival probability calculation
InterpolatedAffineHazardRateCurve(const std::vector< Date > &dates, const std::vector< Rate > &hazardRates, const DayCounter &dayCounter, const ext::shared_ptr< OneFactorAffineModel > &model, const Interpolator &interpolator)
Date maxDate() const override
the latest date for which the curve can return values
const std::vector< Rate > & hazardRates() const
Probability conditionalSurvivalProbabilityImpl(Time tFwd, Time tTarget, Real yVal) const override
InterpolatedAffineHazardRateCurve(const Date &referenceDate, const DayCounter &, const ext::shared_ptr< OneFactorAffineModel > &model, const std::vector< Handle< Quote > > &jumps=std::vector< Handle< Quote > >(), const std::vector< Date > &jumpDates=std::vector< Date >(), const Interpolator &interpolator=Interpolator())
Helper class to build interpolated term structures.
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.
const Real minHazardRateComp
ext::shared_ptr< YieldTermStructure > r
default-probability bootstrap traits
InterpolatedAffineHazardRateCurve< Interpolator > type
static void updateGuess(std::vector< Real > &data, Real rate, Size i)
BootstrapHelper< DefaultProbabilityTermStructure > helper
static Real maxValueAfter(Size i, const C *c, bool validData, Size)
static Real guess(Size i, const C *c, bool validData, Size)
static Real initialValue(const DefaultProbabilityTermStructure *)
static Real minValueAfter(Size i, const C *c, bool validData, Size)
static Date initialDate(const DefaultProbabilityTermStructure *c)
static Size maxIterations()