Skip to main content

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

Project description

pyscarcopula

A Python library for dynamic 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

The package includes a required pybind11 C++ extension. It provides built-in copula kernels, static likelihoods, GAS, and SCAR-TM-OU numerical evaluation. Official wheels bundle the extension and do not need a local compiler. Source and editable installs require a C++17 compiler:

  • Windows: Microsoft C++ Build Tools / Visual Studio Build Tools
  • Linux: GCC or Clang with the usual Python development headers
  • macOS: Xcode Command Line Tools

For local development:

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

To run the full test suite from the source tree, build the C++ extension in place first:

python setup.py build_ext --inplace
pytest --run-validation

pytest --run-validation enables optional validation tests. A source checkout without a successfully built extension is incomplete for the default bivariate GAS workflow.

Optional benchmark and large validation checks are disabled by default. Enable them explicitly:

PYSCA_RUN_BENCHMARKS=1 \
PYSCA_RUN_LARGE_BENCHMARKS=1 \
PYSCA_RUN_VINE_BENCHMARKS=1 \
pytest tests --run-validation

On Windows PowerShell:

$env:PYSCA_RUN_BENCHMARKS = "1"
$env:PYSCA_RUN_LARGE_BENCHMARKS = "1"
$env:PYSCA_RUN_VINE_BENCHMARKS = "1"
pytest tests --run-validation

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

Verify a native installation with:

python -m pyscarcopula._native_smoke

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
  • Multivariate Gaussian, Student-t, equicorrelation, and stochastic Student models
  • Explicit CopulaBase / BivariateCopula / MultivariateCopula hierarchy with capability-based strategy validation

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 hybrid deterministic strategy: Hermite spectral evaluation where it is reliable, matrix-based transition evaluation for regimes better handled on a grid, and local Gauss-Hermite in narrow-kernel OU cases. In broad terms, this keeps the latent path integral as repeated deterministic linear-algebra updates while choosing the most suitable transition representation automatically. See docs/guide/performance.md for the details and the available transition_method values.

SCAR-TM-OU uses the bundled C++ extension as its only production numerical engine.

result = fit(copula, u, method="scar-tm-ou")

GAS uses the compiled numerical evaluator for likelihood, score recursion, state updates, prediction, and Rosenblatt paths:

result = fit(copula, u, method="gas")

Use the default scaling="unit" for production. scaling="fisher" remains an experimental, numerically sensitive mode.

See docs/guide/performance.md for supported C++ families and numerical options.

Custom Python copulas remain useful with custom Python strategies, sampling, and diagnostics. Built-in native production strategies do not execute arbitrary Python copula kernels: unsupported classes fail before optimization.

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. Migration notes for the native-core and multivariate namespace changes are in docs/release-notes/native-core-migration.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.17.4.tar.gz (382.1 kB view details)

Uploaded Source

Built Distributions

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

pyscarcopula-0.17.4-cp314-cp314-win_amd64.whl (521.9 kB view details)

Uploaded CPython 3.14Windows x86-64

