/src/quantlib/ql/experimental/credit/onefactorgaussiancopula.hpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2008 Roland Lichters |
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 onefactorgaussiancopula.hpp |
21 | | \brief One-factor Gaussian copula |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_one_factor_gaussian_copula_hpp |
25 | | #define quantlib_one_factor_gaussian_copula_hpp |
26 | | |
27 | | #include <ql/experimental/credit/onefactorcopula.hpp> |
28 | | #include <ql/math/distributions/normaldistribution.hpp> |
29 | | |
30 | | namespace QuantLib { |
31 | | |
32 | | //! One-factor Gaussian Copula |
33 | | /*! The copula model |
34 | | \f[ Y_i = a_i\,M+\sqrt{1-a_i^2}\:Z_i \f] |
35 | | is specified here by setting the desnity function for all |
36 | | variables, \f$ M, Z,\f$ and also \f$ Y \f$ to the standard |
37 | | normal distribution |
38 | | \f$ \phi(x) = \exp(-x^2/2) / \sqrt{2\pi}. \f$ |
39 | | */ |
40 | | class OneFactorGaussianCopula : public OneFactorCopula { |
41 | | public: |
42 | | explicit OneFactorGaussianCopula(const Handle<Quote>& correlation, |
43 | | Real maximum = 5, Size integrationSteps = 50) |
44 | 0 | : OneFactorCopula (correlation, maximum, integrationSteps) { |
45 | 0 | registerWith(correlation_); |
46 | 0 | } |
47 | | Real density(Real m) const override; |
48 | | Real cumulativeZ(Real z) const override; |
49 | | /*! overrides the base class implementation based on table data */ |
50 | | Real cumulativeY(Real y) const override; |
51 | | Real testCumulativeY (Real y) const; |
52 | | /*! overrides the base class implementation based on table data */ |
53 | | Real inverseCumulativeY(Real p) const override; |
54 | | |
55 | | private: |
56 | | // nothing to be done when correlation changes |
57 | 0 | void performCalculations() const override {} |
58 | | |
59 | | NormalDistribution density_; |
60 | | CumulativeNormalDistribution cumulative_; |
61 | | InverseCumulativeNormal inverseCumulative_; |
62 | | }; |
63 | | |
64 | 0 | inline Real OneFactorGaussianCopula::density (Real m) const { |
65 | 0 | return density_(m); |
66 | 0 | } |
67 | | |
68 | 0 | inline Real OneFactorGaussianCopula::cumulativeZ (Real z) const { |
69 | 0 | return cumulative_(z); |
70 | 0 | } |
71 | | |
72 | 0 | inline Real OneFactorGaussianCopula::cumulativeY (Real y) const { |
73 | 0 | return cumulative_(y); |
74 | 0 | } |
75 | | |
76 | 0 | inline Real OneFactorGaussianCopula::inverseCumulativeY (Real p) const { |
77 | 0 | return inverseCumulative_(p); |
78 | 0 | } |
79 | | |
80 | | } |
81 | | |
82 | | #endif |