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:

$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.3.tar.gz (382.6 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.3-cp314-cp314-win_amd64.whl (522.4 kB view details)

Uploaded CPython 3.14Windows x86-64

pyscarcopula-0.17.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (633.0 kB view details)

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

pyscarcopula-0.17.3-cp314-cp314-macosx_10_15_universal2.whl (877.2 kB view details)

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

pyscarcopula-0.17.3-cp313-cp313-win_amd64.whl (514.7 kB view details)

Uploaded CPython 3.13Windows x86-64

pyscarcopula-0.17.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (632.6 kB view details)

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

pyscarcopula-0.17.3-cp313-cp313-macosx_10_13_universal2.whl (876.1 kB view details)

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

pyscarcopula-0.17.3-cp312-cp312-win_amd64.whl (514.7 kB view details)

Uploaded CPython 3.12Windows x86-64

pyscarcopula-0.17.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (632.5 kB view details)

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

pyscarcopula-0.17.3-cp312-cp312-macosx_10_13_universal2.whl (876.0 kB view details)

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

pyscarcopula-0.17.3-cp311-cp311-win_amd64.whl (510.5 kB view details)

Uploaded CPython 3.11Windows x86-64

pyscarcopula-0.17.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (627.0 kB view details)

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

pyscarcopula-0.17.3-cp311-cp311-macosx_10_9_universal2.whl (865.7 kB view details)

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

pyscarcopula-0.17.3-cp310-cp310-win_amd64.whl (508.9 kB view details)

Uploaded CPython 3.10Windows x86-64

pyscarcopula-0.17.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (624.4 kB view details)

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

pyscarcopula-0.17.3-cp310-cp310-macosx_10_9_universal2.whl (862.1 kB view details)

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

File details

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

File metadata

  • Download URL: pyscarcopula-0.17.3.tar.gz
  • Upload date:
  • Size: 382.6 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.3.tar.gz
Algorithm Hash digest
SHA256 9ac95246c02c2108208816879a3f7686ad5ec3184ecbe7e732ab87dc9af91e32
MD5 b015857223844e85e7ee0e947da1ceef
BLAKE2b-256 1c13c51f731c7991b0b37b123b63a7100b28fb9b61bfadf00da2dbfd9b1146e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 32efb05df752f2a503d468f0ef00f745821a24a6b2de4d5aa053617edf371385
MD5 0abe8fd4da5dbda2f758ecfb7ef08239
BLAKE2b-256 20cc6611ff5f3604a81a3c0b008c90e18144b8bd66735b150a42a78e3b8445a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bcf58a6e0f9569400a080a6357e921979e20936dc2c52c5d38bd031aa1538d65
MD5 07eca522e6075fb27874dff165dd2242
BLAKE2b-256 753cbb89eebbb5f562d2b7ada460baf6566dbdf3e65f9735e66bf882abd3e015

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 a057767ca88e9f28b5d12c5395627f04984efa00b7c0cf8763e4713720b51ceb
MD5 cad362ca7ba0d1d0b694f66c6e7cba6a
BLAKE2b-256 2ee4076c6c9e8ad039e7c4a18bd07d0d8bad2954261d7b7edf3a8540274a280b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5850486744ccdcda34a4cd940efc9c013d7d788bc2873717d5a8869a31b19b08
MD5 48b355b7b09b21bee155635c9b0cf9f7
BLAKE2b-256 9f2036ec9e183a7411eec9367ef73a0be8a2e4db6c03fecfab4678aa091cf35b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ada37483f234222459f176a26baf573a297a820750f35402ad20879f98268d33
MD5 04f8ae3cea542190c7460771792471a2
BLAKE2b-256 2751013473ddfb9e65e33e938312d717c5d5f2d591a0f563d85bf7ea88be3b5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 3e46ce634b7c8093029b944ea9cf8d6a136391911d55aaa92f9437d960ba9163
MD5 04c6a47fcfb061dc6852adbc7022fa3e
BLAKE2b-256 dd6d2e8fbcdbe2798304dd36648613de233516fb87b34a9b793a8699c9b3eac3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1046f8bb3d66c8fac36f0c5c0b818cc1574fd0e56044faf881819658bbd075e2
MD5 15e5c276935138fe37e514e170aba27b
BLAKE2b-256 35fe88d8d45b2458bcb63fe1dc2e24a9ebea433d314a2f5ff6832a7c60c6b787

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0473feb494d14b870b9b842a6efa47cf7e9b757897b6d28f654f0e0d4cc591d9
MD5 f53854ea417177697ae841b1e0ee9fc4
BLAKE2b-256 fc63b3b41b841fa8ade2c6f4c684b61fdd76f9228d31b966779c41323b741de7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 33574538e90bfe7e8498c996c6fdba6f39befb5cb0bb89e1a07142ebaaf41eff
MD5 19f6906b2d9efb50b4c131168d7ea529
BLAKE2b-256 21029e20b22a4c8191d5477a07752d1cd978c22a050605cfa4b4b408ee1c140a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 baa34219c89f1acafd7c281ff6665fead7e0ff7054a9e43bf4d0b2552daeabb4
MD5 ee7bf6596a564ebcd8bb1234248f9c4f
BLAKE2b-256 c4dfc7a702ef49fb6c8998013e85b7f25fa6d046061f27e016a036878b88d7a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ed26cc7c07dea18e2c858448f66f5ad00487ce5f24d0c17bc751d1159fc82be6
MD5 611b5cef721062d35fae76aade3bb756
BLAKE2b-256 a23723d3757a570bf181ed66677c7076ccc4c9685f16708176a1094dddcb19db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d192d8ff0a2aee1bdb5b426a5cc844622accc3f9ccca71e8cfe2ff658b67017e
MD5 ea168d0bb795473d3b71261730fc265d
BLAKE2b-256 f2ca389b9d8e79d0f381cdbca3e438c5c553515d7aa94bda9fc6a352c61d83ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2ff798606ccd26883030996de101da449ffcd312f15d1e7435298957d582b01a
MD5 f83eab3f072e8af3cdeec494fbbc8108
BLAKE2b-256 ab9465048f44ea430ddc930469a16fbf7db5d7aab4f8400ceabd646e42c74208

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a652d8d2b316e88353a69339a153b018369cbea7715ad175a3ec1ee7675c008c
MD5 56c0696931ed84c97de7e5e76e23cbde
BLAKE2b-256 fbb0a66d33cd407a19fc979f169e924e2bebb1821af7b93672ca1c2d5040a2c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.3-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 a311514a5151dee18bf49ac42a2c0fac4647e12367b52c7b93cfa4fd0cf0798c
MD5 c4be700ebe82a7e91757d81cc99eda8e
BLAKE2b-256 508a7156f1c5a41538e0fb0e9d2a7f83187c441d1e57ead629bd4ce672891b8a

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