Skip to main content

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 Static/constant model parameters
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, or MinGW-w64 GCC (see below)
  • Linux: GCC or Clang with the usual Python development headers
  • macOS: Xcode Command Line Tools

On Windows, a MinGW-w64 GCC toolchain (for example the MSYS2 ucrt64 GCC) can be used instead of the Microsoft compiler by opting in explicitly:

PYSCA_CPP_COMPILER=mingw32 pip install .
# or, from the source tree:
python setup.py build_ext --compiler=mingw32 --inplace

The GCC runtime is linked statically, so the resulting extension does not need MSYS2 DLLs at runtime. MSVC remains the default Windows toolchain.

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

VineCopula quick start

VineCopula is the primary API for regular vines. Omitting structure selects an R-vine from data; C-vines and D-vines are fixed RVineMatrix structures:

from pyscarcopula import VineCopula
from pyscarcopula.vine import RVineMatrix, cvine_structure, dvine_structure

# Data-driven regular vine
auto = VineCopula().fit(u, method="mle")

# Fixed standard structures
c_vine = VineCopula.cvine(d=u.shape[1]).fit(u, method="mle")
d_vine = VineCopula.dvine(d=u.shape[1]).fit(u, method="mle")

# Any valid regular-vine tree sequence, without writing a raw matrix
structure = RVineMatrix.from_trees(d=u.shape[1], trees=my_trees)
fixed = VineCopula(structure=structure).fit(u, method="mle")

Use vine.structure for the RVineMatrix and vine.natural_order_matrix when an integration specifically needs the natural-order runtime matrix. vine.matrix is a compatibility property. The raw pyvinecopulib matrix uses one-based labels and the opposite tree-level order above each anti-diagonal entry, so it is not obtained by simply adding one. See the matrix-layout conversion.

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

  • One VineCopula runtime for auto-selected and fixed regular vines
  • Fixed C-vine and D-vine factories backed by RVineMatrix
  • Arbitrary valid structures built from decoded tree edges
  • 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, multivariate, and vine models
  • Conditional sampling for static and dynamic multivariate models and R-vines
  • Exact and approximate conditional modes for R-vines
  • 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

CPU parallelism

  • Explicit native threading for eligible multivariate row, emission, conditional-sampling, static-likelihood, and Monte Carlo kernels
  • Process-level fit_independent and rolling risk_metrics execution
  • Absolute one-thread default: omitted n_threads always means 1, regardless of environment variables
  • Dependency-free C++17 linear algebra without hidden BLAS or OpenMP pools

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. VineCopula() selects a regular-vine structure from data subject to the proximity condition. VineCopula.cvine(...) and VineCopula.dvine(...) use fixed standard structures, while VineCopula(structure=RVineMatrix.from_trees(...)) accepts an arbitrary valid decoded tree sequence.

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. CPU threading, process workers, thread safety, and scaling limits are documented in docs/guide/parallelism.md. Release history is in CHANGELOG.md.

License

MIT License. See LICENSE.txt.

Contacts

Contact me for any questions or discussion aanovokhatskiy@gmail.com

Release files for pyscarcopula 0.20.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyscarcopula 0.20.0
File Size Uploaded
pyscarcopula-0.20.0.tar.gz 6.4 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for pyscarcopula 0.20.0
File
pyscarcopula-0.20.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
pyscarcopula-0.20.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
pyscarcopula-0.20.0-cp314-cp314-macosx_10_15_universal2.whl CPython 3.14 CPython 3.14 macOS 10.15+ universal2 (ARM64, x86-64) Details
pyscarcopula-0.20.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
pyscarcopula-0.20.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
pyscarcopula-0.20.0-cp313-cp313-macosx_10_13_universal2.whl CPython 3.13 CPython 3.13 macOS 10.13+ universal2 (ARM64, x86-64) Details
pyscarcopula-0.20.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
pyscarcopula-0.20.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
pyscarcopula-0.20.0-cp312-cp312-macosx_10_13_universal2.whl CPython 3.12 CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64) Details
pyscarcopula-0.20.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
pyscarcopula-0.20.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
pyscarcopula-0.20.0-cp311-cp311-macosx_10_9_universal2.whl CPython 3.11 CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) Details
pyscarcopula-0.20.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
pyscarcopula-0.20.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
pyscarcopula-0.20.0-cp310-cp310-macosx_10_9_universal2.whl CPython 3.10 CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) Details

Total release size:22.2 MB

Release files / pyscarcopula-0.20.0.tar.gz

Download URL pyscarcopula-0.20.0.tar.gz
Size 6.4 MB
Tags Source
SHA-256 checksum
How to use checksums
9458dd624ff893cb3a4a16920829e19749121917444060c4561b2de6c3892a66
BLAKE2b-256 checksum
How to use checksums
433f3f88b4371f18e7771fd3b9bc6e889401755989d23d19780558b5557a9adf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp314-cp314-win_amd64.whl

Download URL pyscarcopula-0.20.0-cp314-cp314-win_amd64.whl
Size 799.4 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
512a76a52a9fb333947d0da523865abef2279587e037dba668de54939515e361
BLAKE2b-256 checksum
How to use checksums
187fc478534f7454b1b459048f1bd7564c3661d53dd91ae3846d30f7135c78b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pyscarcopula-0.20.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 991.4 kB
Tags CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
997d3d5263738729daf15c6c668928e5c5d60ad8c82b056994e041d04fe0d7fa
BLAKE2b-256 checksum
How to use checksums
b57966ef3d5f5da4c7b797c7021bb8f97a38ec3b86291416aeba6caabfe6f719
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp314-cp314-macosx_10_15_universal2.whl

