44#ifndef quantext_interpolated_hazard_rate_curve_hpp
45#define quantext_interpolated_hazard_rate_curve_hpp
47#include <ql/termstructures/credit/hazardratestructure.hpp>
48#include <ql/termstructures/interpolatedcurve.hpp>
59 template <
class Interpolator>
62 protected InterpolatedCurve<Interpolator> {
65 const std::vector<Date>&
dates,
67 const DayCounter& dayCounter,
68 const Calendar& cal = Calendar(),
69 const std::vector<Handle<Quote> >& jumps =
70 std::vector<Handle<Quote> >(),
71 const std::vector<Date>& jumpDates = std::vector<Date>(),
72 const Interpolator& interpolator = Interpolator(),
73 const bool allowNegativeRates =
false);
75 const std::vector<Date>&
dates,
77 const DayCounter& dayCounter,
78 const Calendar& calendar,
79 const Interpolator& interpolator,
80 const bool allowNegativeRates =
false);
82 const std::vector<Date>&
dates,
84 const DayCounter& dayCounter,
85 const Interpolator& interpolator,
86 const bool allowNegativeRates =
false);
93 const std::vector<Time>&
times()
const;
94 const std::vector<Date>&
dates()
const;
95 const std::vector<Real>&
data()
const;
97 std::vector<std::pair<Date, Real> >
nodes()
const;
102 const std::vector<Handle<Quote> >& jumps = std::vector<Handle<Quote> >(),
103 const std::vector<Date>& jumpDates = std::vector<Date>(),
104 const Interpolator& interpolator = Interpolator(),
105 const bool allowNegativeRates =
false);
107 const Date& referenceDate,
109 const std::vector<Handle<Quote> >& jumps = std::vector<Handle<Quote> >(),
110 const std::vector<Date>& jumpDates = std::vector<Date>(),
111 const Interpolator& interpolator = Interpolator(),
112 const bool allowNegativeRates =
false);
114 Natural settlementDays,
117 const std::vector<Handle<Quote> >& jumps = std::vector<Handle<Quote> >(),
118 const std::vector<Date>& jumpDates = std::vector<Date>(),
119 const Interpolator& interpolator = Interpolator(),
120 const bool allowNegativeRates =
false);
137 return dates_.back();
141 inline const std::vector<Time>&
147 inline const std::vector<Date>&
153 inline const std::vector<Real>&
159 inline const std::vector<Rate>&
165 inline std::vector<std::pair<Date, Real> >
167 std::vector<std::pair<Date, Real> > results(dates_.size());
168 for (Size i=0; i<dates_.size(); ++i)
169 results[i] = std::make_pair(dates_[i], this->data_[i]);
179 if (t <= this->times_.back())
180 return this->interpolation_(t,
true);
183 return this->data_.back();
193 if (t <= this->times_.back()) {
194 integral = this->interpolation_.primitive(t,
true);
197 integral = this->interpolation_.primitive(this->times_.back(),
true)
198 + this->data_.back()*(t - this->times_.back());
205 const DayCounter& dayCounter,
206 const std::vector<Handle<Quote> >& jumps,
207 const std::vector<Date>& jumpDates,
208 const T& interpolator,
209 const bool allowNegativeRates)
211 InterpolatedCurve<T>(interpolator), allowNegativeRates_(allowNegativeRates) {}
215 const Date& referenceDate,
216 const DayCounter& dayCounter,
217 const std::vector<Handle<Quote> >& jumps,
218 const std::vector<Date>& jumpDates,
219 const T& interpolator,
220 const bool allowNegativeRates)
222 InterpolatedCurve<T>(interpolator), allowNegativeRates_(allowNegativeRates) {}
226 Natural settlementDays,
227 const Calendar& calendar,
228 const DayCounter& dayCounter,
229 const std::vector<Handle<Quote> >& jumps,
230 const std::vector<Date>& jumpDates,
231 const T& interpolator,
232 const bool allowNegativeRates)
234 InterpolatedCurve<T>(interpolator), allowNegativeRates_(allowNegativeRates) {}
238 const std::vector<Date>& dates,
239 const std::vector<Rate>& hazardRates,
240 const DayCounter& dayCounter,
241 const Calendar& calendar,
242 const std::vector<Handle<Quote> >& jumps,
243 const std::vector<Date>& jumpDates,
244 const T& interpolator,
245 const bool allowNegativeRates)
247 InterpolatedCurve<T>(std::vector<Time>(), hazardRates, interpolator),
248 dates_(dates), allowNegativeRates_(allowNegativeRates)
255 const std::vector<Date>& dates,
256 const std::vector<Rate>& hazardRates,
257 const DayCounter& dayCounter,
258 const Calendar& calendar,
259 const T& interpolator,
260 const bool allowNegativeRates)
262 InterpolatedCurve<T>(std::vector<Time>(), hazardRates, interpolator),
263 dates_(dates), allowNegativeRates_(allowNegativeRates)
270 const std::vector<Date>& dates,
271 const std::vector<Rate>& hazardRates,
272 const DayCounter& dayCounter,
273 const T& interpolator,
274 const bool allowNegativeRates)
276 InterpolatedCurve<T>(std::vector<Time>(), hazardRates, interpolator),
277 dates_(dates), allowNegativeRates_(allowNegativeRates)
287 QL_REQUIRE(dates_.size() >= T::requiredPoints,
288 "not enough input dates given");
289 QL_REQUIRE(this->data_.size() == dates_.size(),
290 "dates/data count mismatch");
292 this->times_.resize(dates_.size());
293 this->times_[0] = 0.0;
294 for (Size i=1; i<dates_.size(); ++i) {
295 QL_REQUIRE(dates_[i] > dates_[i-1],
296 "invalid date (" << dates_[i] <<
", vs "
297 << dates_[i-1] <<
")");
298 this->times_[i] = dayCounter().yearFraction(dates_[0], dates_[i]);
299 QL_REQUIRE(!close(this->times_[i], this->times_[i-1]),
300 "two dates correspond to the same time "
301 "under this curve's day count convention");
302 QL_REQUIRE(allowNegativeRates_ || this->data_[i] >= 0.0,
"negative hazard rate");
305 this->interpolation_ =
306 this->interpolator_.interpolate(this->times_.begin(),
308 this->data_.begin());
309 this->interpolation_.update();
DefaultProbabilityTermStructure based on interpolation of hazard rates.
Real hazardRateImpl(Time) const override
std::vector< Date > dates_
InterpolatedHazardRateCurve(const Date &referenceDate, const DayCounter &, const std::vector< Handle< Quote > > &jumps=std::vector< Handle< Quote > >(), const std::vector< Date > &jumpDates=std::vector< Date >(), const Interpolator &interpolator=Interpolator(), const bool allowNegativeRates=false)
const std::vector< Date > & dates() const
InterpolatedHazardRateCurve(Natural settlementDays, const Calendar &, const DayCounter &, const std::vector< Handle< Quote > > &jumps=std::vector< Handle< Quote > >(), const std::vector< Date > &jumpDates=std::vector< Date >(), const Interpolator &interpolator=Interpolator(), const bool allowNegativeRates=false)
const std::vector< Real > & data() const
InterpolatedHazardRateCurve(const std::vector< Date > &dates, const std::vector< Rate > &hazardRates, const DayCounter &dayCounter, 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(), const bool allowNegativeRates=false)
std::vector< std::pair< Date, Real > > nodes() const
InterpolatedHazardRateCurve(const std::vector< Date > &dates, const std::vector< Rate > &hazardRates, const DayCounter &dayCounter, const Interpolator &interpolator, const bool allowNegativeRates=false)
const std::vector< Time > & times() const
Probability survivalProbabilityImpl(Time) const override
Date maxDate() const override
const std::vector< Rate > & hazardRates() const
InterpolatedHazardRateCurve(const DayCounter &, const std::vector< Handle< Quote > > &jumps=std::vector< Handle< Quote > >(), const std::vector< Date > &jumpDates=std::vector< Date >(), const Interpolator &interpolator=Interpolator(), const bool allowNegativeRates=false)
InterpolatedHazardRateCurve(const std::vector< Date > &dates, const std::vector< Rate > &hazardRates, const DayCounter &dayCounter, const Calendar &calendar, const Interpolator &interpolator, const bool allowNegativeRates=false)
Real integral(const CrossAssetModel &model, const E &e, const Real a, const Real b)