26#ifndef quantlib_piecewise_forward_spreaded_term_structure_hpp
27#define quantlib_piecewise_forward_spreaded_term_structure_hpp
48 template <
class Interpolator>
53 const std::vector<Date>& dates,
55 const Interpolator& factory = Interpolator());
92 const std::vector<Date>& dates,
95 : originalCurve_(
std::move(h)), spreads_(
std::move(spreads)), dates_(dates),
96 times_(dates.size()), spreadValues_(dates.size()), dc_(
std::move(dc)),
100 "spread and date vector have different sizes");
110 return originalCurve_->dayCounter();
115 return originalCurve_->calendar();
120 return originalCurve_->settlementDays();
126 return originalCurve_->referenceDate();
131 return std::min(originalCurve_->maxDate(), dates_.back());
137 Spread spreadPrimitive = calcSpreadPrimitive(
t);
139 return zeroRate + spreadPrimitive;
147 return forwardRate + spread;
153 if (
t <= times_.front()) {
154 return spreads_.front()->value();
155 }
else if (
t >= times_.back()) {
156 return spreads_.back()->value();
158 return interpolator_(
t,
true);
166 return calcSpread(0.0);
169 if (t <= this->times_.back()) {
170 integral = this->interpolator_.primitive(
t,
true);
172 integral = this->interpolator_.primitive(this->times_.back(),
true)
173 + this->spreads_.back()->value() * (
t - this->times_.back());
180 if (!originalCurve_.empty()) {
181 updateInterpolation();
195 for (
Size i = 0; i < dates_.size(); i++) {
196 times_[i] = timeFromReference(dates_[i]);
197 spreadValues_[i] = spreads_[i]->value();
199 interpolator_ = factory_.interpolate(times_.begin(),
201 spreadValues_.begin());
Forward-rate term structure
Shared handle to an observable.
Concrete interest rate class.
Term structure with an added vector of spreads on the instantaneous forward rate.
Real calcSpreadPrimitive(Time t) const
Calendar calendar() const override
the calendar used for reference and/or option date calculation
std::vector< Date > dates_
Rate zeroYieldImpl(Time) const override
returns the spreaded zero yield rate
const Date & referenceDate() const override
the date at which discount = 1.0 and/or variance = 0.0
std::vector< Time > times_
Handle< YieldTermStructure > originalCurve_
Natural settlementDays() const override
the settlementDays used for reference date calculation
Real calcSpread(Time t) const
DayCounter dayCounter() const override
the day counter used for date/time conversion
Rate forwardImpl(Time) const override
instantaneous forward-rate calculation
Date maxDate() const override
the latest date for which the curve can return values
std::vector< Spread > spreadValues_
void updateInterpolation()
std::vector< Handle< Quote > > spreads_
Interpolation interpolator_
base class for 1-D interpolations.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Forward-based yield term structure.
Frequency
Frequency of events.
@ NoFrequency
null frequency
Real Time
continuous quantity with 1-year units
unsigned QL_INTEGER Natural
positive integer
Real Spread
spreads on interest rates
std::size_t Size
size of a container
linear interpolation between discrete points
Compounding
Interest rate coumpounding rule.
purely virtual base class for market observables