24#ifndef quantext_interpolated_discount_curve_2_hpp
25#define quantext_interpolated_discount_curve_2_hpp
27#include <ql/math/interpolations/loginterpolation.hpp>
28#include <ql/patterns/lazyobject.hpp>
29#include <ql/termstructures/yieldtermstructure.hpp>
30#include <ql/time/calendars/nullcalendar.hpp>
32#include <boost/make_shared.hpp>
56 for (Size i = 0; i < quotes.size(); ++i) {
57 QL_REQUIRE(
times_.size() > 1,
"at least two times required");
58 QL_REQUIRE(
times_.size() == quotes.size(),
"size of time and quote vectors do not match");
59 QL_REQUIRE(
times_[0] == 0.0,
"First time must be 0, got " <<
times_[0]);
60 QL_REQUIRE(!quotes[i].empty(),
"quote at index " << i <<
" is empty");
65 QuantLib::ext::make_shared<LogLinearInterpolation>(
times_.begin(),
times_.end(),
data_.begin());
69 registerWith(Settings::instance().evaluationDate());
77 for (Size i = 0; i < dates.size(); ++i)
79 for (Size i = 0; i < quotes.size(); ++i) {
80 QL_REQUIRE(
times_.size() > 1,
"at least two times required");
81 QL_REQUIRE(
times_.size() == quotes.size(),
"size of time and quote vectors do not match");
82 QL_REQUIRE(
times_[0] == 0.0,
"First time must be 0, got " <<
times_[0]);
83 QL_REQUIRE(!quotes[i].empty(),
"quote at index " << i <<
" is empty");
88 QuantLib::ext::make_shared<LogLinearInterpolation>(
times_.begin(),
times_.end(),
data_.begin());
92 registerWith(Settings::instance().evaluationDate());
96 Date
maxDate()
const override {
return Date::maxDate(); }
99 TermStructure::update();
106 Calendar
calendar()
const override {
return NullCalendar(); }
111 today_ = Settings::instance().evaluationDate();
112 for (Size i = 0; i <
times_.size(); ++i) {
114 QL_REQUIRE(
data_[i] > 0,
"InterpolatedDiscountCurve2: invalid value " <<
data_[i] <<
" at index " << i);
117 for (Size i = 0; i <
times_.size(); ++i) {
118 data_[i] = -std::log(
data_[std::max<Size>(i, 1)]) /
times_[std::max<Size>(i, 1)];
126 if (t <= this->
times_.back()) {
127 Real tmp = (*dataInterpolation_)(t,
true);
131 return std::exp(-tmp * t);
133 Time tMax = this->
times_.back();
134 DiscountFactor dMax =
137 Rate instFwdMax = -(*dataInterpolation_).derivative(tMax) / dMax;
138 return dMax * std::exp(-instFwdMax * (t - tMax));
140 return std::pow(dMax, t / tMax);
InterpolatedDiscountCurve2 as in QuantLib, but with floating discount quotes and floating reference d...
void performCalculations() const override
Calendar calendar() const override
DiscountFactor discountImpl(Time t) const override
const Date & referenceDate() const override
std::vector< Time > times_
Interpolation interpolation_
Extrapolation extrapolation_
Natural settlementDays() const override
Date maxDate() const override
InterpolatedDiscountCurve2(const std::vector< Time > ×, const std::vector< Handle< Quote > > "es, const DayCounter &dc, const Interpolation interpolation=Interpolation::logLinear, const Extrapolation extrapolation=Extrapolation::flatFwd)
times based constructor, note that times should be consistent with day counter dc passed
std::vector< Handle< Quote > > quotes_
InterpolatedDiscountCurve2(const std::vector< Date > &dates, const std::vector< Handle< Quote > > "es, const DayCounter &dc, const Interpolation interpolation=Interpolation::logLinear, const Extrapolation extrapolation=Extrapolation::flatFwd)
date based constructor
QuantLib::ext::shared_ptr< QuantLib::Interpolation > dataInterpolation_
std::vector< Real > data_