Skip to main content

Copula modeling for Python (NumPy) and Rust: vines, pair copulas, and reference-tested pseudo-observation workflows

Project description

rscopulas logo

rscopulas

rscopulas is a Python package for fitting, evaluating, and sampling copula models on validated pseudo-observations, backed by a Rust core built with PyO3 and maturin.

Install

pip install rscopulas

Optional plotting helpers are available with:

pip install "rscopulas[viz]"

Included models

  • Gaussian and Student t copulas
  • Archimedean families including Clayton, Frank, and Gumbel
  • Pair copulas, including Khoudraji constructions
  • C-vine, D-vine, and R-vine copulas
  • Hierarchical Archimedean copulas

Python example

import numpy as np
from rscopulas import GaussianCopula

data = np.array(
    [
        [0.12, 0.18],
        [0.21, 0.25],
        [0.82, 0.79],
    ],
    dtype=np.float64,
)

fit = GaussianCopula.fit(data)
print("AIC:", fit.diagnostics.aic)
print("sample:\n", fit.model.sample(4, seed=7))

Sampling example

from rscopulas import GumbelCopula

model = GumbelCopula.from_params(2, 2.1)
samples = model.sample(5, seed=11)

print("family:", model.family)
print("samples:\n", samples)
print("log_pdf:\n", model.log_pdf(samples))

Advanced example: fit an R-vine

import numpy as np
from rscopulas import VineCopula

data = np.array(
    [
        [0.10, 0.14, 0.18, 0.22],
        [0.18, 0.21, 0.24, 0.27],
        [0.24, 0.29, 0.33, 0.31],
        [0.33, 0.30, 0.38, 0.41],
        [0.47, 0.45, 0.43, 0.49],
        [0.52, 0.58, 0.55, 0.53],
        [0.69, 0.63, 0.67, 0.71],
        [0.81, 0.78, 0.74, 0.76],
    ],
    dtype=np.float64,
)

fit = VineCopula.fit_r(
    data,
    family_set=["independence", "gaussian", "clayton", "frank", "gumbel"],
    truncation_level=2,
    max_iter=200,
)

print("structure kind:", fit.model.structure_kind)
print("order:", fit.model.order)
print("first-tree families:", [edge.family for edge in fit.model.trees[0].edges])
print("sample:\n", fit.model.sample(4, seed=13))

Project links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rscopulas-0.1.1.tar.gz (93.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rscopulas-0.1.1-cp313-cp313-macosx_11_0_arm64.whl (567.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file rscopulas-0.1.1.tar.gz.

File metadata

  • Download URL: rscopulas-0.1.1.tar.gz
  • Upload date:
  • Size: 93.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for rscopulas-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e1f7abbefc4ea3941a0e9ab6382c1db72c1070d866b55e16079fbaf93a28eec4
MD5 d284b2e04f69b854c7e7e04280fd5bc3
BLAKE2b-256 25a79b7863ffb12108b5b6a9736213392c6af26ff37b69dbbe38f79d5fbd438b

See more details on using hashes here.

File details

Details for the file rscopulas-0.1.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rscopulas-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eccf9c5113f439b5a22f46b6facff5aa8bc2f969c5b0b932f1fc5094905c90c4
MD5 198bcfb41a95e090d510c55b25c167c6
BLAKE2b-256 2aee959070db1e5e07b6bf46a13117040b723d1114a3300deee61cfb8bde5a33

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page