pyscarcopula-0.17.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (632.4 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyscarcopula-0.17.4-cp314-cp314-macosx_10_15_universal2.whl (876.7 kB view details)

Uploaded CPython 3.14macOS 10.15+ universal2 (ARM64, x86-64)

pyscarcopula-0.17.4-cp313-cp313-win_amd64.whl (514.2 kB view details)

Uploaded CPython 3.13Windows x86-64

pyscarcopula-0.17.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (632.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyscarcopula-0.17.4-cp313-cp313-macosx_10_13_universal2.whl (875.6 kB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

pyscarcopula-0.17.4-cp312-cp312-win_amd64.whl (514.1 kB view details)

Uploaded CPython 3.12Windows x86-64

pyscarcopula-0.17.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (632.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyscarcopula-0.17.4-cp312-cp312-macosx_10_13_universal2.whl (875.5 kB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

pyscarcopula-0.17.4-cp311-cp311-win_amd64.whl (510.0 kB view details)

Uploaded CPython 3.11Windows x86-64

pyscarcopula-0.17.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (626.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyscarcopula-0.17.4-cp311-cp311-macosx_10_9_universal2.whl (865.2 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

pyscarcopula-0.17.4-cp310-cp310-win_amd64.whl (508.4 kB view details)

Uploaded CPython 3.10Windows x86-64

pyscarcopula-0.17.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (623.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyscarcopula-0.17.4-cp310-cp310-macosx_10_9_universal2.whl (861.6 kB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)

File details

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

File metadata

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

File hashes

Hashes for pyscarcopula-0.17.4.tar.gz
Algorithm Hash digest
SHA256 11dada2b484b14ca530d56d84cf5391f54193d61c1ea89a780c2feec7fc31a8d
MD5 ec6646c582df016adf357e43202b6d7d
BLAKE2b-256 1d462aef3dfa2459bc7a8cc291b2c68b0cb89e7f797a31c1d9bf35f1145de0f0

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 cecd9c2b050df41288890eae06a37c57a8eace5a2571b01f0bbcf29cd57b00e4
MD5 c65a59896161c4e3d3845cb5d5918e96
BLAKE2b-256 1ec4749cced16225c4cc01873994c377721767e4689553eb1275ce67625381e8

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7ab2c5a4774ac4b0e0e441b8db396967c770e56b9477935e0485375e99054b18
MD5 e1751c9ffe1957274d1a457a0cb3a787
BLAKE2b-256 f82bd742a31288deb46c580e831d50a067307480c25fa88f6f302f8b4203dbbb

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp314-cp314-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 f67420683b2356c66c5ab3b8b98cf9bae5d93cd8702e5cf6d0d7b2893b5e0460
MD5 ed310db97a9492ac5bae5206b27ce269
BLAKE2b-256 a74593c75c464e54ce3003b6c7a8d9cd0a900ce4aba4d1f6b1120b3b26e82035

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e396d58ee1c65dd1a2d9c598d5c6eaf933c2af22029b00a9c7ccd6407538bac6
MD5 7c73c82499bb57200bea04aa3fc80374
BLAKE2b-256 7ccad51621e0efd3f4f522f3bc9b8648ac6c6268d57c4e92b345f6f4e9143f7a

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5009300c757fd63e3db01f1c10c986382e423012a9687be2aa105d2213603fd7
MD5 0691016883ac7c101c3fbb97bf29ed5c
BLAKE2b-256 9beb54e027f093b06fca9504bb008ebc3ae4746b66702278c2a43808d0450c88

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 a865fc49750a2232dbe6d38234464dee4cf1f65d0eca2da40db833776d548f27
MD5 312ef21f18c664bf9604bae5d1d7edbc
BLAKE2b-256 e493ffe7f251a8b14d927656151a27ea4e734113151d0cbd3d7ca91165e993b5

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3c3af5ce55b3a3022691e5da6a7e8c35075b700ed47bba538b43490a96d6d2e9
MD5 11ecd15d03952ad6f0b1901304a0c675
BLAKE2b-256 1810ed3c25c826f387ad7225493b166e3ea95d4a27f4099febfb8314459852f4

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 513fb3d56849fe785b54b4f518a5ce9bf6ff83a18fde6b2ed041591ff311f68b
MD5 28d09ba38d04ba030df21e34864ec36d
BLAKE2b-256 c5b70138d5b0f9687b4b1ba0dbb1a20b8bca5f225870c12fc0d8bc73e487cd50

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 ea869fe58da61bfe6389848099a0291502a8764c5e898c328cc2f05b0a492159
MD5 71c73def90dd0ae7a2a5fdfa4a9fba94
BLAKE2b-256 22bc18850c7c9d9b0c76a5f225485ece837f453e08b5072fc8de96badb4fc62d

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1d5828c6cdbeda681e3bc85eadb8e29e7a2d55d09a1fa9d627c532ebe70ef441
MD5 8f1ca90ba90eb554882e05339cdfb528
BLAKE2b-256 41cf46eccd66a8727be17a9e1d2ca9d1072ec2aba6208c8c7493defec77aabd1

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 01225e35d222dd63f31a9c4874bc55f6078b1cc5d34761a62441f419a6d05246
MD5 3e9cf669c38da957362ace4cb7995947
BLAKE2b-256 133a7858c93d0fd8092cd25dae6b5cb46c415abd11c32ca675fca806ba84bfe4

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e521bc43a9641fd02ae9254c572667f58665ba0174efd5fc6b6710dc2efc589d
MD5 156da27ea20e27c4f0e82e899ac2ac12
BLAKE2b-256 dd4db3ba0d4a11884c013e3bbfd9aaa434ebfba8c87c457c9eb8df7c56450f4f

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5099658108db01c076eb5a41ea16e5e26565e7b61561d878159dd107e700a8fb
MD5 56917dfb71ceb3bcd1a95d932a3e9275
BLAKE2b-256 af88cc11ccc43dcc9c09c0f3aaf05ed43299d3915be410d82c453203e2f7495b

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 093282cebccbbea6ed4a9df1e958ea63825a4f332bc885c7e77c9cb4f579f880
MD5 21f41eb0b619f1c201be045a23742c08
BLAKE2b-256 db1cf2f609277ec7c1071a8ab6596a7363209f00c0ec3ae8f9d1281177b79200

See more details on using hashes here.

File details

Details for the file pyscarcopula-0.17.4-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pyscarcopula-0.17.4-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e6d91cbb3c4d40b847bed5f750a5f1c9ef268e5cc16c0687e436fd5494c2ad3b
MD5 b006719226ed41946fd69289b04604fb
BLAKE2b-256 2c4c1751e026efe0a6ec79b925fba979a64d60bad90a6a02dd4bd07e9a78d745

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