Coverage Report

Created: 2025-08-05 06:45

/src/quantlib/ql/experimental/credit/onefactorgaussiancopula.cpp
Line
Count
Source (jump to first uncovered line)
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
 <http://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
#include <ql/experimental/credit/onefactorgaussiancopula.hpp>
21
22
namespace QuantLib {
23
24
    //-----------------------------------------------------------------------
25
0
    Real OneFactorGaussianCopula::testCumulativeY (Real y) const {
26
    //-----------------------------------------------------------------------
27
0
        Real c = correlation_->value();
28
29
0
        if (c == 0)
30
0
            return CumulativeNormalDistribution()(y);
31
32
0
        if (c == 1)
33
0
            return CumulativeNormalDistribution()(y);
34
35
0
        NormalDistribution dz;
36
0
        NormalDistribution dm;
37
38
0
        Real minimum = -10;
39
0
        Real maximum = +10;
40
0
        int steps = 200;
41
42
0
        Real delta = (maximum - minimum) / steps;
43
0
        Real cumulated = 0;
44
0
        if (c < 0.5) {
45
            // outer integral -> 1 for c -> 0
46
            // inner integral -> CumulativeNormal()(y) for c-> 0
47
0
            for (Real m = minimum; m < maximum; m += delta)
48
0
                for (Real z = minimum; z < (y - std::sqrt(c) * m) / std::sqrt (1. - c);
49
0
                     z += delta)
50
0
                    cumulated += dm (m) * dz (z);
51
0
        }
52
0
        else {
53
            // outer integral -> 1 for c -> 1
54
            // inner integral -> CumulativeNormal()(y) for c-> 1
55
0
            for (Real z = minimum; z < maximum; z += delta)
56
0
                for (Real m = minimum; m < (y - std::sqrt(1.0 - c) * z) / std::sqrt(c);
57
0
                     m += delta)
58
0
                    cumulated += dm (m) * dz (z);
59
0
        }
60
0
        cumulated *= (delta * delta);
61
62
0
        return cumulated;
63
0
    }
64
65
}
66