Coverage Report

Created: 2025-10-14 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/experimental/risk/creditriskplus.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
  Copyright (C) 2013 Peter Caspers
5
6
  This file is part of QuantLib, a free-software/open-source library
7
  for financial quantitative analysts and developers - http://quantlib.org/
8
9
  QuantLib is free software: you can redistribute it and/or modify it
10
  under the terms of the QuantLib license.  You should have received a
11
  copy of the license along with this program; if not, please email
12
  <quantlib-dev@lists.sf.net>. The license is also available online at
13
  <https://www.quantlib.org/license.shtml>.
14
15
  This program is distributed in the hope that it will be useful, but WITHOUT
16
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
  FOR A PARTICULAR PURPOSE.  See the license for more details.
18
*/
19
20
/*! \file creditriskplus.hpp
21
    \brief Extended CreditRisk+ Model
22
*/
23
24
#ifndef quantlib_creditriskplus_hpp
25
#define quantlib_creditriskplus_hpp
26
27
#include <ql/qldefines.hpp>
28
#include <ql/types.hpp>
29
#include <ql/math/matrix.hpp>
30
#include <vector>
31
32
namespace QuantLib {
33
34
    /*! Extended CreditRisk+ model as described in [1] Integrating Correlations, Risk,
35
      July 1999 and the references therein.
36
37
      \warning the input correlation matrix is not checked for positive
38
      definiteness
39
40
      \deprecated Out of scope; copy this class in your codebase if needed.
41
                  Deprecated in version 1.36.
42
    */
43
    class [[deprecated("Out of scope; copy this class in your codebase if needed")]] CreditRiskPlus {
44
45
      public:
46
        CreditRiskPlus(std::vector<Real> exposure,
47
                       std::vector<Real> defaultProbability,
48
                       std::vector<Size> sector,
49
                       std::vector<Real> relativeDefaultVariance,
50
                       Matrix correlation,
51
                       Real unit);
52
53
0
        const std::vector<Real> &loss() { return loss_; }
54
0
        const std::vector<Real> &marginalLoss() { return marginalLoss_; }
55
56
0
        Real exposure() const { return exposureSum_; }
57
0
        Real expectedLoss() const { return el_; }
58
0
        Real unexpectedLoss() const { return ul_; }
59
0
        Real relativeDefaultVariance() const {
60
0
            return (unexpectedLoss() * unexpectedLoss() - el2_) /
61
0
                   (expectedLoss() * expectedLoss());
62
0
        }
63
64
0
        const std::vector<Real> &sectorExposures() const {
65
0
            return sectorExposure_;
66
0
        }
67
0
        const std::vector<Real> &sectorExpectedLoss() const {
68
0
            return sectorEl_;
69
0
        }
70
0
        const std::vector<Real> &sectorUnexpectedLoss() const {
71
0
            return sectorUl_;
72
0
        }
73
74
        Real lossQuantile(Real p);
75
76
      private:
77
78
        const std::vector<Real> exposure_;
79
        const std::vector<Real> pd_;
80
        const std::vector<Size> sector_;
81
        const std::vector<Real> relativeDefaultVariance_;
82
        const Matrix correlation_;
83
        const Real unit_;
84
85
        Size n_, m_; // number of sectors, exposures
86
87
        std::vector<Real> sectorExposure_, sectorEl_, sectorUl_, marginalLoss_,
88
            loss_;
89
90
        Real exposureSum_, el_, el2_, ul_;
91
        unsigned long upperIndex_;
92
93
        void compute();
94
    };
95
}
96
97
#endif