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.1.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.1-cp314-cp314-win_amd64.whl (731.3 kB view details)

Uploaded CPython 3.14Windows x86-64

pyscarcopula-0.19.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (909.1 kB view details)

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

pyscarcopula-0.19.1-cp314-cp314-macosx_10_15_universal2.whl (1.3 MB view details)

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

pyscarcopula-0.19.1-cp313-cp313-win_amd64.whl (720.5 kB view details)

Uploaded CPython 3.13Windows x86-64

pyscarcopula-0.19.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (908.1 kB view details)

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

pyscarcopula-0.19.1-cp313-cp313-macosx_10_13_universal2.whl (1.3 MB view details)

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

pyscarcopula-0.19.1-cp312-cp312-win_amd64.whl (720.5 kB view details)

Uploaded CPython 3.12Windows x86-64

pyscarcopula-0.19.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (908.3 kB view details)

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

pyscarcopula-0.19.1-cp312-cp312-macosx_10_13_universal2.whl (1.3 MB view details)

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

pyscarcopula-0.19.1-cp311-cp311-win_amd64.whl (716.1 kB view details)

Uploaded CPython 3.11Windows x86-64

pyscarcopula-0.19.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (903.7 kB view details)

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

pyscarcopula-0.19.1-cp311-cp311-macosx_10_9_universal2.whl (1.3 MB view details)

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

pyscarcopula-0.19.1-cp310-cp310-win_amd64.whl (715.1 kB view details)

Uploaded CPython 3.10Windows x86-64

pyscarcopula-0.19.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (901.1 kB view details)

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

pyscarcopula-0.19.1-cp310-cp310-macosx_10_9_universal2.whl (1.3 MB view details)

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

File details

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

File metadata

  • Download URL: pyscarcopula-0.19.1.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.1.tar.gz
Algorithm Hash digest
SHA256 b8198fa48794867e1761d7722b2412d72f9c05c87e14ef9399c851fc84b9b5ac
MD5 70759a0beaa69e13a79606a5ae7c9ce0
BLAKE2b-256 0088c92c35314372d4074d62844ced7cac1e52dad62dd445b6cf6a4870172185

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 3b6bc7526bef36b226c8d14854197ec1563bcc8f505e097d44d8f6d4b11067ab
MD5 1767eff5cfa60c0fea057d526649b0be
BLAKE2b-256 9e6d06e787893ad3849bbe89ba829004dc3c6e4fd38516b0324a6eaf1c851d59

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d435208353fc61844e50d99d48d5786778bfc0a4ac0be2afce3716ed679c692b
MD5 9a1f7be56570e56f1a265ace35cf22b0
BLAKE2b-256 e7961a51e3082360a70089ed420206cc5c0de2ae6871622eb831d338a26c8533

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 69561277d0032aa1d1f28914d64f0d4ea96ce6ed4f870290010b10d7a55fa00d
MD5 69bc64b6d3b2da7faa6959047ceeb135
BLAKE2b-256 de8437501330a84a355913865517735b6157531ef5b75d5b707677fe7b1b6415

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b9dd6d562e442f049cdafb7e25c6816e373ffa01eff08909071686db69c35f60
MD5 33738c7bcd5a736fe12b7844746050f4
BLAKE2b-256 25a5c4f3c69019d6c5fa4624296593b43845df90ae47e71c9ee16ee4475e685e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 154c2152f30c2c1285567331d66deea682e9de7cdfd55dd5f80a5d2df4e502a7
MD5 78a0437b1e80c64c468295a30ed44de1
BLAKE2b-256 2de21c42e7ac7eebe543176962e45738e2c64c4013d3fbfb496d4e542e55580d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 72bed8ad64164a08498c220d4b3ef54f5aaacc061aa4151df10884958faa5b95
MD5 28aeee1e5c17bbb3e440440c035d6893
BLAKE2b-256 3359cad0afa92f4839d0453415c9fdaf25bbaff4a35652c114c6e93ef85f6967

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3a6595d6f2279c4c3cb77b30425d6afad69df4b596b6978a9d82b8999f946a44
MD5 9bd2c162aae9933fb57a6309dd44d967
BLAKE2b-256 787e0963d74ac7fedbb98a7419b8e72c9c69e1270b4b88dd1cebfa01772c5844

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a5930b4207ca462bd21d66ea8b08ba0a76027bb2be771b5e6daf195469523824
MD5 1954cb3e473757d43de1e975a53a05e4
BLAKE2b-256 09800fa98620b29983508e7d2f2907081fcddb98727cb707e3e3ecbee60298f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 380ce3031320e1513f343cfa3fa8007779bb3208fab0403291c8067e0f72ffe6
MD5 ad3771fb04b16b364f35eb2687dddec2
BLAKE2b-256 a3721f9919f5906ed7d29b0ef11fa29f61cee5f980e39e75e399fec1065b294a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 74776a7f5ab9adf4c9c62377970ddb8f727f5860e14d2f0e6104648b16100103
MD5 07329928aa4b5abcc7eb4c02ed34f0e0
BLAKE2b-256 d930e8b093bbcd94d900afa99e37624f289126f16cfb4640fdb400944a7e2cd8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 804adbe5ac7d0c07fcbf882e683597421ee9a0e832d91dba922a0c91f368681e
MD5 444da88df35bc17300d543b163bc2452
BLAKE2b-256 8722d05e5b40e7ec30f9f2087fdd2341a3a4c7a4a749c0d6794e55ddf102e813

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 a28457782e18d066695d544298ec4bfa445043e0a05b50c330b75b256efc39f7
MD5 4261c911e44daa9b0637a8d49fabc1d0
BLAKE2b-256 9d5fa62f0aebc774ccaad1dd92816fb26d3ef4c0bd11952181fa3dc45da0ca9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ff3e10bb09abc5eede97857c9fbfc63eecd1ffbd1b6abaa32b43852031430a10
MD5 6d4eb0f10e9c041b3b2a5400921e0f89
BLAKE2b-256 64aa235c8c7d936cddc6dcade50ef9953f743a7d2a3673cbcc5ae2c0e944f0ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2833a3b6ff9c412800a3f39dfd2c7c98732666dbf4a2acf262477a35e3c1b142
MD5 9eb65b9e1c2b2ee2af3461810fe6a130
BLAKE2b-256 2fb3d9bd31987a18c3986a8cbc925984a945fb32d8792d8d7e6d9c207cfb5024

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyscarcopula-0.19.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 78c9fb5328235427ed3bd61b83cd2b8655c6eab4b1c8d165e65c6eed2ace97c6
MD5 afec5175ba92a4134f4dac25819561c0
BLAKE2b-256 33092aa9183e2517529f9ee01fd17e33adc6b0ceee1fe41948696653a59eadc1

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

This release

0.19.1 This release

16 files

0.19.0

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