Download URL pyscarcopula-0.20.0-cp314-cp314-macosx_10_15_universal2.whl
Size 1.4 MB
Tags CPython 3.14 macOS 10.15+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
90e8b58e00ebbae19719df65bb5bb59dfddca113c1516d0f72e1891234a1b7e1
BLAKE2b-256 checksum
How to use checksums
eecf0a1773af7a1d542f3f59215604b4fd08ddee8fef991a0389f85edd5f1360
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp313-cp313-win_amd64.whl

Download URL pyscarcopula-0.20.0-cp313-cp313-win_amd64.whl
Size 787.6 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
536e0428f821e5449d457491e5550f45e2ebb9fd5ee9dcc504319717d6534c4d
BLAKE2b-256 checksum
How to use checksums
2f60f315ea4a6abf027f51225d6eec1cfc0b67fad60728a74965574f17260948
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pyscarcopula-0.20.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 990.4 kB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
c3940bfaf792b7a054bd224df4842f825353eb48d86726591239ec183d6ddbb1
BLAKE2b-256 checksum
How to use checksums
7e62460034c9b3ad51016bdaff97903b6168229ec7768efe91c7624c03d92173
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp313-cp313-macosx_10_13_universal2.whl

Download URL pyscarcopula-0.20.0-cp313-cp313-macosx_10_13_universal2.whl
Size 1.4 MB
Tags CPython 3.13 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
fd324e07744d6c4b31672e7643278e693534ab250c684f19f0b6cf903f74b294
BLAKE2b-256 checksum
How to use checksums
70082795dfd16ef71bae4c806d7c0a1113fbe77936fc043cdc074d2df06391e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp312-cp312-win_amd64.whl

Download URL pyscarcopula-0.20.0-cp312-cp312-win_amd64.whl
Size 787.6 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
587a578dfde7e3358678c509728137b10350b8532bc9c4ca3cd2362577cb5414
BLAKE2b-256 checksum
How to use checksums
a5f25ba850892d5240886eb2895c9bef3a355e6b2c918b5ea6c50d23c0b48d74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pyscarcopula-0.20.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 990.7 kB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
1268e7f756ba5e3a905aabdcf3d51f939580f3673dc5511f712c11f9c81e2cf9
BLAKE2b-256 checksum
How to use checksums
815e6b0669e7a16da33394f693566534bdbb402c913350ffc370c954157b2f55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp312-cp312-macosx_10_13_universal2.whl

Download URL pyscarcopula-0.20.0-cp312-cp312-macosx_10_13_universal2.whl
Size 1.4 MB
Tags CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
9b286e6a891648a2c297a3d7746df8eaa5311157a9633a77f470f508d40d2029
BLAKE2b-256 checksum
How to use checksums
e04039ed9538609fba0207841278cc7743b01811aa958fe1ff5aac141c65e1e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp311-cp311-win_amd64.whl

Download URL pyscarcopula-0.20.0-cp311-cp311-win_amd64.whl
Size 783.3 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
3faf6542526e4c15a9ce1e3485797427de41d4c5da4c7c74ebb31cbd02ecf9ed
BLAKE2b-256 checksum
How to use checksums
72dc92f0f73a11405d782319152fad2518c73aa9446473e1e7f33a763d657742
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pyscarcopula-0.20.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 987.9 kB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
ed0b54ef50a3fa5d93bff52536eefa5a009e0448822a69870ec8aad14844392b
BLAKE2b-256 checksum
How to use checksums
4a41885e27c100d5255a166fc71460a65292480d02e7a999f48460ce1991110e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp311-cp311-macosx_10_9_universal2.whl

Download URL pyscarcopula-0.20.0-cp311-cp311-macosx_10_9_universal2.whl
Size 1.4 MB
Tags CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
7acd3db38113955e7553838901007328e64c419eeec3a211b8c93be477582b8f
BLAKE2b-256 checksum
How to use checksums
de19592c923a4e13fae6ec502cae7f7ee5d757400564a5e1bdb2a39cb452309e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp310-cp310-win_amd64.whl

Download URL pyscarcopula-0.20.0-cp310-cp310-win_amd64.whl
Size 782.4 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
020953fb0fd4966eb7c20f4133015d91938eb8be7a960df408524a9612d48c12
BLAKE2b-256 checksum
How to use checksums
8b35fe9bc5cb09cc05c1eae9e3d10f04529d5b5b83827ecd111e3a769a3e11c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pyscarcopula-0.20.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 985.6 kB
Tags CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
f05e6b0ff57ae4536d242ec120ea4be11b475a3ba5fdd3b358b65dbcdd4d9a99
BLAKE2b-256 checksum
How to use checksums
afea6b80d1c557b9b5dae23591d516a1f6a57a0d31eb7df82df57402951da501
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / pyscarcopula-0.20.0-cp310-cp310-macosx_10_9_universal2.whl

Download URL pyscarcopula-0.20.0-cp310-cp310-macosx_10_9_universal2.whl
Size 1.4 MB
Tags CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
c4d65dc6409bf42e2de2b1ce83cc41b6fe389ed059a3d4ac58fb540de602d9a3
BLAKE2b-256 checksum
How to use checksums
de4408b02e292dd96d86a4f690202cba9d08137856b5b15ccf5ddeab205e6e49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page