21#include <ql/math/interpolations/loginterpolation.hpp>
26 const std::vector<Time>& times,
const std::vector<Handle<Quote>>& quotes,
28 : YieldTermStructure(referenceCurve->dayCounter()), referenceCurve_(referenceCurve), times_(times), quotes_(quotes),
29 interpolation_(interpolation), extrapolation_(extrapolation), data_(times_.size(), 1.0) {
30 QL_REQUIRE(
times_.size() > 1,
"SpreadedDiscountCurve: at least two times required");
31 QL_REQUIRE(
times_.size() == quotes.size(),
"SpreadedDiscountCurve: size of time and quote vectors do not match");
32 QL_REQUIRE(
times_[0] == 0.0,
"SpreadedDiscountCurve: first time must be 0, got " <<
times_[0]);
33 for (Size i = 0; i < quotes.size(); ++i) {
49 TermStructure::update();
59 for (Size i = 0; i <
times_.size(); ++i) {
60 QL_REQUIRE(!
quotes_[i].empty(),
"SpreadedDiscountCurve: quote at index " << i <<
" is empty");
62 QL_REQUIRE(
data_[i] > 0,
"SpreadedDiscountCurve: invalid value " <<
data_[i] <<
" at index " << i);
65 for (Size i = 0; i <
times_.size(); ++i) {
66 data_[i] = -std::log(
data_[std::max<Size>(i, 1)]) /
times_[std::max<Size>(i, 1)];
74 Time tMax = this->
times_.back();
77 if (t <= this->
times_.back()) {
78 Real tmp = (*dataInterpolation_)(t,
true);
85 Rate instFwdMax = -(*dataInterpolation_).derivative(tMax) / dMax;
86 return referenceCurve_->discount(t) * dMax * std::exp(-instFwdMax * (t - tMax));
void performCalculations() const override
Calendar calendar() const override
Handle< YieldTermStructure > referenceCurve_
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
std::vector< Handle< Quote > > quotes_
SpreadedDiscountCurve(const Handle< YieldTermStructure > &referenceCurve, const std::vector< Time > ×, const std::vector< Handle< Quote > > "es, const Interpolation interpolation=Interpolation::logLinear, const Extrapolation extrapolation=Extrapolation::flatFwd)
times should be consistent with reference ts day counter
QuantLib::ext::shared_ptr< QuantLib::Interpolation > dataInterpolation_
std::vector< Real > data_
spreaded discount term structure