QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
onefactorgaussiancopula.cpp
Go to the documentation of this file.
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
21
22namespace QuantLib {
23
24 //-----------------------------------------------------------------------
26 //-----------------------------------------------------------------------
27 Real c = correlation_->value();
28
29 if (c == 0)
31
32 if (c == 1)
34
37
38 Real minimum = -10;
39 Real maximum = +10;
40 int steps = 200;
41
42 Real delta = (maximum - minimum) / steps;
43 Real cumulated = 0;
44 if (c < 0.5) {
45 // outer integral -> 1 for c -> 0
46 // inner integral -> CumulativeNormal()(y) for c-> 0
47 for (Real m = minimum; m < maximum; m += delta)
48 for (Real z = minimum; z < (y - std::sqrt(c) * m) / std::sqrt (1. - c);
49 z += delta)
50 cumulated += dm (m) * dz (z);
51 }
52 else {
53 // outer integral -> 1 for c -> 1
54 // inner integral -> CumulativeNormal()(y) for c-> 1
55 for (Real z = minimum; z < maximum; z += delta)
56 for (Real m = minimum; m < (y - std::sqrt(1.0 - c) * z) / std::sqrt(c);
57 m += delta)
58 cumulated += dm (m) * dz (z);
59 }
60 cumulated *= (delta * delta);
61
62 return cumulated;
63 }
64
65}
66
Cumulative normal distribution function.
Normal distribution function.
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
One-factor Gaussian copula.