DistributionExt
Closed-form pdf, cdf, characteristic function, and moments for every distribution — 18 of 19 closed-form, with five named unimplemented moments.
DistributionExt<T>
Closed-form analytics for every distribution that has them.
pub trait DistributionExt<T: FloatExt> {
fn pdf(&self, x: T) -> T;
fn cdf(&self, x: T) -> T;
fn characteristic_fn(&self, t: T) -> Complex<T>;
fn mean(&self) -> T;
fn variance(&self) -> T;
fn skewness(&self) -> T { unimplemented_moment::<T>() }
fn kurtosis(&self) -> T { unimplemented_moment::<T>() }
}Coverage
18 / 19 distributions implement closed-form pdf, cdf, characteristic
function, mean, and variance. The exception is ComplexDistribution,
which is a wrapper used by Fourier-domain pricers and intentionally
opaque.
For higher-order moments, 5 named distributions carry
unimplemented! for skewness and / or kurtosis — those are documented
on each distribution's reference page. The remaining 14 ship full
closed-form skewness and excess kurtosis.
Default behaviour: panic, never zero
Project rule: an unimplemented moment panics with a helpful message including the type name, never silently returns 0. This was a deliberate choice after a v1.x bug where a silent-zero kurtosis caused a downstream calibration to converge on garbage.
fn unimplemented_moment<T>() -> ! {
let name = std::any::type_name::<T>();
unimplemented!("moment not implemented for {name}")
}If you hit such a panic, you have two options:
- Use a different distribution if the moment is non-essential.
- Open an issue / PR — the
feedback_implementation.mdrule says we follow papers exactly, so closed forms get added with a citation.
Why no statrs::distribution::*
The library deliberately writes closed forms from scratch in
stochastic-rs-distributions, never delegating to statrs. Reasons:
- Generic precision.
statrsisf64-only. We needf32support for GPU + memory-bound bulk sampling. - No-allocation guarantees.
statrsallocates in some cdfs; the bulk samplers in this library cannot afford that. - Audit trail. Every formula in this crate is anchored to a paper
citation, with a comparison test against the paper's numerical
tables.
statrs's implementations are competent but lack that audit trail.
See the per-distribution pages under Distributions for the formulas, tests, and references.
ProcessExt
The trait every stochastic process implements — sample, sample_par, with the contract for path length, time grid, and parallel determinism.
PricerExt and ModelPricer
The two pricer trait surfaces — date-aware PricerExt for vanilla flow, and concrete-typed ModelPricer for fast Greeks and calibration without &dyn.