26#ifndef quantlib_interpolated_default_density_curve_hpp
27#define quantlib_interpolated_default_density_curve_hpp
37 template <
class Interpolator>
43 const std::vector<Date>&
dates,
44 const std::vector<Real>& densities,
49 const Interpolator& interpolator = {});
51 const std::vector<Date>&
dates,
52 const std::vector<Real>& densities,
55 const Interpolator& interpolator);
57 const std::vector<Date>&
dates,
58 const std::vector<Real>& densities,
60 const Interpolator& interpolator);
67 const std::vector<Time>&
times()
const;
68 const std::vector<Date>&
dates()
const;
69 const std::vector<Real>&
data()
const;
71 std::vector<std::pair<Date, Real> >
nodes()
const;
78 const Interpolator& interpolator = {});
84 const Interpolator& interpolator = {});
91 const Interpolator& interpolator = {});
106 return dates_.back();
110 inline const std::vector<Time>&
116 inline const std::vector<Date>&
122 inline const std::vector<Real>&
128 inline const std::vector<Real>&
134 inline std::vector<std::pair<Date, Real> >
136 std::vector<std::pair<Date, Real> >
results(dates_.size());
137 for (
Size i=0; i<dates_.size(); ++i)
138 results[i] = std::make_pair(dates_[i], this->data_[i]);
148 if (t <= this->times_.back())
149 return this->interpolation_(
t,
true);
152 return this->data_.back();
162 if (t <= this->times_.back()) {
163 integral = this->interpolation_.primitive(
t,
true);
166 integral = this->interpolation_.primitive(this->times_.back(),
true)
167 + this->data_.back()*(
t - this->times_.back());
171 return std::max<Real>(P, 0.0);
176 const DayCounter& dayCounter,
177 const std::vector<Handle<Quote> >& jumps,
178 const std::vector<Date>& jumpDates,
179 const T& interpolator)
180 : DefaultDensityStructure(dayCounter, jumps, jumpDates),
181 InterpolatedCurve<
T>(interpolator) {}
185 const Date& referenceDate,
186 const DayCounter& dayCounter,
187 const std::vector<Handle<Quote> >& jumps,
188 const std::vector<Date>& jumpDates,
189 const T& interpolator)
190 : DefaultDensityStructure(referenceDate, Calendar(), dayCounter, jumps, jumpDates),
191 InterpolatedCurve<
T>(interpolator) {}
196 const Calendar& calendar,
197 const DayCounter& dayCounter,
198 const std::vector<Handle<Quote> >& jumps,
199 const std::vector<Date>& jumpDates,
200 const T& interpolator)
201 : DefaultDensityStructure(settlementDays, calendar, dayCounter, jumps, jumpDates),
202 InterpolatedCurve<
T>(interpolator) {}
206 const std::vector<Date>& dates,
207 const std::vector<Real>& densities,
208 const DayCounter& dayCounter,
209 const Calendar& calendar,
210 const std::vector<Handle<Quote> >& jumps,
211 const std::vector<Date>& jumpDates,
212 const T& interpolator)
213 : DefaultDensityStructure(dates.at(0), calendar, dayCounter, jumps, jumpDates),
214 InterpolatedCurve<
T>(
std::vector<
Time>(), densities, interpolator),
222 const std::vector<Date>& dates,
223 const std::vector<Real>& densities,
224 const DayCounter& dayCounter,
225 const Calendar& calendar,
226 const T& interpolator)
227 : DefaultDensityStructure(dates.at(0), calendar, dayCounter),
228 InterpolatedCurve<
T>(
std::vector<
Time>(), densities, interpolator),
236 const std::vector<Date>& dates,
237 const std::vector<Real>& densities,
238 const DayCounter& dayCounter,
239 const T& interpolator)
240 : DefaultDensityStructure(dates.at(0), Calendar(), dayCounter),
241 InterpolatedCurve<
T>(
std::vector<
Time>(), densities, interpolator),
253 QL_REQUIRE(dates_.size() >= T::requiredPoints,
254 "not enough input dates given");
255 QL_REQUIRE(this->data_.size() == dates_.size(),
256 "dates/data count mismatch");
258 for (
Size i=0; i<dates_.size(); ++i) {
259 QL_REQUIRE(this->data_[i] >= 0.0,
"negative default density");
262 this->setupTimes(dates_, dates_[0], dayCounter);
263 this->setupInterpolation();
264 this->interpolation_.update();
Default-density term structure.
const std::vector< Date > & jumpDates() const
Shared handle to an observable.
Helper class to build interpolated term structures.
DefaultProbabilityTermStructure based on interpolation of default densities.
Real defaultDensityImpl(Time) const override
default density calculation
const std::vector< Real > & defaultDensities() const
std::vector< Date > dates_
InterpolatedDefaultDensityCurve(const Date &referenceDate, const DayCounter &, const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
const std::vector< Date > & dates() const
InterpolatedDefaultDensityCurve(const std::vector< Date > &dates, const std::vector< Real > &densities, const DayCounter &dayCounter, const Calendar &calendar=Calendar(), const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
const std::vector< Real > & data() const
void initialize(const DayCounter &dayCounter)
std::vector< std::pair< Date, Real > > nodes() const
InterpolatedDefaultDensityCurve(Natural settlementDays, const Calendar &, const DayCounter &, const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
const std::vector< Time > & times() const
Probability survivalProbabilityImpl(Time) const override
survival probability calculation
Date maxDate() const override
the latest date for which the curve can return values
InterpolatedDefaultDensityCurve(const std::vector< Date > &dates, const std::vector< Real > &densities, const DayCounter &dayCounter, const Calendar &calendar, const Interpolator &interpolator)
InterpolatedDefaultDensityCurve(const std::vector< Date > &dates, const std::vector< Real > &densities, const DayCounter &dayCounter, const Interpolator &interpolator)
InterpolatedDefaultDensityCurve(const DayCounter &, const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
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
default-density term structure
#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.