QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
centrallimitgaussianrng.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2003 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
25#ifndef quantlib_central_limit_gaussian_rng_h
26#define quantlib_central_limit_gaussian_rng_h
27
28#include <ql/methods/montecarlo/sample.hpp>
29
30namespace QuantLib {
31
33
43 template <class RNG>
45 public:
47 typedef RNG urng_type;
48 explicit CLGaussianRng(const RNG& uniformGenerator);
50 sample_type next() const;
51 private:
53 };
54
55 template <class RNG>
56 CLGaussianRng<RNG>::CLGaussianRng(const RNG& uniformGenerator)
57 : uniformGenerator_(uniformGenerator) {}
58
59 template <class RNG>
62 Real gaussPoint = -6.0, gaussWeight = 1.0;
63 for (Integer i=1;i<=12;i++) {
64 typename RNG::sample_type sample = uniformGenerator_.next();
65 gaussPoint += sample.value;
66 gaussWeight *= sample.weight;
67 }
68 return {gaussPoint, gaussWeight};
69 }
70
71}
72
73
74#endif
Gaussian random number generator.
sample_type next() const
returns a sample from a Gaussian distribution
CLGaussianRng(const RNG &uniformGenerator)
QL_REAL Real
real number
Definition: types.hpp:50
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Definition: any.hpp:35
weighted sample
Definition: sample.hpp:35