| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2002, 2003 Sadruddin Rejeb |
| 5 | Copyright (C) 2007 Klaus Spanderen |
| 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 chisquaredistribution.hpp |
| 22 | \brief Chi-square (central and non-central) distributions |
| 23 | */ |
| 24 | |
| 25 | #ifndef quantlib_chi_square_distribution_hpp |
| 26 | #define quantlib_chi_square_distribution_hpp |
| 27 | |
| 28 | #include <ql/types.hpp> |
| 29 | #include <functional> |
| 30 | |
| 31 | namespace QuantLib { |
| 32 | |
| 33 | class CumulativeChiSquareDistribution { |
| 34 | public: |
| 35 | /*! \deprecated Use `auto` or `decltype` instead. |
| 36 | Deprecated in version 1.29. |
| 37 | */ |
| 38 | QL_DEPRECATED |
| 39 | typedef Real argument_type; |
| 40 | |
| 41 | /*! \deprecated Use `auto` or `decltype` instead. |
| 42 | Deprecated in version 1.29. |
| 43 | */ |
| 44 | QL_DEPRECATED |
| 45 | typedef Real result_type; |
| 46 | |
| 47 | explicit CumulativeChiSquareDistribution(Real df) : df_(df) {} |
| 48 | Real operator()(Real x) const; |
| 49 | private: |
| 50 | Real df_; |
| 51 | }; |
| 52 | |
| 53 | class NonCentralCumulativeChiSquareDistribution { |
| 54 | public: |
| 55 | /*! \deprecated Use `auto` or `decltype` instead. |
| 56 | Deprecated in version 1.29. |
| 57 | */ |
| 58 | QL_DEPRECATED |
| 59 | typedef Real argument_type; |
| 60 | |
| 61 | /*! \deprecated Use `auto` or `decltype` instead. |
| 62 | Deprecated in version 1.29. |
| 63 | */ |
| 64 | QL_DEPRECATED |
| 65 | typedef Real result_type; |
| 66 | |
| 67 | NonCentralCumulativeChiSquareDistribution(Real df, Real ncp) |
| 68 | : df_(df), ncp_(ncp) {} |
| 69 | Real operator()(Real x) const; |
| 70 | private: |
| 71 | Real df_, ncp_; |
| 72 | }; |
| 73 | |
| 74 | class NonCentralCumulativeChiSquareSankaranApprox { |
| 75 | public: |
| 76 | /*! \deprecated Use `auto` or `decltype` instead. |
| 77 | Deprecated in version 1.29. |
| 78 | */ |
| 79 | QL_DEPRECATED |
| 80 | typedef Real argument_type; |
| 81 | |
| 82 | /*! \deprecated Use `auto` or `decltype` instead. |
| 83 | Deprecated in version 1.29. |
| 84 | */ |
| 85 | QL_DEPRECATED |
| 86 | typedef Real result_type; |
| 87 | |
| 88 | NonCentralCumulativeChiSquareSankaranApprox(Real df, Real ncp) |
| 89 | : df_(df), ncp_(ncp) {} |
| 90 | Real operator()(Real x) const; |
| 91 | private: |
| 92 | Real df_, ncp_; |
| 93 | }; |
| 94 | |
| 95 | class InverseNonCentralCumulativeChiSquareDistribution { |
| 96 | public: |
| 97 | /*! \deprecated Use `auto` or `decltype` instead. |
| 98 | Deprecated in version 1.29. |
| 99 | */ |
| 100 | QL_DEPRECATED |
| 101 | typedef Real argument_type; |
| 102 | |
| 103 | /*! \deprecated Use `auto` or `decltype` instead. |
| 104 | Deprecated in version 1.29. |
| 105 | */ |
| 106 | QL_DEPRECATED |
| 107 | typedef Real result_type; |
| 108 | |
| 109 | InverseNonCentralCumulativeChiSquareDistribution(Real df, Real ncp, |
| 110 | Size maxEvaluations=10, |
| 111 | Real accuracy = 1e-8); |
| 112 | Real operator()(Real x) const; |
| 113 | |
| 114 | private: |
| 115 | NonCentralCumulativeChiSquareDistribution nonCentralDist_; |
| 116 | const Real guess_; |
| 117 | const Size maxEvaluations_; |
| 118 | const Real accuracy_; |
| 119 | }; |
| 120 | |
| 121 | } |
| 122 | |
| 123 | |
| 124 | #endif |
| 125 | |