Distributions
Module: Shoals.Distributions.
This module adds finance-relevant densities and cumulatives on top of the
normal distribution from Nautilus.Distributions and the log-gamma special
function from Nautilus.Special: the lognormal density and cumulative, the
Student-t density and a cumulative approximation, and the bivariate-normal
density.
Lognormal
Section titled “Lognormal”def lognormal_pdf(x: f32, mu: f32, sigma: f32) -> f32def lognormal_cdf(x: f32, mu: f32, sigma: f32) -> f32lognormal_pdf is the density of a lognormal whose log has mean mu and
standard deviation sigma, defined to be zero for non-positive x.
lognormal_cdf is the cumulative, also zero for non-positive x. From
tests/distributions.ch:
p = lognormal_pdf(cast(1.0, f32), cast(0.0, f32), cast(1.0, f32)) // p ~ 0.398942c = lognormal_cdf(cast(1.0, f32), cast(0.0, f32), cast(1.0, f32)) // c == 0.5Student-t
Section titled “Student-t”def student_t_pdf(x: f32, nu: f32) -> f32def student_t_cdf_approx(x: f32, nu: f32) -> f32student_t_pdf is the Student-t density with nu degrees of freedom,
composed over Nautilus.Special.log_gamma for the normalizing constant. It
is symmetric about zero. student_t_cdf_approx is a normal-approximation to
the Student-t cumulative. From tests/distributions.ch:
p = student_t_pdf(cast(0.0, f32), cast(5.0, f32)) // p ~ 0.379607Bivariate normal
Section titled “Bivariate normal”def bvn_pdf(x: f32, y: f32, mu_x: f32, mu_y: f32, sigma_x: f32, sigma_y: f32, rho: f32) -> f32bvn_pdf is the bivariate-normal density at (x, y) with means
(mu_x, mu_y), standard deviations (sigma_x, sigma_y), and correlation
rho. At the origin under independent unit normals it equals
1 / (2 * pi). From tests/distributions.ch:
p = bvn_pdf(cast(0.0, f32), cast(0.0, f32), cast(0.0, f32), cast(0.0, f32), cast(1.0, f32), cast(1.0, f32), cast(0.0, f32))// p ~ 0.159155Each of these agrees with its textbook reference under the property checks.