24#ifndef quantext_interpolated_discount_curve_hpp
25#define quantext_interpolated_discount_curve_hpp
27#include <boost/make_shared.hpp>
28#include <ql/termstructures/yieldtermstructure.hpp>
49 const Natural settlementDays,
const Calendar& cal,
const DayCounter& dc,
59 const Natural settlementDays,
const Calendar& cal,
const DayCounter& dc,
62 : YieldTermStructure(settlementDays, cal, dc),
times_(dates.size()),
interpolation_(interpolation),
64 for (Size i = 0; i < dates.size(); ++i)
65 times_[i] = timeFromReference(dates[i]);
71 void initalise(
const std::vector<Handle<Quote>>& quotes) {
72 QL_REQUIRE(
times_.size() > 1,
"at least two times required");
73 QL_REQUIRE(
times_[0] == 0.0,
"First time must be 0, got " <<
times_[0]);
74 QL_REQUIRE(
times_.size() == quotes.size(),
"size of time and quote vectors do not match");
75 for (Size i = 0; i < quotes.size(); ++i) {
76 quotes_.push_back(QuantLib::ext::make_shared<LogQuote>(quotes[i]));
78 for (Size i = 0; i <
times_.size() - 1; ++i)
84 Date
maxDate()
const override {
return Date::maxDate(); }
90 Real tMax = this->
times_.back();
91 Real dMax = std::exp(
quotes_.back()->value());
92 return std::pow(dMax, t / tMax);
94 std::vector<Time>::const_iterator it = std::upper_bound(
times_.begin(),
times_.end(), t);
95 Size i = std::min<Size>(it -
times_.begin(),
times_.size() - 1);
99 Real value = (1.0 - weight) *
quotes_[i]->value() + weight *
quotes_[i - 1]->value();
104 return ::exp(t * value);
111 std::vector<QuantLib::ext::shared_ptr<Quote>>
quotes_;
InterpolatedDiscountCurve based on loglinear interpolation of DiscountFactors.
DiscountFactor discountImpl(Time t) const override
InterpolatedDiscountCurve(const std::vector< Time > ×, const std::vector< Handle< Quote > > "es, const Natural settlementDays, const Calendar &cal, const DayCounter &dc, const Interpolation interpolation=Interpolation::logLinear, const Extrapolation extrapolation=Extrapolation::flatFwd)
default constructor
void initalise(const std::vector< Handle< Quote > > "es)
std::vector< Time > times_
Interpolation interpolation_
std::vector< QuantLib::ext::shared_ptr< Quote > > quotes_
std::vector< Time > timeDiffs_
Extrapolation extrapolation_
Date maxDate() const override
InterpolatedDiscountCurve(const std::vector< Date > &dates, const std::vector< Handle< Quote > > "es, const Natural settlementDays, const Calendar &cal, const DayCounter &dc, const Interpolation interpolation=Interpolation::logLinear, const Extrapolation extrapolation=Extrapolation::flatFwd)
constructor that takes a vector of dates
stores log of quote for log-linear interpolation