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 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 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.2.tar.gz (367.9 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.2-cp314-cp314-win_amd64.whl (510.5 kB view details)

Uploaded CPython 3.14Windows x86-64

pyscarcopula-0.17.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (609.0 kB view details)

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

pyscarcopula-0.17.2-cp314-cp314-macosx_10_15_universal2.whl (830.3 kB view details)

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

pyscarcopula-0.17.2-cp313-cp313-win_amd64.whl (503.1 kB view details)

Uploaded CPython 3.13Windows x86-64

pyscarcopula-0.17.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (608.8 kB view details)

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

pyscarcopula-0.17.2-cp313-cp313-macosx_10_13_universal2.whl (828.9 kB view details)

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

pyscarcopula-0.17.2-cp312-cp312-win_amd64.whl (503.0 kB view details)

Uploaded CPython 3.12Windows x86-64

pyscarcopula-0.17.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (608.6 kB view details)

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

pyscarcopula-0.17.2-cp312-cp312-macosx_10_13_universal2.whl (828.8 kB view details)

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

pyscarcopula-0.17.2-cp311-cp311-win_amd64.whl (498.8 kB view details)

Uploaded CPython 3.11Windows x86-64

pyscarcopula-0.17.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (605.9 kB view details)

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

pyscarcopula-0.17.2-cp311-cp311-macosx_10_9_universal2.whl (824.8 kB view details)

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

pyscarcopula-0.17.2-cp310-cp310-win_amd64.whl (497.1 kB view details)

Uploaded CPython 3.10Windows x86-64

pyscarcopula-0.17.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (602.6 kB view details)

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

pyscarcopula-0.17.2-cp310-cp310-macosx_10_9_universal2.whl (823.3 kB view details)

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

File details

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

File metadata

  • Download URL: pyscarcopula-0.17.2.tar.gz
  • Upload date:
  • Size: 367.9 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.2.tar.gz
Algorithm Hash digest
SHA256 fe469fcb5f7e23b97e1a92821c90d7a5944be8732f6b619eee10dc8ea82f88fe
MD5 90608cff3491a0d565db4c2055d4af59
BLAKE2b-256 95d166179b9142830b0568e3d0b71f77d8ca490f3d669903a843c3b3600c6800

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 a92a76e4672d9c56b26df23ce366319d58de3daaf38a6bad13e4b64788eafadf
MD5 bde62484d411f946b057d9278033fa4c
BLAKE2b-256 2ffba8579e9e90e5ad93e40af9eeb878d5be82a3e2f4474184c33dd111538b89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 951f9682f79253aa8fbe68012298cfdc7f6499afb94d5497b4670db3cecf2841
MD5 e20293f2b8d7a10634427894ad602311
BLAKE2b-256 62e31f5b9728f460604a21f0cf2d1f4b817e5e6fe3569b048fb7eb8f50ffd047

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 8d93e8eb7bf7872aef9be2820fc5be7459c3caa05b9d48f82f75b379d50f6ee3
MD5 3bf1e78b2de10cdaab8a9dcd1944f6b9
BLAKE2b-256 fd32a6c41e3974a64f48505b1487b3aadfa52a9a8a0c9b128f1ed3e4117003d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 54ca8b958fbe03cbad957b8cf642b8b62b2bd9473e691177cd7b62062d8b0f7b
MD5 968eaa82d56808e7ddbba2f80e9452e6
BLAKE2b-256 3dd7e76a920cffe72a6a5b0b3fee323cdc434f3146aac8b114df026d04f6c009

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6e62894067e1978faaba3f525a40344d2068af16831c50cb8bcdb8832138faef
MD5 5f6c239b30facd2a78af4ecdc85f14a9
BLAKE2b-256 293db570490f3f7f960a58e948d42353e87f64c261e9becb1b286683e5892551

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 4a76d8b4a166efdf999e032fadd3db709568c46494e80fdc87d92cac347d62ee
MD5 9604ce5cf3a9b19017378040254905d6
BLAKE2b-256 05a2da60985b3a9e57ed1fa8d0f440a1c15da6463b8ea85e0ab7a966271220b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 92d58f17bb6e7531658da6a55a63ca1b9438584a92b3ea4b3651baf7fc48ae47
MD5 cd1048fc2591191014913938ba5adc6f
BLAKE2b-256 7c9e084d1af554fd323a9db448aa82f2f1309fd2f6d0dd99912aad1fa53ae392

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c4c49cf8bce98323d877ddd6c77e8877f8e52a9e71377024fe7639c7f082123e
MD5 6ec79a732654e67d639366c2aa15e516
BLAKE2b-256 41b34cef8ac1b2814e0ca17eff76a7daa85da2165bac9d12bf51a8306e73ad9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 c8aaabf0e1f7b4d7b46739aef710e70498b1cb57665f0f8b4fa18e838f832e16
MD5 fb682ac1e434292d6e5887198b050d6f
BLAKE2b-256 9419d72bb0fef9d2a162cd1ec4a706934617302799e73a01de142a716c8f07bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f1fd19fceb494ea5b31b0f877387114fe7009051db2fa5c3be05ed73b173726f
MD5 3ad08bb2e21c894b650d454d04364dbe
BLAKE2b-256 d9af0733fd6c1b7fee55e3a74e0a8a16bc340bad058e861cde1ddd48cc82f837

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5d8af19fa362bd724e89069aca4157d8a113019a79948d574d7da981067fcf7e
MD5 0fe6a4fbdd15bd716948758d00b630e9
BLAKE2b-256 65159a6b2d0be301402a60f7ca09cc40ba6d887db73ec65c98a684aa78d91efd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 408160ea28d34ec7bc859e8bc6dcffe7ab86b6da4d07c5eff1efc753a6c7a594
MD5 07e9ed19ad79e65b37a3238edbbf84c0
BLAKE2b-256 029b2fa61315d405b2a401719f65a3f2d2f02ed53ad970397cbb822b4f80787d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 521981fd62e6156d97661ade98b5d6c4e0497753499347240907129986816788
MD5 92f3b10d10c7715d64912fbfb9a3cb46
BLAKE2b-256 fcc5fba86d5977a9111460c11e958dead0a7f88dc81d157806fe4c14536dcf5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3e71e4e5831ebbcaaeaf136adbf348854f994229d200aca0dfd97de13c5351e3
MD5 68315c2948214afb80bdce982dc15fed
BLAKE2b-256 f2bdd8c34838611ac8bb1de8d6c37a50ad799312badc7787b4bbfaf3d28541d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f21e1919c298954402a71e0f5bfb0dc370adc113a29743ff1b5a88559af6b5f6
MD5 6c76be753c10d549e84d23bd3dcd7b8f
BLAKE2b-256 1bcbcbabe432c402b0ec050eb297cf4686b7a395b1121ac304ef41fe4266f848

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