27#ifndef quantlib_discount_curve_hpp
28#define quantlib_discount_curve_hpp
40 template <
class Interpolator>
46 const std::vector<Date>&
dates,
47 const std::vector<DiscountFactor>& dfs,
52 const Interpolator& interpolator = {});
54 const std::vector<Date>&
dates,
55 const std::vector<DiscountFactor>& dfs,
58 const Interpolator& interpolator);
60 const std::vector<Date>&
dates,
61 const std::vector<DiscountFactor>& dfs,
63 const Interpolator& interpolator);
70 const std::vector<Time>&
times()
const;
71 const std::vector<Date>&
dates()
const;
72 const std::vector<Real>&
data()
const;
73 const std::vector<DiscountFactor>&
discounts()
const;
74 std::vector<std::pair<Date, Real> >
nodes()
const;
80 const Interpolator& interpolator = {});
86 const Interpolator& interpolator = {});
93 const Interpolator& interpolator = {});
117 if (this->maxDate_ !=
Date())
118 return this->maxDate_;
119 return dates_.back();
123 inline const std::vector<Time>&
129 inline const std::vector<Date>&
135 inline const std::vector<Real>&
141 inline const std::vector<DiscountFactor>&
147 inline std::vector<std::pair<Date, Real> >
149 std::vector<std::pair<Date, Real> >
results(dates_.size());
150 for (
Size i=0; i<dates_.size(); ++i)
151 results[i] = std::make_pair(dates_[i], this->data_[i]);
161 if (t <= this->times_.back())
162 return this->interpolation_(
t,
true);
165 Time tMax = this->times_.back();
167 Rate instFwdMax = - this->interpolation_.derivative(tMax) / dMax;
168 return dMax * std::exp(- instFwdMax * (
t-tMax));
173 const DayCounter& dayCounter,
174 const T& interpolator)
175 : YieldTermStructure(dayCounter),
176 InterpolatedCurve<
T>(interpolator) {}
180 const Date& referenceDate,
181 const DayCounter& dayCounter,
182 const std::vector<Handle<Quote> >& jumps,
183 const std::vector<Date>& jumpDates,
184 const T& interpolator)
185 : YieldTermStructure(referenceDate, Calendar(), dayCounter, jumps, jumpDates),
186 InterpolatedCurve<
T>(interpolator) {}
191 const Calendar& calendar,
192 const DayCounter& dayCounter,
193 const std::vector<Handle<Quote> >& jumps,
194 const std::vector<Date>& jumpDates,
195 const T& interpolator)
196 : YieldTermStructure(settlementDays, calendar, dayCounter, jumps, jumpDates),
197 InterpolatedCurve<
T>(interpolator) {}
201 const std::vector<Date>& dates,
202 const std::vector<DiscountFactor>& discounts,
203 const DayCounter& dayCounter,
204 const Calendar& calendar,
205 const std::vector<Handle<Quote> >& jumps,
206 const std::vector<Date>& jumpDates,
207 const T& interpolator)
208 : YieldTermStructure(dates.at(0), calendar, dayCounter, jumps, jumpDates),
209 InterpolatedCurve<
T>(
std::vector<
Time>(), discounts, interpolator),
217 const std::vector<Date>& dates,
218 const std::vector<DiscountFactor>& discounts,
219 const DayCounter& dayCounter,
220 const Calendar& calendar,
221 const T& interpolator)
222 : YieldTermStructure(dates.at(0), calendar, dayCounter),
223 InterpolatedCurve<
T>(
std::vector<
Time>(), discounts, interpolator),
231 const std::vector<Date>& dates,
232 const std::vector<DiscountFactor>& discounts,
233 const DayCounter& dayCounter,
234 const T& interpolator)
235 : YieldTermStructure(dates.at(0), Calendar(), dayCounter),
236 InterpolatedCurve<
T>(
std::vector<
Time>(), discounts, interpolator),
247 QL_REQUIRE(dates_.size() >= T::requiredPoints,
248 "not enough input dates given");
249 QL_REQUIRE(this->data_.size() == dates_.size(),
250 "dates/data count mismatch");
252 "the first discount must be == 1.0 "
253 "to flag the corresponding date as reference date");
254 for (
Size i=1; i<dates_.size(); ++i) {
255 QL_REQUIRE(this->data_[i] > 0.0,
"negative discount");
258 this->setupTimes(dates_, dates_[0], dayCounter());
259 this->setupInterpolation();
260 this->interpolation_.update();
Shared handle to an observable.
Helper class to build interpolated term structures.
YieldTermStructure based on interpolation of discount factors.
std::vector< Date > dates_
const std::vector< DiscountFactor > & discounts() const
const std::vector< Date > & dates() const
InterpolatedDiscountCurve(const std::vector< Date > &dates, const std::vector< DiscountFactor > &dfs, const DayCounter &dayCounter, const Calendar &cal=Calendar(), const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
InterpolatedDiscountCurve(const std::vector< Date > &dates, const std::vector< DiscountFactor > &dfs, const DayCounter &dayCounter, const Interpolator &interpolator)
InterpolatedDiscountCurve(const std::vector< Date > &dates, const std::vector< DiscountFactor > &dfs, const DayCounter &dayCounter, const Calendar &calendar, const Interpolator &interpolator)
const std::vector< Real > & data() const
InterpolatedDiscountCurve(const Date &referenceDate, const DayCounter &, const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
std::vector< std::pair< Date, Real > > nodes() const
const std::vector< Time > & times() const
DiscountFactor discountImpl(Time) const override
discount factor calculation
Date maxDate() const override
the latest date for which the curve can return values
InterpolatedDiscountCurve(const DayCounter &, const Interpolator &interpolator={})
InterpolatedDiscountCurve(Natural settlementDays, const Calendar &, 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
Interest-rate term structure.
const std::vector< Date > & jumpDates() const
floating-point comparisons
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
unsigned QL_INTEGER Natural
positive integer
std::size_t Size
size of a container
InterpolatedDiscountCurve< LogLinear > DiscountCurve
Term structure based on log-linear interpolation of discount factors.
Helper class to build interpolated term structures.
log-linear and log-cubic interpolation between discrete points
Interest-rate term structure.