24#ifndef quantlib_binomial_distribution_h
25#define quantlib_binomial_distribution_h
98 logOneMinusP_ = std::log(1.0-p);
104 CumulativeBinomialDistribution::CumulativeBinomialDistribution(
105 Real p, BigNatural n)
108 QL_REQUIRE(p>=0, "negative p not allowed
");
109 QL_REQUIRE(p<=1.0, "p>1.0 not allowed
");
113 inline Real BinomialDistribution::operator()(BigNatural k) const {
115 if (k > n_) return 0.0;
119 return (k==n_ ? 1.0 : 0.0);
121 else if (logOneMinusP_==0.0)
122 return (k==0 ? 1.0 : 0.0);
124 return std::exp(binomialCoefficientLn(n_, k) +
125 k * logP_ + (n_-k) * logOneMinusP_);
136 inline Real PeizerPrattMethod2Inversion(Real z, BigNatural n) {
139 "
n must be an odd number:
" << n << " not allowed
");
141 Real result = (z/(n+1.0/3.0+0.1/(n+1.0)));
143 result = std::exp(-result*(n+1.0/6.0));
144 result = 0.5 + (z>0 ? 1 : -1) * std::sqrt((0.25 * (1.0-result)));
Beta and beta incomplete functions.
Binomial probability distribution function.
BinomialDistribution(Real p, BigNatural n)
Real operator()(BigNatural k) const
Cumulative binomial distribution function.
Real operator()(BigNatural k) const
static Real ln(Natural n)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Factorial numbers calculator.
Real incompleteBetaFunction(Real a, Real b, Real x, Real accuracy, Integer maxIteration)
Incomplete Beta function.
Real binomialCoefficient(BigNatural n, BigNatural k)
Real binomialCoefficientLn(BigNatural n, BigNatural k)
unsigned QL_BIG_INTEGER BigNatural
large positive integer