Class SpecialFunctions

java.lang.Object
com.quantfinlib.stats.SpecialFunctions

public final class SpecialFunctions extends Object
Normal density, distribution and quantile, log-gamma, the regularized incomplete beta function and the Student-t distribution function.

Added in 2.4.0 as the home of these functions from util.MathUtils (removed in 3.0). The code was moved, not rewritten, so every value is bit-identical to 2.3.

Since:
2.4.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    logGamma(double x)
    Natural log of the gamma function (Lanczos, |relative error| < 2e-10).
    static double
    logNormPdf(double x)
    Natural log of the standard normal density, finite for any finite x.
    static double
    normCdf(double x)
    Standard normal CDF to full double precision.
    static double
    normInv(double p)
    Inverse standard normal CDF: Acklam's rational seed (|error| < 1.15e-9) refined by one Halley step on normCdf(double), which brings it to double precision apart from the last few bits.
    static double
    normPdf(double x)
    Standard normal density.
    static double
    regularizedIncompleteBeta(double a, double b, double x)
    Regularized incomplete beta function I_x(a, b) via the continued fraction (modified Lentz), switching to the symmetry I_x(a,b) = 1 − I_{1−x}(b,a) where the fraction converges fastest.
    static double
    tCdf(double t, double df)
    Student-t CDF with df degrees of freedom — exact via the regularized incomplete beta (P(T ≤ t) = 1 − ½·I_{ν/(ν+t²)}(ν/2, ½) for t ≥ 0), no normal approximation: the tails are precisely where a t distribution and its moment-matched normal disagree most.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • normInv

      public static double normInv(double p)
      Inverse standard normal CDF: Acklam's rational seed (|error| < 1.15e-9) refined by one Halley step on normCdf(double), which brings it to double precision apart from the last few bits.
    • logNormPdf

      public static double logNormPdf(double x)
      Natural log of the standard normal density, finite for any finite x.
    • normPdf

      public static double normPdf(double x)
      Standard normal density.
    • normCdf

      public static double normCdf(double x)
      Standard normal CDF to full double precision.

      W. J. Cody's rational Chebyshev approximations (Cody 1969, "Rational Chebyshev approximations for the error function", Math. Comp. 23, 631-637; coefficients from his SPECFUN routine ANORM, 1993, the set R's pnorm also uses). Three regions: |x| <= 0.67449, |x| <= sqrt(32) and the asymptotic tail. The Gaussian factor is split as exp(-xs^2/2) exp(-(x-xs)(x+xs)/2) with xs = |x| truncated to a multiple of 1/16, so the exponent carries no rounding error and the lower tail keeps relative accuracy (about 1e-15) down to x = -37.5. Further out the value is subnormal and then 0. NaN in gives NaN out.

    • logGamma

      public static double logGamma(double x)
      Natural log of the gamma function (Lanczos, |relative error| < 2e-10).
    • regularizedIncompleteBeta

      public static double regularizedIncompleteBeta(double a, double b, double x)
      Regularized incomplete beta function I_x(a, b) via the continued fraction (modified Lentz), switching to the symmetry I_x(a,b) = 1 − I_{1−x}(b,a) where the fraction converges fastest. Accurate to ~1e-13 across (0, 1).
    • tCdf

      public static double tCdf(double t, double df)
      Student-t CDF with df degrees of freedom — exact via the regularized incomplete beta (P(T ≤ t) = 1 − ½·I_{ν/(ν+t²)}(ν/2, ½) for t ≥ 0), no normal approximation: the tails are precisely where a t distribution and its moment-matched normal disagree most.