Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
stochastic-rs
A high-performance Rust library for simulating stochastic processes, with first-class bindings. Built for quantitative finance, statistical modeling and synthetic data generation.
Features
- 85+ stochastic models - diffusions, jump processes, stochastic volatility, interest rate models, autoregressive models, noise generators, and probability distributions
- Copulas - bivariate, multivariate, and empirical copulas with correlation utilities
- Quant toolbox - option pricing, bond analytics, calibration, loss models, order book, and trading strategies
- Statistics - MLE, kernel density estimation, fractional OU estimation, and CIR parameter fitting
- SIMD-optimized - fractional Gaussian noise, fractional Brownian motion, and all probability distributions use wide SIMD for fast sample generation
- Parallel sampling -
sample_par(m)generatesmindependent paths in parallel via rayon - Generic precision - most models support both
f32andf64 - Bindings - full stochastic model coverage with numpy integration; all models return numpy arrays
Installation
Rust
[]
= "1.0.0"
Bindings
For development builds from source (requires maturin):
Usage
Rust
use FBM;
use Heston;
use HestonPow;
use ProcessExt;
Bindings
All models return numpy arrays. Use dtype="f32" or dtype="f64" (default) to control precision.
# Basic processes
=
= # shape (1000,)
= # shape (500, 1000)
# Stochastic volatility
=
, =
# Models with callable parameters
=
=
# Jump processes with custom jump distributions
=
=
Benchmarks
CUDA build details (Windows/Linux commands) are documented in src/stochastic/cuda/CUDA_BUILD.md.
CUDA fallback (if auto-build fails)
If cargo build --features cuda fails (for example: nvcc fatal : Cannot find compiler 'cl.exe'), use prebuilt CUDA FGN binaries.
- Download the platform file from GitHub Releases:
https://github.com/dancixx/stochastic-rs/releases - Place it at:
- Windows:
src/stochastic/cuda/fgn_windows/fgn.dll - Linux:
src/stochastic/cuda/fgn_linux/libfgn.so
- Windows:
- Set runtime path explicitly:
$env:STOCHASTIC_RS_CUDA_FGN_LIB_PATH='src/stochastic/cuda/fgn_windows/fgn.dll'
FGN CPU vs CUDA (sample, sample_par, sample_cuda)
Measured with Criterion in --release using:
$env:STOCHASTIC_RS_CUDA_FGN_LIB_PATH='src/stochastic/cuda/fgn_windows/fgn.dll'
Environment:
- GPU: NVIDIA GeForce RTX 4070 SUPER
- Rust:
rustc 1.93.1 - CUDA library:
src/stochastic/cuda/fgn_windows/fgn.dll(fatbinsm_75+)
Note: one-time CUDA init is excluded via warmup (sample_cuda(...) called once before each benchmark case).
Single path (sample vs sample_cuda(1), f32, H=0.7):
| n | CPU sample |
CUDA sample_cuda(1) |
CUDA speedup (CPU/CUDA) |
|---|---|---|---|
| 1,024 | 10.112 us | 62.070 us | 0.16x |
| 4,096 | 40.901 us | 49.040 us | 0.83x |
| 16,384 | 184.060 us | 59.592 us | 3.09x |
| 65,536 | 1.0282 ms | 121.160 us | 8.49x |
Batch (sample_par(m) vs sample_cuda(m), f32, H=0.7):
| n, m | CPU sample_par(m) |
CUDA sample_cuda(m) |
CUDA speedup (CPU/CUDA) |
|---|---|---|---|
| 4,096, 32 | 148.840 us | 154.080 us | 0.97x |
| 4,096, 128 | 364.690 us | 1.1255 ms | 0.32x |
| 4,096, 512 | 1.7975 ms | 4.3293 ms | 0.42x |
| 16,384, 128 | 1.7029 ms | 4.5458 ms | 0.37x |
| 16,384, 512 | 5.5850 ms | 17.2110 ms | 0.32x |
Interpretation:
- CUDA wins for large single-path generation (from roughly
n >= 16kin this setup). - For the tested batch sizes, CPU
sample_paris faster than current CUDA path.
Distribution Sampling (All Built-in Distributions)
Measured with:
Configuration in this run:
sample_matrixbenchmark- 1-thread vs 14-thread rayon pools
- size is mostly
1024 x 1024; heavy discrete samplers use512 x 512
| Distribution | Shape | 1T (ms) | MT (ms) | Speedup |
|---|---|---|---|---|
| Normal | 1024 x 1024 | 1.78 | 0.34 | 5.28x |
| Exp | 1024 x 1024 | 1.73 | 0.33 | 5.25x |
| Uniform | 1024 x 1024 | 0.65 | 0.13 | 5.12x |
| Cauchy | 1024 x 1024 | 6.23 | 0.90 | 6.96x |
| LogNormal | 1024 x 1024 | 5.07 | 0.81 | 6.25x |
| Gamma | 1024 x 1024 | 5.20 | 0.72 | 7.19x |
| ChiSq | 1024 x 1024 | 5.06 | 1.22 | 4.14x |
| StudentT | 1024 x 1024 | 7.89 | 1.89 | 4.18x |
| Beta | 1024 x 1024 | 11.85 | 1.68 | 7.04x |
| Weibull | 1024 x 1024 | 13.17 | 1.73 | 7.59x |
| Pareto | 1024 x 1024 | 5.48 | 0.80 | 6.87x |
| InvGauss | 1024 x 1024 | 2.52 | 0.44 | 5.69x |
| NIG | 1024 x 1024 | 5.93 | 0.90 | 6.62x |
| AlphaStable | 1024 x 1024 | 42.52 | 5.36 | 7.94x |
| Poisson | 1024 x 1024 | 2.28 | 0.42 | 5.40x |
| Geometric | 1024 x 1024 | 2.75 | 0.44 | 6.30x |
| Binomial | 512 x 512 | 4.43 | 0.70 | 6.32x |
| Hypergeo | 512 x 512 | 20.99 | 2.76 | 7.60x |
Normal single-thread kernel comparison (fill_slice, same run):
- vs
rand_distr + SimdRng: ~1.21xto1.35x - vs
rand_distr + rand::rng(): ~4.09xto4.61x
Contributing
Contributions are welcome - bug reports, feature suggestions, or PRs. Open an issue or start a discussion on GitHub.
License
MIT - see LICENSE.