Skip to main content

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

Project description

rscopulas

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.2.tar.gz (93.1 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.2-cp313-cp313-macosx_11_0_arm64.whl (567.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for rscopulas-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5fc573079c1061e3c701fa1fae5e6a573d7bdd460c046bdbc6b265292ac7b31b
MD5 9bbc9692923233c5850025cd464a1c62
BLAKE2b-256 86dfcfd7fee75b264e3b5f186f5b23a3926af4f49bed4201296988903ea253aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rscopulas-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fcca43063e305af0713813ecf03c28cb3df7303f89d0e051e14f61d6ed0f08e5
MD5 a9556eb7c934ea669b270b31a17c6ef1
BLAKE2b-256 6e8e8b11a55bc43e179618592dbad3e200b29b4de39f94dfeb509a154a67b3e0

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