Article Menu |
Calculating the Cumulative Normal Distributionby M.A. (Thijs) van den Berg The cumulative normal distribution is defined by the integral with n(t) the normal density function
This integral has no closed form solution, but many good approximations exist.
[edit] Abromowitz and Stegun approximationThe most used algorithm is algorithm 26.2.17 from Abromowitz and Stegun, Handbook of Mathematical Functions. It has a maximum absolute error of 7.5e^-8. with
[edit] C++ code
double N(const double x) { const double b1 = 0.319381530; const double b2 = -0.356563782; const double b3 = 1.781477937; const double b4 = -1.821255978; const double b5 = 1.330274429; const double p = 0.2316419; const double c = 0.39894228; if(x >= 0.0) { double t = 1.0 / ( 1.0 + p * x ); return (1.0 - c * exp( -x * x / 2.0 ) * t * ( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 )); } else { double t = 1.0 / ( 1.0 - p * x ); return ( c * exp( -x * x / 2.0 ) * t * ( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 )); } } [edit] VBA (Visual Basic for Applications) code
Public Function NormProb(x As Double) As Double Dim t As Double Const b1 = 0.31938153 Const b2 = -0.356563782 Const b3 = 1.781477937 Const b4 = -1.821255978 Const b5 = 1.330274429 Const p = 0.2316419 Const c = 0.39894228 If x >= 0 Then t = 1# / (1# + p * x) NormProb = (1# - c * Exp(-x * x / 2#) * t * _ (t * (t * (t * (t * b5 + b4) + b3) + b2) + b1)) Else t = 1# / (1# - p * x) NormProb = (c * Exp(-x * x / 2#) * t * _ (t * (t * (t * (t * b5 + b4) + b3) + b2) + b1)) End If End Function [edit] High Precision ApproximationA high (double) precision approximation is described in the article Better Approximations to Cumulative Normal Fuctiona by Graeme West. The algorithm is based on Hart's algorithm 5666 (1968). |
