29 std::vector<Real> defaultProbability,
30 std::vector<Size> sector,
31 std::vector<Real> relativeDefaultVariance,
34 : exposure_(
std::move(exposure)),
pd_(
std::move(defaultProbability)),
35 sector_(
std::move(sector)), relativeDefaultVariance_(
std::move(relativeDefaultVariance)),
43 <<
") must be equal to number of pds ("
44 <<
pd_.size() <<
")");
46 "number of exposures ("
48 <<
") must be equal to number of exposure sectors ("
54 <<
") must be a square matrix");
57 "number of relative default variances ("
59 <<
" must be equal to number of sectors (" <<
n_ <<
")");
64 for (
Size i = 0; i <
m_; ++i) {
66 << i <<
" is negative ("
71 <<
") is out of range 0..."
96 Real p2 = sum >= p ? sum : 1.0;
100 return l1 + (p - p1) / (p2 - p1) * (l2 - l1);
105 std::vector<Real> sectorPdSum_, sectorSpecTerms_;
107 sectorPdSum_ = std::vector<Real>(
n_, 0.0);
110 sectorSpecTerms_ = std::vector<Real>(
n_, 0.0);
114 std::vector<Real> pdAdj(
m_, 0.0);
118 unsigned long maxNu_ = 0;
122 std::map<unsigned long, Real, std::less<> > epsNuC_;
124 std::map<unsigned long, Real, std::less<> >::iterator iter;
126 for (
Size k = 0; k <
m_; ++k) {
127 auto exUnit = (
unsigned long)(std::floor(0.5 +
exposure_[k] /
unit_));
135 Real el = exUnit * pdAdj[k];
137 iter = epsNuC_.find(exUnit);
138 if (iter == epsNuC_.end()) {
139 epsNuC_.insert(std::pair<unsigned long, Real>(exUnit, el));
141 (*iter).second += el;
150 for (
Size k = 0; k <
m_; ++k) {
157 for (
Size i = 0; i <
n_; ++i) {
162 for (
Size j = 0; j <
n_; ++j) {
164 sectorSpecTerms_[i] +=
176 for (
Size i = 0; i <
n_; ++i) {
180 for (
Size j = 0; j <
n_; ++j) {
191 for (
Size k = 0; k <
m_; ++k) {
197 for (
Size i = 0; i <
n_; ++i)
202 for (
Size k = 0; k <
m_; ++k) {
209 Real sigmaC_ = pdSum_ * sqrt(matchUl_ / (
el_ *
el_));
210 Real alphaC_ = pdSum_ * pdSum_ / (sigmaC_ * sigmaC_);
211 Real betaC_ = sigmaC_ * sigmaC_ / pdSum_;
212 Real pC_ = betaC_ / (1.0 + betaC_);
217 loss_.push_back(std::pow(1.0 - pC_, alphaC_));
223 for (
unsigned long j = 0;
224 j <= std::min<unsigned long>(maxNu_ - 1,
n); ++j) {
225 iter = epsNuC_.find(j + 1);
226 if (iter != epsNuC_.end()) {
227 res += (*iter).second *
loss_[
n - j] * alphaC_;
229 res += (*iter).second / ((
Real)(j + 1)) *
233 loss_.push_back(res * pC_ / (pdSum_ * ((
Real)(
n + 1))));
std::vector< Real > loss_
unsigned long upperIndex_
const std::vector< Real > exposure_
CreditRiskPlus(std::vector< Real > exposure, std::vector< Real > defaultProbability, std::vector< Size > sector, std::vector< Real > relativeDefaultVariance, Matrix correlation, Real unit)
std::vector< Real > sectorEl_
const Matrix correlation_
std::vector< Real > sectorExposure_
const std::vector< Real > relativeDefaultVariance_
Real lossQuantile(Real p)
const std::vector< Real > pd_
const std::vector< Size > sector_
std::vector< Real > marginalLoss_
std::vector< Real > sectorUl_
Matrix used in linear algebra.
Extended CreditRisk+ Model.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
std::size_t Size
size of a container