39 QL_REQUIRE(longTermCorr<=1.0 && longTermCorr>=0.0,
40 "Long term correlation (" << longTermCorr <<
41 ") outside [0;1] interval");
44 ") must be greater than zero");
47 ") outside [0;1] interval");
50 Size nbRows = rateTimes.size()-1;
51 Matrix correlations(nbRows, nbRows, 0.0);
52 for (
Size i=0; i<nbRows; ++i) {
55 if (time<=rateTimes[i]) {
56 correlations[i][i] = 1.0;
57 for (
Size j=0; j<i; ++j) {
58 if (time<=rateTimes[j]) {
59 correlations[i][j] = correlations[j][i] =
60 longTermCorr + (1.0-longTermCorr) *
61 std::exp(-
beta*std::fabs(
62 std::pow(rateTimes[i]-time, gamma) -
63 std::pow(rateTimes[j]-time, gamma)
78 std::vector<Time> times)
79 : numberOfRates_(rateTimes.empty() ? 0 : rateTimes.size() - 1), longTermCorr_(longTermCorr),
80 beta_(
beta), gamma_(gamma), rateTimes_(rateTimes), times_(
std::move(times)) {
83 "Rate times must contain at least two values");
94 if (
close(gamma,1.0)) {
98 <<
" must be equal to (all) rate times (but the last) "
108 "last corr time " <<
times_.back() <<
109 "is after next-to-last rate time " <<
123 const std::vector<Time>&
128 const std::vector<Time>&
133 const std::vector<Matrix>&
const std::vector< Time > & rateTimes() const override
const std::vector< Time > & times() const override
std::vector< Time > times_
std::vector< Time > rateTimes_
ExponentialForwardCorrelation(const std::vector< Time > &rateTimes, Real longTermCorr=0.5, Real beta=0.2, Real gamma=1.0, std::vector< Time > times=std::vector< Time >())
const std::vector< Matrix > & correlations() const override
Size numberOfRates() const override
std::vector< Matrix > correlations_
Matrix used in linear algebra.
static std::vector< Matrix > evolvedMatrices(const Matrix &fwdCorrelation)
floating-point comparisons
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
exponential correlation matrix
detail::sequence_holder< typename Container::const_iterator > sequence(const Container &c)
output STL-compliant containers as space-separated sequences
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
Matrix exponentialCorrelations(const std::vector< Time > &rateTimes, Real longTermCorr, Real beta, Real gamma, Time time)
void checkIncreasingTimes(const std::vector< Time > ×)
check for strictly increasing times, first time greater than zero
bool close(const Quantity &m1, const Quantity &m2, Size n)