Skip to main content

Python library for bivariate, multivariate, vine, and stochastic copula models

Project description

pyscarcopula

A Python library for copula modelling: bivariate, multivariate, vine, and stochastic copula models for financial time series and risk analytics.

About

pyscarcopula fits bivariate and multivariate dependence models using copulas in Python. Alongside classical constant-parameter copulas, it supports stochastic copula autoregressive (SCAR) models where the copula parameter is driven by a latent Ornstein-Uhlenbeck process or Kendall's tau follows a bounded Jacobi diffusion.

The package is aimed at financial time series, risk modelling, and experiments with dynamic dependence. It provides bivariate copulas, C-vines, R-vines, conditional sampling, prediction, goodness-of-fit diagnostics, and risk metrics.

Supported estimation methods:

Method Key Description
Maximum likelihood mle Constant copula parameter
SCAR transfer matrix scar-tm-ou Deterministic OU latent-state likelihood
SCAR Jacobi transfer matrix scar-tm-jacobi Deterministic Kendall-tau diffusion likelihood
SCAR Monte Carlo scar-p-ou, scar-m-ou Monte Carlo alternatives
GAS gas Observation-driven score model

Install

pip install pyscarcopula

For local development:

git clone https://github.com/AANovokhatskiy/pyscarcopula
cd pyscarcopula
pip install -e ".[test]"
pytest

Core dependencies: numpy, numba, scipy, joblib, tqdm.

Features

Copula families

  • Archimedean: Gumbel, Frank, Clayton, Joe, including rotations where supported
  • Elliptical: Gaussian and Student-t
  • Independence copula for null models and vine pruning
  • Experimental models in pyscarcopula.copula.experimental

Vine copulas

  • C-vine pair-copula construction with fixed star structure
  • R-vine pair-copula construction with Dissmann-style structure selection
  • Automatic family and rotation selection per edge using AIC/BIC
  • Tree-level and edge-level truncation
  • Mixed MLE, SCAR, GAS, and independence edges within one vine

Sampling and prediction

  • Unconditional sampling from fitted bivariate and vine models
  • Conditional sampling for R-vines, including exact suffix/rebuild paths and runtime-DAG plus MCMC fallback for arbitrary conditioning sets
  • PredictConfig for explicit prediction options
  • Reproducible random generation via rng
  • JSON persistence through model.save() and ModelClass.load()

Diagnostics and risk

  • Rosenblatt-transform based goodness-of-fit tests
  • Mixture Rosenblatt transform for stochastic models
  • Predictive time-varying copula parameter paths
  • VaR and CVaR utilities in pyscarcopula.contrib

Mathematical background

By Sklar's theorem, a joint distribution can be represented as

F(x_1, \ldots, x_d) = C(F_1(x_1), \ldots, F_d(x_d)),

where C is a copula and F_i are marginal distributions. This separates marginal modelling from dependence modelling.

For a one-parameter Archimedean copula with generator phi,

C(u_1, \ldots, u_d; \theta)
  = \phi^{-1}(\phi(u_1; \theta) + \cdots + \phi(u_d; \theta)).

In SCAR models the copula parameter is time-varying:

\theta_t = \Psi(x_t),
\qquad
dx_t = \kappa(\mu - x_t)dt + \nu dW_t,

where x_t is a latent Ornstein-Uhlenbeck process and Psi maps the latent state to the valid parameter domain. scar-tm-jacobi instead evolves Kendall's tau directly with a bounded Jacobi diffusion and maps tau back to the copula parameter for families that implement tau_to_param.

The transfer matrix method evaluates the latent-state likelihood by exploiting the Markov structure of the latent process. The path integral is computed as a sequence of matrix-vector products on a discretized grid or spectral basis, avoiding Monte Carlo variance at the cost of numerical approximation.

For SCAR-TM-OU, transition_method='auto' uses a Hermite spectral likelihood except in narrow-kernel OU regimes, where it uses local Gauss-Hermite. In standardized stationary coordinates, the OU transition is diagonal in the probabilists-Hermite basis with eigenvalues rho**n, rho = exp(-kappa * dt). The observation densities are projected back to this truncated basis by Gauss-Hermite quadrature. This turns the latent path integral into repeated small matrix multiplications and diagonal scalings. See docs/guide/performance.md for the details and the available transition_method values.

Vine copulas decompose a d-dimensional dependence model into bivariate copulas arranged in a sequence of trees. R-vines choose the tree structure from data subject to the proximity condition; C-vines use a fixed star structure.

Examples and docs

Worked notebooks are available in examples/:

Additional documentation is in docs/. Method semantics are described in docs/guide/estimation-methods.md, and performance-related details are kept in docs/guide/performance.md.

License

MIT License. See LICENSE.txt.

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

pyscarcopula-0.15.0.tar.gz (247.5 kB view details)

Uploaded Source

Built Distribution

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

pyscarcopula-0.15.0-py3-none-any.whl (217.0 kB view details)

Uploaded Python 3

File details

Details for the file pyscarcopula-0.15.0.tar.gz.

File metadata

  • Download URL: pyscarcopula-0.15.0.tar.gz
  • Upload date:
  • Size: 247.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for pyscarcopula-0.15.0.tar.gz
Algorithm Hash digest
SHA256 645d1f31b106a5292c92e53b39116c9887a086a52003d915281b7b27c21c1dcf
MD5 96ff72111e67d43baa2ac9c2a2fb19cd
BLAKE2b-256 6652c3337e974b7acf51c4cbe9c82ede380bb71f3a1bc68deb807fcc7699a8e4

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.15.0-py3-none-any.whl.

File metadata

  • Download URL: pyscarcopula-0.15.0-py3-none-any.whl
  • Upload date:
  • Size: 217.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for pyscarcopula-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c9111e7d7416534b6c19702392fa4bfef49b7f4480d046476dc47bc79cc6496
MD5 0d3c09da44c5cbc08596b57c5e032bd6
BLAKE2b-256 d4d2172ff8b083efad3020b56cbf3c1631637fec97af4951cbc029b52b3d280f

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