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 pybind11 C++ backend for SCAR-TM-OU. Wheels 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. C++ backend tests are skipped when the compiled extension is unavailable.

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

PYSCA_RUN_BENCHMARKS=1 pytest -m benchmark

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

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
  • Experimental models in pyscarcopula.copula.experimental

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.

The default SCAR-TM-OU backend is auto. No extra argument is needed: supported copula/transform combinations use the C++ extension when it is installed, while unsupported combinations fall back to Python/Numba.

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

Use backend="python" only when you want to force the Python/Numba path, for example for debugging or numerical comparisons:

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

See docs/guide/performance.md for supported C++ 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/. Method semantics are described in docs/guide/estimation-methods.md, and performance-related details are kept in docs/guide/performance.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.16.0.tar.gz (299.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.16.0-cp314-cp314-win_amd64.whl (464.8 kB view details)

Uploaded CPython 3.14Windows x86-64

pyscarcopula-0.16.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (495.2 kB view details)

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

pyscarcopula-0.16.0-cp314-cp314-macosx_10_15_universal2.whl (690.5 kB view details)

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

pyscarcopula-0.16.0-cp313-cp313-win_amd64.whl (460.4 kB view details)

Uploaded CPython 3.13Windows x86-64

pyscarcopula-0.16.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (495.0 kB view details)

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

pyscarcopula-0.16.0-cp313-cp313-macosx_10_13_universal2.whl (689.0 kB view details)

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

pyscarcopula-0.16.0-cp312-cp312-win_amd64.whl (460.4 kB view details)

Uploaded CPython 3.12Windows x86-64

pyscarcopula-0.16.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (494.9 kB view details)

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

pyscarcopula-0.16.0-cp312-cp312-macosx_10_13_universal2.whl (689.0 kB view details)

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

pyscarcopula-0.16.0-cp311-cp311-win_amd64.whl (457.4 kB view details)

Uploaded CPython 3.11Windows x86-64

pyscarcopula-0.16.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (492.3 kB view details)

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

pyscarcopula-0.16.0-cp311-cp311-macosx_10_9_universal2.whl (684.8 kB view details)

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

pyscarcopula-0.16.0-cp310-cp310-win_amd64.whl (455.2 kB view details)

Uploaded CPython 3.10Windows x86-64

pyscarcopula-0.16.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (491.0 kB view details)

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

pyscarcopula-0.16.0-cp310-cp310-macosx_10_9_universal2.whl (682.2 kB view details)

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

File details

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

File metadata

  • Download URL: pyscarcopula-0.16.0.tar.gz
  • Upload date:
  • Size: 299.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.16.0.tar.gz
Algorithm Hash digest
SHA256 285bca3fbe3e02b7e6c0985c291c02fd37785dcad2214e7c1644d4eedf76d80d
MD5 fa5f5e30ff926c0b2e4c5c643c382aa3
BLAKE2b-256 7edbd9b51a80704f232184ac21a883cfa659dcf87e518060bfa9eb62b4807121

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 bae5551ebad57638f8dabab0d07042d26b1ad7e228229757949b351e9b261b6b
MD5 4f62a0fb54b52523012fa0dcc5ebb59d
BLAKE2b-256 53aedba3744e7ac686ffb8c0e2320dc942e0dc9e43e712afd8776991aeba742f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 394ac38bb71f42bd46db0503e63ac64e38b6204f44dd1e2b3903fc17a89204ff
MD5 a6fcfb124760e24d43f8caca8df0b64a
BLAKE2b-256 1f298833bdc283a7319761e1ad34b192d3fe0a5be4fc66d965618ff8e2784ee4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 bc79b8a428bda05b45efff77051460c678e8a00e2217698ebc9cb835baaabec6
MD5 dcc95ccf7450994f9d4b72a03c1c369b
BLAKE2b-256 7a34c78680f93fafc0bc05eb2d1aafc4ac4da8953b070f711b87df788d55caf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2d7f0e7bf00248bd0ffe744220bbd369b78d08960c476fe23d12d76f42337039
MD5 dffa36ce3ef591d92134d50c090e9374
BLAKE2b-256 d13dbd80e86fd562af5e59031168e25761d06a45b101cd7ea87922371a9515fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8b3c9ed3a43056306574b4ad121807c1a6b9564d9f52633e0cbfb4281e89259e
MD5 5c63cd031e916cd9d45d67c2f9e44a7f
BLAKE2b-256 09d82a56e0a5d631cf0375358b83c400f2f8a0bea14d3a525a696c8c14557372

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 9a84dd585238a83c039edeeb0dd12b2da22eaeb7c967b1916e8c8ceb388bc633
MD5 0660aff7392f9f877ec7d2948c494100
BLAKE2b-256 cb13eaa529cc2f010f411a147bde5f7c626a3f21d899a419a32669f78433d968

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 261ea11cca3541aad1eb656f05436faa993e1e6ca5d2f9fcb7aefba8cc8c1ac7
MD5 5383b8d520231302acf69a8eb52bbc47
BLAKE2b-256 d7bedbde4aa918d391a029fc5a8ec3cd48ced2a12538952e6342ad86c8fe4e10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 466255d880a2119b06374e6ae7c433e9f922c2b40e35e7e682b95004bd082099
MD5 13966984cf55bf24c5ac30eaa2f77f97
BLAKE2b-256 5de7582442603344118b4a84c5bd0fe928a19fa3466955e663bf89ebb64f5342

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 ac699866cb535f890815202dd90f433d3dc9aaff79ed94fbef54949a44bd8327
MD5 d2823a72fa21066f8bca18bae273acfb
BLAKE2b-256 fb6881b1a039952c789c78164dd69a53fda9d13394a52277a57ea4bd84632340

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fdd5c77c3a5a8a0aa0ea4e81aec83d5b41db3cc35e0fb15ebf0d3abcb2049fc7
MD5 42d4e8af02b27636c7ae5b4b884ec5d0
BLAKE2b-256 295b6abcaf10ee7d3cf95a489429dc3bc811858a243e85557759a946ca78dc59

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ffaf07f7a4242009b7a30b45963ddd869a6f1bc4437194e16de3ff0a9fa686d9
MD5 603ef70e25ab2abec08a5dbd3e9d6333
BLAKE2b-256 b6157bcbff408eb16b55b423c3e6aa24b345b724b6f5b999b90060310c34de10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 1c44027c0a37dea6b849317c3e2a2e0015adedb928916980fbccd56704782177
MD5 91b781cdd6ffd77721fad2989521c082
BLAKE2b-256 285c5ff7fbea6b82e8f9d6fa2053d59267b15449e3cb04ad6a5e3feb009e6edd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 feee1eac6c756b03cf2a4c5781fb25218e1f722c1ec2671d9b50e9d30bc3caf6
MD5 7f950975a847d20173d6ccb875bc4ffe
BLAKE2b-256 8c75b157be1ea895d629dce9abf8880e35a491797700dc237e6ea703bb9e444b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1df5f0d682705492c6e32d3fac371c68f8a41cf112f0c53bd2e4bafd26d9fff0
MD5 5a67b1ad073c92097d4494cdcc54375f
BLAKE2b-256 231e2821772c2a85ad469ae3c5ce495d2122981d6e6bdc7f4f857b50f686c876

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.16.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 7a6910f8bc0c6d8dab434d5f3d7930aaea8edf8d7c4bf1f20f4ff2c308ef8216
MD5 08f2d9c2b97f63a60513b970692e2c3b
BLAKE2b-256 845c46e605ecb7096ea348682724c3a3f7c68bc0398f7ff0b7f974def5b6dddc

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