1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2008 Roland Lichters
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<https://www.quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
/*! \file onefactorstudentcopula.hpp
\brief One-factor Student-t copula
*/
#ifndef quantlib_one_factor_student_copula_hpp
#define quantlib_one_factor_student_copula_hpp
#include <ql/experimental/credit/onefactorcopula.hpp>
#include <ql/math/distributions/studenttdistribution.hpp>
#include <ql/math/distributions/normaldistribution.hpp>
namespace QuantLib {
//! One-factor Double Student t-Copula
/*! The copula model
\f[ Y_i = a_i\,M+\sqrt{1-a_i^2}\:Z_i \f]
is specified here by setting the probability density functions
for \f$ Z_i \f$ (\f$ D_Z \f$) and \f$ M \f$ (\f$ D_M \f$) to
Student t-distributions with \f$ N_z \f$ and \f$ N_m \f$
degrees of freedom, respectively.
The variance of the Student t-distribution with \f$ \nu \f$
degrees of freedom is \f$ \nu / (\nu - 2) \f$. Since the
copula approach requires zero mean and unit variance
distributions, variables \f$ Z \f$ and \f$ M \f$ are scaled by
\f$ \sqrt{(N_z - 2) / N_z} \f$ and \f$ \sqrt{(N_m - 2) / N_m}, \f$
respectively.
\todo Improve performance/accuracy of the calculation of
inverse cumulative Y. Tabulate and store it for selected
correlations?
*/
class OneFactorStudentCopula : public OneFactorCopula {
public:
OneFactorStudentCopula (const Handle<Quote>& correlation,
int nz, int nm,
Real maximum = 10, Size integrationSteps = 200);
Real density(Real m) const override;
Real cumulativeZ(Real z) const override;
private:
//! Observer interface
void performCalculations() const override;
StudentDistribution density_; // density of M
CumulativeStudentDistribution cumulative_; // cumulated density of Z
int nz_; // degrees of freedom of Z
int nm_; // degrees of freedom of M
Real scaleM_; // scaling for m to ensure unit variance
Real scaleZ_; // scaling for z to ensure unit variance
// This function is used to update the table of the cumulative
// distribution of Y. It is invoked by performCalculations() when the
// correlation handle is amended.
Real cumulativeYintegral (Real y) const;
};
inline Real OneFactorStudentCopula::density (Real m) const {
return density_(m / scaleM_) / scaleM_;
}
inline Real OneFactorStudentCopula::cumulativeZ (Real z) const {
return cumulative_(z / scaleZ_);
}
//! One-factor Gaussian-Student t-Copula
/*! The copula model
\f[ Y_i = a_i\,M+\sqrt{1-a_i^2}\:Z_i \f]
is specified here by setting the probability density functions
for \f$ Z_i \f$ (\f$ D_Z \f$) to a Student t-distributions
with \f$ N_z \f$ degrees of freedom, and for \f$ M \f$
(\f$ D_M \f$) to a Gaussian.
The variance of the Student t-distribution with \f$ \nu \f$
degrees of freedom is \f$ \nu / (\nu - 2) \f$. Since the
copula approach requires zero mean and unit variance
distributions, \f$ Z \f$ is scaled by \f$ \sqrt{(N_z - 2) /
N_z}.\f$
\todo Improve performance/accuracy of the calculation of
inverse cumulative Y. Tabulate and store it for selected
correlations?
*/
class OneFactorGaussianStudentCopula : public OneFactorCopula {
public:
OneFactorGaussianStudentCopula (const Handle<Quote>& correlation,
int nz,
Real maximum = 10,
Size integrationSteps = 200);
Real density(Real m) const override;
Real cumulativeZ(Real z) const override;
private:
//! Observer interface
void performCalculations() const override;
NormalDistribution density_; // density of M
CumulativeStudentDistribution cumulative_; // cumulated density of Z
int nz_; // degrees of freedom of Z
Real scaleZ_; // scaling for z to ensure unit variance
// This function is used to update the table of the cumulative
// distribution of Y. It is invoked by performCalculations() when the
// correlation handle is amended.
Real cumulativeYintegral (Real y) const;
};
inline Real OneFactorGaussianStudentCopula::density (Real m) const {
return density_(m);
}
inline Real OneFactorGaussianStudentCopula::cumulativeZ (Real z) const {
return cumulative_(z / scaleZ_);
}
//! One-factor Student t - Gaussian Copula
/*! The copula model
\f[ Y_i = a_i\,M+\sqrt{1-a_i^2}\:Z_i \f]
is specified here by setting the probability density functions
for \f$ Z_i \f$ (\f$ D_Z \f$) to a Gaussian and for \f$ M \f$
(\f$ D_M \f$) to a Student t-distribution with \f$ N_m \f$
degrees of freedom.
The variance of the Student t-distribution with \f$ \nu \f$
degrees of freedom is \f$ \nu / (\nu - 2) \f$. Since the
copula approach requires zero mean and unit variance
distributions, \f$ M \f$ is scaled by \f$ \sqrt{(N_m - 2) /
N_m}. \f$
\todo Improve performance/accuracy of the calculation of
inverse cumulative Y. Tabulate and store it for selected
correlations?
*/
class OneFactorStudentGaussianCopula : public OneFactorCopula {
public:
OneFactorStudentGaussianCopula (const Handle<Quote>& correlation,
int nm,
Real maximum = 10,
Size integrationSteps = 200);
Real density(Real m) const override;
Real cumulativeZ(Real z) const override;
private:
//! Observer interface
void performCalculations() const override;
StudentDistribution density_; // density of M
CumulativeNormalDistribution cumulative_; // cumulated density of Z
int nm_; // degrees of freedom of M
Real scaleM_; // scaling for m to ensure unit variance
// This function is used to update the table of the cumulative
// distribution of Y. It is invoked by performCalculations() when the
// correlation handle is amended.
Real cumulativeYintegral (Real y) const;
};
inline Real OneFactorStudentGaussianCopula::density (Real m) const {
return density_(m / scaleM_) / scaleM_;
}
inline Real OneFactorStudentGaussianCopula::cumulativeZ (Real z) const {
return cumulative_(z);
}
}
#endif
|