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 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, 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

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.19.0.tar.gz (6.3 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.19.0-cp314-cp314-win_amd64.whl (711.0 kB view details)

Uploaded CPython 3.14Windows x86-64

pyscarcopula-0.19.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (888.8 kB view details)

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

pyscarcopula-0.19.0-cp314-cp314-macosx_10_15_universal2.whl (1.2 MB view details)

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

pyscarcopula-0.19.0-cp313-cp313-win_amd64.whl (700.2 kB view details)

Uploaded CPython 3.13Windows x86-64

pyscarcopula-0.19.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (887.8 kB view details)

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

pyscarcopula-0.19.0-cp313-cp313-macosx_10_13_universal2.whl (1.2 MB view details)

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

pyscarcopula-0.19.0-cp312-cp312-win_amd64.whl (700.2 kB view details)

Uploaded CPython 3.12Windows x86-64

pyscarcopula-0.19.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (888.0 kB view details)

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

pyscarcopula-0.19.0-cp312-cp312-macosx_10_13_universal2.whl (1.2 MB view details)

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

pyscarcopula-0.19.0-cp311-cp311-win_amd64.whl (695.7 kB view details)

Uploaded CPython 3.11Windows x86-64

pyscarcopula-0.19.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (883.4 kB view details)

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

pyscarcopula-0.19.0-cp311-cp311-macosx_10_9_universal2.whl (1.2 MB view details)

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

pyscarcopula-0.19.0-cp310-cp310-win_amd64.whl (694.8 kB view details)

Uploaded CPython 3.10Windows x86-64

pyscarcopula-0.19.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (880.8 kB view details)

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

pyscarcopula-0.19.0-cp310-cp310-macosx_10_9_universal2.whl (1.2 MB view details)

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

File details

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

File metadata

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

File hashes

Hashes for pyscarcopula-0.19.0.tar.gz
Algorithm Hash digest
SHA256 7defb04625eb2bc89c7e8a20ae44b368530561db2f9e15684d7eeec8357c8410
MD5 9556f70fd400a90e2517441633a4256f
BLAKE2b-256 490bed346e1edf4392e7dd9d5cd44d8cef5f7d2929eb731d6a583fd8d852322c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 a717aac7cbeb80ec5a1456a6569e565029bf4b5cbda35087e77b812666ba4718
MD5 ac97edeb9bce7575c13953c47da5f327
BLAKE2b-256 2152be1741b60c8f3ff8e975d88e768afaae3cec7bce60cc98823bfdfded738f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fafbbcd9d890a433722468f4bc71f1fb10dfb70a7f941da4a4e08c4fd3dd383f
MD5 99ff91464ab96cc0e496e8ffa66e2e26
BLAKE2b-256 ee7997d7dd4d46b67404ff2e66ca44467da81e3bc1c6ccb1df198fe1a4cb3259

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 5362d2c26798cd454ad2eaa8fc4d067cb776e0829a09d4cb2627776aea627e61
MD5 d9b930943572fb2a0e768677eb43ba9a
BLAKE2b-256 cbd3ea203308321901b661ccb2dbb1c0d76040ede57e7b2bc89e267e626a10ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e9980884397f61fc8eb79cf72ba3543bf001c8439f531480d763accf8c2e7526
MD5 e8d77a40ef7a5e9252f8239f1f1df49a
BLAKE2b-256 44804e34dec61f337afca21e3a7da4c8dd5d5500745cb837933ec35034b2c38d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f69b7aeff35244969bf9091639d469680745bef16ca11a6210a2716734db84f9
MD5 b9826c964a86d67c5772904d7b57b947
BLAKE2b-256 d70b9c51e725360bc7cf29ec23a08123735fc5370a17098b5c4619a63954b23d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 bcc1a4c76d17a5501dc78bbab69d40364a9af10369fb721f46047fe4fae14abf
MD5 6ae5af0bc13dc0f684811a03ad9b9e2c
BLAKE2b-256 b3bed55f7f6d090c71a3fb5d20611b3616656a7bbdf54644989ae2a6be1bb985

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e7623be4be5c03eaaaf33727e8ea85a808816be6b4e4cdf3f0542a0161800375
MD5 26c6ecf7c870fa6b2fb14074a3076f00
BLAKE2b-256 ebf781c8053638c58b5b402598355876eec55d9309add41d7896f20d3a758f1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4eed902d9cc022e77648672ef5fe0a4085fef066d553eb9a89d12a185d663119
MD5 6dc5b5b029d44067134f3ceea6fdb379
BLAKE2b-256 871198e5e89134c1db0e406110006f07798663408bd14b8b4f6cab5951e7ffab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 5fcbe23e88408604179df78742122b7aaf4ec0fa5f10e11969a35c07214d9784
MD5 c75762ab3bca5fded17a77d9b0e3934b
BLAKE2b-256 974e1020ea87ca5526e94b7dc5b4037c5d6311e21ffe6b9cccd015046e6ae0da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cb757b4ce83832d6a12331a4dc7c3e9875dae858391225b9cfb44e8be54915cd
MD5 4000a298cbd6917807d1352d57748bbf
BLAKE2b-256 9dd2aafec0243ff89703c6edd498926e298f5e1ef218bb70857935a4ea9f2df4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 78ae9d029356c86b05705ca8106ca58577ce51c1a6243ef164b14e7543f25315
MD5 8b62f66d6824e5142e9e75cb5be87cd8
BLAKE2b-256 c3cdc29294c63947c7c2809f957aa63cf84520db4b6a45bcb6f221be60a43309

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0daeb4a95731b69b5c3e4ad707e6159978eb5c916f43285aff1420208cd95638
MD5 b167bdf7715def7a1298420bc4a86010
BLAKE2b-256 864362e3d227431c33addfa5d8b3338c3c75500d91855aefd8780a77864c3dd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f035b9da061a69a530995db05ab27bab9825dee7e91d77d3fb8eedc622194a9a
MD5 c06b5bf02de2b229c67eed82b2e5b72f
BLAKE2b-256 e8fdd3079f735328478b45efcadbecbca5ddb350223a97ff2b6bcf3dbcc77d96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5df4a2f3fad1ba5e58e395b9b478821d082912a678d361b466f824577b9d98e7
MD5 bf126748e9c240285bd313d15ba3e542
BLAKE2b-256 ca7c21b8684130244d6367f2d74e99407e61557300346553f77519a1cb1f0884

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 99786f5428382feb1d78220dc46f34054d796615faa45719a0c52373168d933b
MD5 125b08c3f0a3ab47ee7623c040a0a937
BLAKE2b-256 76bb298e0d5d8577e28a6576af38cb6cb2d5b81ce0ac54de723746d3e50bb808

See more details on using hashes here.

Release history Release notifications | RSS feed

0.22.0

21 files

0.21.0

16 files

0.20.2

16 files

0.20.1

16 files

0.20.0

16 files

0.19.1

16 files

This release

0.19.0 This release

16 files

0.18.0

16 files

0.17.5

16 files

0.17.4

16 files

0.17.3

16 files

0.17.2

16 files

0.17.1

16 files

0.17.0

16 files

0.16.0

16 files

0.15.1

2 files

0.15.0

2 files

0.14.1

2 files

0.14.0

2 files

0.13.0

2 files

0.12.1

2 files

0.12.0

2 files

0.11.0

2 files

0.10.1

2 files

0.10.0

2 files

0.9.1

2 files

0.9.0

2 files

0.8.1

2 files

0.8.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.2

2 files

0.5.1

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

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