Skip to content

Normal distribution

The normal (Gaussian) distribution is the most commonly used continuous distribution in Nautilus. It provides PDF, CDF, inverse CDF, and sampling. The CDF and inverse CDF are the workhorses for Black-Scholes pricing, Value-at-Risk, and hypothesis testing.

Signature: (x: f32, mean: f32, std: f32) -> f32

Computes (1 / (std * sqrt(2*pi))) * exp(-0.5 * ((x - mean) / std)^2).

import Nautilus.Distributions (normal_pdf)
p = normal_pdf(cast(0.0, f32), cast(0.0, f32), cast(1.0, f32)) -- approximately 0.3989

Signature: (x: f32, mean: f32, std: f32) -> f32

Computes P(X <= x) via the error function: 0.5 * (1 + erf(z / sqrt(2))) where z = (x - mean) / std.

import Nautilus.Distributions (normal_cdf)
p = normal_cdf(cast(1.96, f32), cast(0.0, f32), cast(1.0, f32)) -- approximately 0.975

Signature: (q: f32, mean: f32, std: f32) -> f32

Returns x such that normal_cdf(x, mean, std) = q. Uses the Acklam rational approximation via erfinv, with separate branches for central and tail regions.

  • Domain: q in (0, 1)
  • At q = 0: returns -inf
  • At q = 1: returns +inf
  • Outside [0, 1]: returns NaN
import Nautilus.Distributions (normal_inv_cdf)
x = normal_inv_cdf(cast(0.975, f32), cast(0.0, f32), cast(1.0, f32)) -- approximately 1.96

Signature: [n](template: tensor[n, f32], mean: f32, std: f32) -> tensor[n, f32] ! { Random }

Generates n samples from Normal(mean, std) using the Box-Muller transform. The template tensor determines the output shape; its values are ignored. Carries the Random effect.

import Nautilus.Distributions (normal_sample)
-- template shape determines output length
samples = normal_sample(zeros, cast(0.0, f32), cast(1.0, f32))
Inputnormal_pdfnormal_cdfnormal_inv_cdf
x = mean1/(stdsqrt(2pi))0.5mean
x = +inf0.01.0n/a
x = -inf0.00.0n/a
q = 0n/an/a-inf
q = 1n/an/a+inf
q outside [0,1]n/an/aNaN