20#ifndef quantlib_base_correl_structure_hpp
21#define quantlib_base_correl_structure_hpp
50 template<
class Interpolator2D_T>
64 const std::vector<Period>& tenors,
65 const std::vector<Real>& lossLevel,
112 bool extrapolate =
false)
const
130 template <
class I2D_T>
133 "first tranche tenor is negative (" <<
135 for (
Size i=1; i<nTrancheTenors_; ++i)
137 "non increasing tranche tenor: " <<
io::ordinal(i) <<
138 " is " << tenors_[i-1] <<
", " <<
io::ordinal(i+1) <<
139 " is " << tenors_[i]);
142 template <
class I2D_T>
145 "first loss level is negative (" <<
146 lossLevel_[0] <<
")");
148 "First loss level larger than 100% (" << lossLevel_[0] <<
")");
149 for (
Size i=1; i<nLosses_; ++i) {
152 " is " << lossLevel_[i-1] <<
", " <<
io::ordinal(i+1) <<
153 " is " << lossLevel_[i]);
155 "Loss level " << i <<
" larger than 100% (" << lossLevel_[i] <<
")");
159 template <
class I2D_T>
161 for (
Size i=0; i<nTrancheTenors_; ++i)
162 trancheTimes_[i] = timeFromReference(trancheDates_[i]);
165 template <
class I2D_T>
167 Size volsColumns)
const {
169 "mismatch between number of loss levels (" <<
170 nLosses_ <<
") and number of rows (" << volRows <<
171 ") in the correl matrix");
173 "mismatch between number of tranche tenors (" <<
174 nTrancheTenors_ <<
") and number of columns (" <<
175 volsColumns <<
") in the correl matrix");
178 template <
class I2D_T>
181 for (
Size i=0; i<correlHandles_.size(); ++i)
182 for (
Size j=0; j<correlHandles_.front().size(); ++j)
183 registerWith(correlHandles_[i][j]);
186 template <
class I2D_T>
192 template <
class I2D_T>
194 for (
Size i=0; i<correlHandles_.size(); ++i)
195 for (
Size j=0; j<correlHandles_.front().size(); ++j)
196 correlations_[i][j] = correlHandles_[i][j]->value();
bicubic spline interpolation between discrete points
bilinear interpolation between discrete points
void registerWithMarketData()
void checkTrancheTenors() const
void updateMatrix() const
std::vector< Real > lossLevel_
Size correlationSize() const override
The size of the squared correlation.
virtual void setupInterpolation()
std::vector< Period > tenors_
Real correlation(const Date &d, Real lossLevel, bool extrapolate=false) const
std::vector< std::vector< Handle< Quote > > > correlHandles_
Interpolation2D interpolation_
Real correlation(Time t, Real lossLevel, bool extrapolate=false) const
Date maxDate() const override
the latest date for which the curve can return values
void checkInputs(Size volRows, Size volsColumns) const
std::vector< Date > trancheDates_
std::vector< Time > trancheTimes_
Real ImplicitCorrelation(Real, Real)
Implicit correlation for the given loss interval.
BaseCorrelationTermStructure(Natural settlementDays, const Calendar &cal, BusinessDayConvention bdc, const std::vector< Period > &tenors, const std::vector< Real > &lossLevel, const std::vector< std::vector< Handle< Quote > > > &correls, const DayCounter &dc=DayCounter())
void initializeTrancheTimes() const
BusinessDayConvention businessDayConvention() const
Shared handle to an observable.
base class for 2-D interpolations.
Matrix used in linear algebra.
virtual Natural settlementDays() const
the settlementDays used for reference date calculation
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
virtual Calendar calendar() const
the calendar used for reference and/or option date calculation
Time timeFromReference(const Date &date) const
date/time conversion
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
BusinessDayConvention
Business Day conventions.
detail::ordinal_holder ordinal(Size)
outputs naturals as 1st, 2nd, 3rd...
Real Time
continuous quantity with 1-year units
unsigned QL_INTEGER Natural
positive integer
std::size_t Size
size of a container
purely virtual base class for market observables