/src/quantlib/ql/math/distributions/gammadistribution.hpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2002, 2003 Sadruddin Rejeb |
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 gammadistribution.hpp |
21 | | \brief Gamma distribution |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_math_gamma_distribution_h |
25 | | #define quantlib_math_gamma_distribution_h |
26 | | |
27 | | #include <ql/errors.hpp> |
28 | | #include <ql/types.hpp> |
29 | | #include <functional> |
30 | | |
31 | | namespace QuantLib { |
32 | | |
33 | | class CumulativeGammaDistribution { |
34 | | public: |
35 | 0 | CumulativeGammaDistribution(Real a) : a_(a) { |
36 | | QL_REQUIRE(a>0.0, "invalid parameter for gamma distribution"); |
37 | 0 | } |
38 | | Real operator()(Real x) const; |
39 | | private: |
40 | | Real a_; |
41 | | }; |
42 | | |
43 | | //! Gamma function class |
44 | | /*! This is a function defined by |
45 | | \f[ |
46 | | \Gamma(z) = \int_0^{\infty}t^{z-1}e^{-t}dt |
47 | | \f] |
48 | | |
49 | | The implementation of the algorithm was inspired by |
50 | | "Numerical Recipes in C", 2nd edition, |
51 | | Press, Teukolsky, Vetterling, Flannery, chapter 6 |
52 | | |
53 | | \test the correctness of the returned value is tested by |
54 | | checking it against known good results. |
55 | | */ |
56 | | class GammaFunction { |
57 | | public: |
58 | | Real value(Real x) const; |
59 | | Real logValue(Real x) const; |
60 | | private: |
61 | | static const Real c1_, c2_, c3_, c4_, c5_, c6_; |
62 | | }; |
63 | | |
64 | | } |
65 | | |
66 | | |
67 | | #endif |