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

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 checks are disabled by default. Enable them explicitly:

PYSCA_RUN_BENCHMARKS=1 pytest -m benchmark

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 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, including the matrix/local numerical fallbacks used when a spectral evaluation is not accepted.

SCAR-TM-OU uses the bundled C++ extension as its only production numerical engine. No backend argument is needed.

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

GAS uses the compiled numerical evaluator for likelihood, score recursion, state updates, prediction, and Rosenblatt paths. There is no backend selector or silent Python fallback:

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.0.tar.gz (365.7 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.0-cp314-cp314-win_amd64.whl (509.0 kB view details)

Uploaded CPython 3.14Windows x86-64

pyscarcopula-0.17.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (607.5 kB view details)

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

pyscarcopula-0.17.0-cp314-cp314-macosx_10_15_universal2.whl (828.9 kB view details)

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

pyscarcopula-0.17.0-cp313-cp313-win_amd64.whl (501.6 kB view details)

Uploaded CPython 3.13Windows x86-64

pyscarcopula-0.17.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (607.3 kB view details)

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

pyscarcopula-0.17.0-cp313-cp313-macosx_10_13_universal2.whl (827.5 kB view details)

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

pyscarcopula-0.17.0-cp312-cp312-win_amd64.whl (501.6 kB view details)

Uploaded CPython 3.12Windows x86-64

pyscarcopula-0.17.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (607.1 kB view details)

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

pyscarcopula-0.17.0-cp312-cp312-macosx_10_13_universal2.whl (827.3 kB view details)

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

pyscarcopula-0.17.0-cp311-cp311-win_amd64.whl (497.4 kB view details)

Uploaded CPython 3.11Windows x86-64

pyscarcopula-0.17.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (604.5 kB view details)

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

pyscarcopula-0.17.0-cp311-cp311-macosx_10_9_universal2.whl (823.4 kB view details)

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

pyscarcopula-0.17.0-cp310-cp310-win_amd64.whl (495.6 kB view details)

Uploaded CPython 3.10Windows x86-64

pyscarcopula-0.17.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (601.2 kB view details)

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

pyscarcopula-0.17.0-cp310-cp310-macosx_10_9_universal2.whl (821.9 kB view details)

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

File details

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

File metadata

  • Download URL: pyscarcopula-0.17.0.tar.gz
  • Upload date:
  • Size: 365.7 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.0.tar.gz
Algorithm Hash digest
SHA256 9bdeb209a4c02283e60912c0979dd15c83fadb8bf597db39f5461e9236e53007
MD5 8540353fe7902377c5429e654c73b928
BLAKE2b-256 ae711c3d2ebac35f28af9826de29e0b7f12cb0db502e3c576242bf5eeaf509cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 b2a72d25e0a7f53be7f59dba5c1f06be629e67cbbc798367f5ef7e0ff8b0edba
MD5 ba550ac79317a93bbea5baaa13343bd2
BLAKE2b-256 41c3948ff73d88ce81a8649c7eb16cfcff8003cfed7da133cd42af4782b1107d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 167051dd7bc1231d1d12f6cc51d5ae569d9a511cf1f99359c1f75d00cd98e76f
MD5 106a7fc48a1ad0568a2397d750507825
BLAKE2b-256 a83a427ef29c41b579b50b25545343e47853697546315c434570ae61ca091493

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 72f2c26e08ab085d31df5c87ee061e5712c9064c1a78fc6c99d98fbfde09a97e
MD5 7374823be9364ecd3de62bc0ad453695
BLAKE2b-256 c0d2047c044c252212782b4793c8732df0081cee6771822b00f883556f4a8c81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e08fac1deb27b12767c5c53cd0754dbd97327a740032ba188070523f4e404478
MD5 6e03a05c567b444f5cef0b29de2b62e3
BLAKE2b-256 7550d09e1c461a732ef97beb588293f9ce416c97190880abe1b93c1f180b15d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 093242d44de40b8fd47de6d84dd6289320161079ccba4a4225a77f1fc1cad33c
MD5 59e8366a18f9b59cccabd807613cca29
BLAKE2b-256 507266b986557d141a2540166b0e08d9769b67dd27a4455263d59ef71d069a63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 0c525a8a194cd45adf8e5b0f9551950d0de616a48694601838840b3212cf21b0
MD5 0bfb339fc880a784b460eed3c3f70a68
BLAKE2b-256 61ba99e2001de1d5aaa7a545abcd33923855668bf79d8f3df714246cb80c28ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b16ff3a6479b1c07fe8315f71124d9ac9d31accad3df2748329dd6e7f2d89996
MD5 835c26ebd4ab9b6a3ba607deb889580d
BLAKE2b-256 3ddb39c9a22da25eac41d7162d849235995036902eba61a19b5f6c818bbe80c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 136f41a5cc07856b8d3c3d8fafb0690bdb2ed1403c0df06c10fb7609d1a56d32
MD5 6181f2e10c5fe9ece05020022053fff9
BLAKE2b-256 ca76f1c213df3a9ab359ffbd3a71e69e6856ba5802563d8683f3b1f1c08f8456

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 8a75678e3dc84404dda2352aa9dac19e4d0885a5ef50f979cc80435f50749b6c
MD5 d4f0928d4ebc12b360084c176bf18779
BLAKE2b-256 6b2b003063c91e7bb4ecabea6a2eb85b4a54f889cae808ffe9f4ec79d07faed5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 575588f872362ca541ce837f69e78140f7625b759c26562313074f35e3bc7cbb
MD5 8b9379c385ea20ea41c75d53bb31d99b
BLAKE2b-256 e6e761fb67f664548f588a7eff435e8fe59d8f85496b31522d4a5f24e2b7eed6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c1acfa9d522085bcf3d45cc475ffda8732e7d55dab233e3c2a85db597f0491d8
MD5 72c475a93f6da964eb6e69dd403447d1
BLAKE2b-256 a718ecb41acc2fdf940c25f2f5b4198f9f6a8bd7c8e8da165d68fb5bab75fd36

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 08046019197052f87a74f58f4444579373b3a410ba84869713191f8175537254
MD5 1792750bfd9a5ee4aa5fb10a0b839816
BLAKE2b-256 9897160526f5e3fc8fa1c6ea87c16f38b01800cef62fe4e787c2787811997139

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d0c76a9389c130c912a3dec541db14abfbcd7f4bc42cc9fd967626f5ac1ffb46
MD5 3a17c532744493e88ffb154f968d0f54
BLAKE2b-256 0bbb18d306651b1e234ff56f09e878b26a827825052e8ea579079d126afa92eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5d3cdf55b476e92c82526e82b34bf82f2c671c7ff2fba56ebbf543ae94dd87cc
MD5 977b9b8c147cc115b7c45fdcb7da13f8
BLAKE2b-256 5c4d6117b6b21b6e1e39e50147109d3dd60951a2a004368225b1588098bf82e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c672fa5006ecb841233fb8d83d29bc4ce9e04d45629841aba8cbba99cc431ffd
MD5 4443ea98c9d7405bd4743c15ddfa6d0e
BLAKE2b-256 b3bdf996fb186109bb03be6f1cfce05c237aee2c0931d8c1743c8e9182159149

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