QuantLib
: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
ql
math
randomnumbers
inversecumulativerng.hpp
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) 2003, 2004 Ferdinando Ametrano
5
Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
6
7
This file is part of QuantLib, a free-software/open-source library
8
for financial quantitative analysts and developers - http://quantlib.org/
9
10
QuantLib is free software: you can redistribute it and/or modify it
11
under the terms of the QuantLib license. You should have received a
12
copy of the license along with this program; if not, please email
13
<quantlib-dev@lists.sf.net>. The license is also available online at
14
<http://quantlib.org/license.shtml>.
15
16
This program is distributed in the hope that it will be useful, but WITHOUT
17
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
FOR A PARTICULAR PURPOSE. See the license for more details.
19
*/
20
21
/*! \file inversecumulativerng.hpp
22
\brief Inverse cumulative Gaussian random-number generator
23
*/
24
25
#ifndef quantlib_inversecumulative_rng_h
26
#define quantlib_inversecumulative_rng_h
27
28
#include <
ql/methods/montecarlo/sample.hpp
>
29
30
namespace
QuantLib
{
31
32
//! Inverse cumulative random number generator
33
/*! It uses a uniform deviate in (0, 1) as the source of cumulative
34
distribution values.
35
Then an inverse cumulative distribution is used to calculate
36
the distribution deviate.
37
38
The uniform deviate is supplied by RNG.
39
40
Class RNG must implement the following interface:
41
\code
42
RNG::sample_type RNG::next() const;
43
\endcode
44
45
The inverse cumulative distribution is supplied by IC.
46
47
Class IC must implement the following interface:
48
\code
49
IC::IC();
50
Real IC::operator() const;
51
\endcode
52
*/
53
template
<
class
RNG,
class
IC>
54
class
InverseCumulativeRng
{
55
public
:
56
typedef
Sample<Real>
sample_type
;
57
typedef
RNG
urng_type
;
58
explicit
InverseCumulativeRng
(
const
RNG& uniformGenerator);
59
//! returns a sample from a Gaussian distribution
60
sample_type
next
()
const
;
61
private
:
62
RNG
uniformGenerator_
;
63
IC
ICND_
;
64
};
65
66
template
<
class
RNG,
class
IC>
67
InverseCumulativeRng<RNG, IC>::InverseCumulativeRng
(
const
RNG& ug)
68
: uniformGenerator_(ug) {}
69
70
template
<
class
RNG,
class
IC>
71
inline
typename
InverseCumulativeRng<RNG, IC>::sample_type
72
InverseCumulativeRng<RNG, IC>::next
()
const
{
73
typename
RNG::sample_type sample = uniformGenerator_.next();
74
return
sample_type
(ICND_(sample.value),sample.weight);
75
}
76
77
}
78
79
80
#endif
QuantLib::InverseCumulativeRng
Inverse cumulative random number generator.
Definition:
inversecumulativerng.hpp:54
QuantLib::InverseCumulativeRng::ICND_
IC ICND_
Definition:
inversecumulativerng.hpp:63
QuantLib::InverseCumulativeRng::next
sample_type next() const
returns a sample from a Gaussian distribution
Definition:
inversecumulativerng.hpp:72
QuantLib::InverseCumulativeRng::uniformGenerator_
RNG uniformGenerator_
Definition:
inversecumulativerng.hpp:62
QuantLib::InverseCumulativeRng::InverseCumulativeRng
InverseCumulativeRng(const RNG &uniformGenerator)
Definition:
inversecumulativerng.hpp:67
QuantLib::InverseCumulativeRng::urng_type
RNG urng_type
Definition:
inversecumulativerng.hpp:57
QuantLib::InverseCumulativeRng::sample_type
Sample< Real > sample_type
Definition:
inversecumulativerng.hpp:56
QuantLib
Definition:
any.hpp:35
sample.hpp
weighted sample
QuantLib::Sample
weighted sample
Definition:
sample.hpp:35
Generated by
Doxygen
1.9.5