25#include <boost/optional/optional.hpp>
26#include <ql/math/interpolations/bilinearinterpolation.hpp>
27#include <ql/patterns/lazyobject.hpp>
28#include <ql/quote.hpp>
29#include <ql/time/dategenerationrule.hpp>
42 const std::vector<Period>& tenors,
const std::vector<double>&
detachmentPoints,
43 const DayCounter& dc = DayCounter(),
const Date&
startDate = Date(),
44 boost::optional<DateGeneration::Rule>
rule = boost::none);
47 const std::vector<Period>& tenors,
const std::vector<double>&
detachmentPoints,
48 const DayCounter& dc = DayCounter(),
const Date&
startDate = Date(),
49 boost::optional<DateGeneration::Rule>
rule = boost::none);
72 boost::optional<DateGeneration::Rule>
rule()
const {
return rule_; }
75 BusinessDayConvention
bdc_;
77 boost::optional<DateGeneration::Rule>
rule_;
84 virtual void checkRange(Time t, Real strike,
bool extrapolate)
const override;
92template <
class Interpolator>
96 const std::vector<Period>& tenors,
98 const std::vector<std::vector<Handle<Quote>>>& baseCorrelations,
99 const DayCounter& dc = DayCounter(),
const Date&
startDate = Date(),
100 boost::optional<DateGeneration::Rule>
rule = boost::none,
101 Interpolator interpolator = Interpolator())
107 for (
const auto& row : this->
quotes_) {
108 QL_REQUIRE(row.size() ==
tenors_.size(),
109 "Mismatch between number of detachment points and quotes");
113 this->
interpolator_.interpolate(this->
times_.begin(), this->times_.end(), this->detachmentPoints_.begin(),
114 this->detachmentPoints_.end(), this->data_);
118 for (Size i = 0; i < this->quotes_.size(); i++) {
119 for (Size j = 0; j < this->quotes_[i].size(); ++j) {
121 QL_REQUIRE(this->quotes_[i][j]->value() >= 0.0 && this->quotes_[i][j]->value() <= 1.0,
122 "correlation not in range (0.0,1.0): " << this->quotes_[i][j]->value());
124 registerWith(this->quotes_[i][j]);
139 std::vector<std::vector<Handle<Quote>>>
quotes_;
158 for (Size i = 0; i < this->detachmentPoints_.size(); ++i)
159 for (Size j = 0; j < this->times_.size(); ++j)
160 this->data_[i][j] = quotes_[i][j]->value();
161 this->interpolation_ =
162 this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->detachmentPoints_.begin(),
163 this->detachmentPoints_.end(), this->data_);
164 this->interpolation_.update();
168 LazyObject::update();
169 BaseCorrelationTermStructure::update();
175 return this->interpolation_(t, detachmentPoint,
true);
void initializeDatesAndTimes() const
std::vector< double > times() const
std::vector< Period > tenors_
virtual double maxDetachmentPoint() const
std::vector< Date > dates_
virtual void checkRange(Time t, Real strike, bool extrapolate) const override
Extra time range check for minimum time, then calls TermStructure::checkRange.
std::vector< double > detachmentPoints() const
boost::optional< DateGeneration::Rule > rule_
virtual Time maxTime() const override
std::vector< double > detachmentPoints_
virtual ~BaseCorrelationTermStructure()=default
std::vector< Date > dates() const
BusinessDayConvention bdc_
BaseCorrelationTermStructure(const Date &referenceDate, const Calendar &cal, BusinessDayConvention bdc, const std::vector< Period > &tenors, const std::vector< double > &detachmentPoints, const DayCounter &dc=DayCounter(), const Date &startDate=Date(), boost::optional< DateGeneration::Rule > rule=boost::none)
boost::optional< DateGeneration::Rule > rule() const
BaseCorrelationTermStructure()
virtual double minDetachmentPoint() const
virtual Time minTime() const override
The minimum time for which the curve can return values.
BusinessDayConvention businessDayConvention() const
virtual Date maxDate() const override
std::vector< double > times_
Correlation term structure.
void performCalculations() const override
Interpolation2D interpolation_
Interpolator interpolator_
Real correlationImpl(Time t, Real detachmentPoint) const override
Correlation calculation.
std::vector< std::vector< Handle< Quote > > > quotes_
InterpolatedBaseCorrelationTermStructure(Natural settlementDays, const Calendar &cal, BusinessDayConvention bdc, const std::vector< Period > &tenors, const std::vector< Real > &detachmentPoints, const std::vector< std::vector< Handle< Quote > > > &baseCorrelations, const DayCounter &dc=DayCounter(), const Date &startDate=Date(), boost::optional< DateGeneration::Rule > rule=boost::none, Interpolator interpolator=Interpolator())
Term structure of correlations.
InterpolatedBaseCorrelationTermStructure< QuantLib::Bilinear > BilinearBaseCorrelationCurve