stochastic-rs

Copulas

Bivariate (Clayton, Frank, Gumbel, independence) and multivariate (Gaussian, tree, vine) copulas with the BivariateExt / MultivariateExt traits.

Copulas

The stochastic-rs-copulas crate ships bivariate and multivariate copulas plus correlation utilities and an empirical copula.

Bivariate (BivariateExt<T>)

Archimedean and elliptical:

CopulaFamilyTail dependence
ClaytonArchimedeanLower only
FrankArchimedeanNone (symmetric)
GumbelArchimedeanUpper only
IndependenceTrivialNone

The bivariate samplers are consolidated under BivariateExt; the v1.x NCopula2DExt was removed in v2.0.

Multivariate (MultivariateExt<T>)

CopulaFamilyNotes
GaussianEllipticalCholesky-based
TreeVine, simplifiedTree-structured Pair-copula
VineVine, fullR-vine / D-vine / C-vine

Multivariate copulas require the openblas feature for the Cholesky factorisation. See Feature flags.

Examples

Clayton — lower-tail dependence

θ>0\theta > 0 produces lower-tail dependence, useful for modelling joint crashes in equity returns.

use stochastic_rs::copulas::bivariate::clayton::Clayton;
use stochastic_rs::traits::BivariateExt;

let cop = Clayton::<f64>::with_seed(/* theta */ 2.0, 42);
let n = 10_000;
let (u, v) = cop.sample(n);                  // both Array1<f64> in [0, 1]

// Empirical Kendall's τ should be ≈ θ / (θ + 2) = 0.5
let tau_hat = stochastic_rs::stats::tail_index::kendall_tau(u.view(), v.view());
println!("τ̂ = {:.3}", tau_hat);
import stochastic_rs as srs

cop = srs.Clayton(theta=2.0, seed=42)
u, v = cop.sample(10_000)
print("Kendall's tau ≈", srs.kendall_tau(u, v))   # ≈ 0.5

Gaussian copula — multivariate sampling

use stochastic_rs::copulas::multivariate::gaussian::GaussianCopula;
use ndarray::array;

let corr = array![
    [1.0, 0.7, 0.3],
    [0.7, 1.0, 0.5],
    [0.3, 0.5, 1.0],
];
let cop = GaussianCopula::<f64>::with_seed(corr, 42);
let samples = cop.sample(10_000);            // Array2<f64>, shape (10_000, 3)
import stochastic_rs as srs
import numpy as np

corr = np.array([
    [1.0, 0.7, 0.3],
    [0.7, 1.0, 0.5],
    [0.3, 0.5, 1.0],
])
cop = srs.GaussianCopula(corr=corr, seed=42)
samples = cop.sample(10_000)                 # shape (10_000, 3)

Adding a copula

See the copula-bivariate SKILL — file-by-file recipe for Clayton / Frank / Gumbel / Joe / Plackett / FGM / extreme-value families.

On this page