23#ifndef quantext_interpolated_correlation_curve_hpp
24#define quantext_interpolated_correlation_curve_hpp
26#include <ql/math/interpolations/backwardflatinterpolation.hpp>
27#include <ql/math/interpolations/linearinterpolation.hpp>
28#include <ql/patterns/lazyobject.hpp>
29#include <ql/termstructures/interpolatedcurve.hpp>
37template <
class Interpolator>
39 protected InterpolatedCurve<Interpolator>,
45 const DayCounter& dayCounter,
const Calendar& calendar,
46 const Interpolator& interpolator = Interpolator());
50 Date
maxDate()
const override {
return Date::maxDate(); }
51 Time
maxTime()
const override {
return QL_MAX_REAL; }
78 if (t <= this->times_[0]) {
79 return this->data_[0];
80 }
else if (t <= this->times_.back()) {
81 return this->interpolation_(t,
true);
84 return this->data_.back();
89 const std::vector<Handle<Quote> >& quotes,
90 const DayCounter& dayCounter,
const Calendar& calendar,
91 const T& interpolator)
92 : CorrelationTermStructure(0, calendar, dayCounter), InterpolatedCurve<T>(std::vector<Time>(), std::vector<Real>(),
96 QL_REQUIRE(times.size() > 1,
"too few times: " << times.size());
97 this->times_.resize(times.size());
98 this->times_[0] = times[0];
99 for (Size i = 1; i < times.size(); i++) {
100 QL_REQUIRE(times[i] > times[i - 1],
"times not sorted");
101 this->times_[i] = times[i];
104 QL_REQUIRE(this->
quotes_.size() == this->times_.size(),
105 "quotes/times count mismatch: " << this->quotes_.size() <<
" vs " << this->times_.size());
108 this->data_.resize(this->times_.size());
109 for (Size i = 0; i < this->times_.size(); i++)
110 this->data_[0] = 0.0;
112 this->interpolation_ =
113 this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->data_.begin());
114 this->interpolation_.update();
117 for (Size i = 0; i < this->
quotes_.size(); i++) {
118 QL_REQUIRE(std::fabs(this->
quotes_[i]->value()) <= 1.0,
119 "correlation not in range (-1.0,1.0): " << this->data_[i]);
121 registerWith(this->
quotes_[i]);
126 LazyObject::update();
127 CorrelationTermStructure::update();
132 for (Size i = 0; i < this->times_.size(); ++i)
133 this->data_[i] = quotes_[i]->value();
134 this->interpolation_ =
135 this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->data_.begin());
136 this->interpolation_.update();
Correlation term structure.
CorrelationTermStructure based on interpolation of correlations.
void performCalculations() const override
Real correlationImpl(Time t, Real) const override
Correlation calculation.
InterpolatedCorrelationCurve(const std::vector< Time > ×, const std::vector< Handle< Quote > > &correlations, const DayCounter &dayCounter, const Calendar &calendar, const Interpolator &interpolator=Interpolator())
Date maxDate() const override
std::vector< Handle< Quote > > quotes_
Time maxTime() const override
Term structure of correlations.
InterpolatedCorrelationCurve< BackwardFlat > BackwardFlatCorrelationCurve
InterpolatedCorrelationCurve< Linear > PiecewiseLinearCorrelationCurve