26#ifndef quantlib_zero_curve_hpp
27#define quantlib_zero_curve_hpp
41 template <
class Interpolator>
47 const std::vector<Date>&
dates,
48 const std::vector<Rate>& yields,
53 const Interpolator& interpolator = {},
57 const std::vector<Date>&
dates,
58 const std::vector<Rate>& yields,
61 const Interpolator& interpolator,
65 const std::vector<Date>&
dates,
66 const std::vector<Rate>& yields,
68 const Interpolator& interpolator,
77 const std::vector<Time>&
times()
const;
78 const std::vector<Date>&
dates()
const;
79 const std::vector<Real>&
data()
const;
80 const std::vector<Rate>&
zeroRates()
const;
81 std::vector<std::pair<Date, Real> >
nodes()
const;
87 const Interpolator& interpolator = {});
93 const Interpolator& interpolator = {});
100 const Interpolator& interpolator = {});
120 if (this->maxDate_ !=
Date())
121 return this->maxDate_;
122 return dates_.back();
136 inline const std::vector<Real>&
142 inline const std::vector<Rate>&
148 inline std::vector<std::pair<Date, Real> >
150 std::vector<std::pair<Date, Real> >
results(dates_.size());
151 for (
Size i=0; i<dates_.size(); ++i)
152 results[i] = std::make_pair(dates_[i], this->data_[i]);
162 if (t <= this->times_.back())
163 return this->interpolation_(
t,
true);
166 Time tMax = this->times_.back();
167 Rate zMax = this->data_.back();
168 Rate instFwdMax = zMax + tMax * this->interpolation_.derivative(tMax);
169 return (zMax * tMax + instFwdMax * (
t-tMax)) /
t;
174 const DayCounter& dayCounter,
175 const T& interpolator)
176 : ZeroYieldStructure(dayCounter), 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 : ZeroYieldStructure(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 : ZeroYieldStructure(settlementDays, calendar, dayCounter, jumps, jumpDates),
197 InterpolatedCurve<
T>(interpolator) {}
201 const std::vector<Date>& dates,
202 const std::vector<Rate>& yields,
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,
210 : ZeroYieldStructure(dates.at(0), calendar, dayCounter, jumps, jumpDates),
211 InterpolatedCurve<
T>(
std::vector<
Time>(), yields, interpolator),
219 const std::vector<Date>& dates,
220 const std::vector<Rate>& yields,
221 const DayCounter& dayCounter,
222 const Calendar& calendar,
223 const T& interpolator,
226 : ZeroYieldStructure(dates.at(0), calendar, dayCounter),
227 InterpolatedCurve<
T>(
std::vector<
Time>(), yields, interpolator),
235 const std::vector<Date>& dates,
236 const std::vector<Rate>& yields,
237 const DayCounter& dayCounter,
238 const T& interpolator,
241 : ZeroYieldStructure(dates.at(0), Calendar(), dayCounter),
242 InterpolatedCurve<
T>(
std::vector<
Time>(), yields, interpolator),
254 QL_REQUIRE(dates_.size() >= T::requiredPoints,
255 "not enough input dates given");
256 QL_REQUIRE(this->data_.size() == dates_.size(),
257 "dates/data count mismatch");
259 this->setupTimes(dates_, dates_[0], dayCounter());
267 InterestRate r(this->data_[0], dayCounter(), compounding, frequency);
270 for (
Size i=1; i<dates_.size(); ++i) {
271 InterestRate r(this->data_[i], dayCounter(), compounding, frequency);
276 this->setupInterpolation();
277 this->interpolation_.update();
Shared handle to an observable.
Concrete interest rate class.
Helper class to build interpolated term structures.
YieldTermStructure based on interpolation of zero rates.
InterpolatedZeroCurve(const std::vector< Date > &dates, const std::vector< Rate > &yields, const DayCounter &dayCounter, const Calendar &calendar, const Interpolator &interpolator, Compounding compounding=Continuous, Frequency frequency=Annual)
InterpolatedZeroCurve(const std::vector< Date > &dates, const std::vector< Rate > &yields, const DayCounter &dayCounter, const Interpolator &interpolator, Compounding compounding=Continuous, Frequency frequency=Annual)
Rate zeroYieldImpl(Time t) const override
zero-yield calculation
std::vector< Date > dates_
const std::vector< Date > & dates() const
void initialize(const Compounding &compounding, const Frequency &frequency)
InterpolatedZeroCurve(Natural settlementDays, const Calendar &, const DayCounter &, const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
const std::vector< Rate > & zeroRates() const
const std::vector< Real > & data() const
InterpolatedZeroCurve(const DayCounter &, const Interpolator &interpolator={})
std::vector< std::pair< Date, Real > > nodes() const
InterpolatedZeroCurve(const Date &referenceDate, const DayCounter &, const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={})
const std::vector< Time > & times() const
Date maxDate() const override
the latest date for which the curve can return values
InterpolatedZeroCurve(const std::vector< Date > &dates, const std::vector< Rate > &yields, const DayCounter &dayCounter, const Calendar &calendar=Calendar(), const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={}, const Interpolator &interpolator={}, Compounding compounding=Continuous, Frequency frequency=Annual)
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
const std::vector< Date > & jumpDates() const
Zero-yield term structure.
floating-point comparisons
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Frequency
Frequency of events.
@ NoFrequency
null frequency
Real Time
continuous quantity with 1-year units
unsigned QL_INTEGER Natural
positive integer
std::size_t Size
size of a container
InterpolatedZeroCurve< Linear > ZeroCurve
Term structure based on linear interpolation of zero yields.
Helper class to build interpolated term structures.
linear interpolation between discrete points
Compounding
Interest rate coumpounding rule.
ext::shared_ptr< YieldTermStructure > r
Zero-yield based term structure.