/// <summary> ///Cumulative normal distribution function ///For this implementation see M. Abramowitz and I. Stegun, ///Handbook of Mathematical Functions, ///Dover Publications, New York (1972) /// </summary> public static double Cumulative(double z) { if (z <= Cdf_Asymptotic_First_Threshold) { // Asymptotic expansion for very negative z following (26.2.12) on page 408 // in M. Abramowitz and A. Stegun, Pocketbook of Mathematical Functions, ISBN 3-87144818-4. double sum = 1; if (z >= CdfAsymptoticSecondThreshold) { double zsqr = z * z, i = 1, g = 1, a = double.MaxValue, lasta; do { lasta = a; double x = (4 * i - 3) / zsqr; double y = x * ((4 * i - 1) / zsqr); a = g * (x - y); sum -= a; g *= y; ++i; a = Math.Abs(a); } while (lasta > a && a >= Math.Abs(sum * DoubleUtils.MachineEpsilon)); } return(-Density(z) * sum / z); } return(0.5 * ErrorFunctions.Erfc(-z * MathConsts.InvSqrt2)); }
private static double NormalizedCall(double d) { return(Math.Exp(-0.5 * d * d) * (MathConsts.InvSqrtTwoPi - 0.5 * d * ErrorFunctions.Erfcx(MathConsts.InvSqrt2 * d))); }