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

Official wheels include the compiled numerical 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 the compiled extension 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
  • Shared APIs for bivariate, multivariate, and vine models

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, with exact and approximate modes
  • PredictConfig for explicit prediction options
  • Reproducible random generation via rng
  • JSON persistence through model.save() and ModelClass.load() (include_data=False can omit stored training data)

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.

result = fit(copula, u, method="scar-tm-ou")
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 families and numerical options.

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/. Estimation methods are described in docs/guide/estimation-methods.md, and performance-related details are kept in docs/guide/performance.md. Release history is in CHANGELOG.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.5.tar.gz (6.1 MB 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.5-cp314-cp314-win_amd64.whl (525.0 kB view details)

Uploaded CPython 3.14Windows x86-64

pyscarcopula-0.17.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (635.5 kB view details)

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

pyscarcopula-0.17.5-cp314-cp314-macosx_10_15_universal2.whl (879.9 kB view details)

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

pyscarcopula-0.17.5-cp313-cp313-win_amd64.whl (517.3 kB view details)

Uploaded CPython 3.13Windows x86-64

pyscarcopula-0.17.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (635.2 kB view details)

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

pyscarcopula-0.17.5-cp313-cp313-macosx_10_13_universal2.whl (878.7 kB view details)

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

pyscarcopula-0.17.5-cp312-cp312-win_amd64.whl (517.3 kB view details)

Uploaded CPython 3.12Windows x86-64

pyscarcopula-0.17.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (635.1 kB view details)

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

pyscarcopula-0.17.5-cp312-cp312-macosx_10_13_universal2.whl (878.6 kB view details)

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

pyscarcopula-0.17.5-cp311-cp311-win_amd64.whl (513.1 kB view details)

Uploaded CPython 3.11Windows x86-64

pyscarcopula-0.17.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (629.6 kB view details)

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

pyscarcopula-0.17.5-cp311-cp311-macosx_10_9_universal2.whl (868.3 kB view details)

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

pyscarcopula-0.17.5-cp310-cp310-win_amd64.whl (511.5 kB view details)

Uploaded CPython 3.10Windows x86-64

pyscarcopula-0.17.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (627.0 kB view details)

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

pyscarcopula-0.17.5-cp310-cp310-macosx_10_9_universal2.whl (864.7 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for pyscarcopula-0.17.5.tar.gz
Algorithm Hash digest
SHA256 15f042b2c248474600a26bf929a214d024c60b93e9765bc9c5bf8af606a6ae59
MD5 26ebfab68b8d4c7dd09ac3e0696df343
BLAKE2b-256 18994cf3d6239d16676799c062e8a016207c026bde4fcddb4260eeff163343b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 ed16d4a018adff7a4275bfc9ff4b1560ba9c3e04e82663afd5a2377e653b9c2d
MD5 8f52d0504f7ad5cdd0c4ba02349b3374
BLAKE2b-256 1960a909984fb985c31a8c26cecb8923d2740426b22561afff70af6b9410d2ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 087e832e311bd98e8d4f2622728a268546800af57b7b7a8c1eb34656f89b6deb
MD5 c227c5af9a123c7a07ced91353d9bca8
BLAKE2b-256 d3b119fbd3701ce4239b407951e18885015c126df49de5bb7b1d29093a34b9e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 35e43e5285b0fb8ddbefd0101bd0d6b03922d64583535a19520db3fd438c55c1
MD5 0f2d7156e7ced909f1b8154f2a04fb8f
BLAKE2b-256 b61030fb01144644d346dc956d7cebc7c9ce42b192b8ac5cb5173a0a6c90344e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 24a311ebe0b6e90963a5ea1d9fedc8d5e6af86bce4f9bd23ba7feb7cb9667298
MD5 215ca3a20460b9cbec53e0326ea0bb72
BLAKE2b-256 b6018e16f1a899a8213d47ac96c6a057ea665d3f016a31fdb7c589aee498b7ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 03ef8a70d015e3d36ea37c8c29903d7c364dc8a4f6856ee71ff8ae8e7042b0fc
MD5 2072a3342af08feab2a0d2381a1091cd
BLAKE2b-256 136c6e4782499033a2ed56ed340bb5b7a6612ed1da8a052a9ba5a26156a98af5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 eb684d17d229f34306461470370b838a5353bb35589af5bc4039175a61885d97
MD5 ea6b91e1f4aba127e924de037e9fe03e
BLAKE2b-256 13dc198f6c5bd4d1f20ac503bd563097eed166c1a05f345911acdf63bf3725d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6867ef889910684061212cbf1cca0e1cf0a281ec6078d5a5899b6ea23bbc636e
MD5 9ca4f9fa5576531a3d7569d6c6d16d04
BLAKE2b-256 d1b9b12aa829d731e0d720042e1cbdae0a027b22f78173dd7f3cbbdce64f8ecd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 977819f9b0b247d1a38e6b69ef046fcb623963ef4a3531339dfdfac485eeb2fe
MD5 569ea9ce91642abce1e0921284690bc5
BLAKE2b-256 bdcfb23f21848699b527fee683f1b609d9198c8ee588fb0ffab7ffdc6cdd9645

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 b1acf00a8bc2ba54736fee58a4f9ce384146b2a94a6915ad52295a426021d1b4
MD5 f9a96e9da9b12a3c5864c4685c8f797c
BLAKE2b-256 9ea940cc1b14e4142f199e9bc2569548b4901e3475cfba8b6c5342a276f9cefc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 66b510ccc37971a6b81e0268f775b03b9b2016fc80874e20434d250efd2ab6f6
MD5 45ddd563d2127bfbdc89758ff0ff42e0
BLAKE2b-256 632726b70d8ce2f36b6f94bfa0185c2b7e896629969b7a7d9164180442c37022

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0a7eb635df31a5a3acb4198945ed2c61b660db087610f331f441961c0c780d46
MD5 5ca3af50eeaed28071965968b1884621
BLAKE2b-256 54bb19215e286092f1fdd62e644954fa6ed6639ddbf5b7dc5c2ba7fac70ba332

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6752ec5bd498cdc5aef04ebb416310931242708909a862e585fba9390b92e4ea
MD5 89395e57f302a9317fb7d40c0a72caf6
BLAKE2b-256 bab132dd32895cca101d5fd831b77edcb9dc3dcb9deebc2c95d55a4e5753ca83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 59e2cb51682de7fcc9ce18deb6221472c967acb1c8f1f553c915bc1b8eefd34b
MD5 4b52b19c8233c8b4195c77ded1214834
BLAKE2b-256 886e3838ca1743e4fe32dafda79bcb02cfc30f99513b594033b68091c8a8c15c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ddab74f2afd9a449bb5a936491036583a79bbd3aa46c7b175965cfa9f2c3bbe7
MD5 d2652e4e4bace663767f86450890bd2c
BLAKE2b-256 ea4b4dc726de62c3639f1b070740e3d693d29d7c4ce8b219e605d802d3f493e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.17.5-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3b340bfb4963cf651dcfde196fa36244f79ffe85d444f1e8ab5c629940b96bfb
MD5 62c0b04f009c2095f69807ffca797768
BLAKE2b-256 18dbfb8e97d010741314dedf6889534c090cc73d7e23c250074ea81907e52713

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