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
VineCopularuntime 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
PredictConfigfor explicit prediction options- Reproducible random generation via
rng - JSON persistence through
model.save()andModelClass.load()(include_data=Falsecan 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_independentand rollingrisk_metricsexecution - Absolute one-thread default: omitted
n_threadsalways means1, 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/:
01_basic_api.ipynb02_bivariate.ipynb03_multivariate.ipynb04_vine.ipynb05_risk_metrics.ipynb06_pyvinecopulib_comparison.ipynb
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8198fa48794867e1761d7722b2412d72f9c05c87e14ef9399c851fc84b9b5ac
|
|
| MD5 |
70759a0beaa69e13a79606a5ae7c9ce0
|
|
| BLAKE2b-256 |
0088c92c35314372d4074d62844ced7cac1e52dad62dd445b6cf6a4870172185
|
File details
Details for the file pyscarcopula-0.19.1-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: pyscarcopula-0.19.1-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 731.3 kB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b6bc7526bef36b226c8d14854197ec1563bcc8f505e097d44d8f6d4b11067ab
|
|
| MD5 |
1767eff5cfa60c0fea057d526649b0be
|
|
| BLAKE2b-256 |
9e6d06e787893ad3849bbe89ba829004dc3c6e4fd38516b0324a6eaf1c851d59
|
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
- Download URL: pyscarcopula-0.19.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 909.1 kB
- Tags: CPython 3.14, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d435208353fc61844e50d99d48d5786778bfc0a4ac0be2afce3716ed679c692b
|
|
| MD5 |
9a1f7be56570e56f1a265ace35cf22b0
|
|
| BLAKE2b-256 |
e7961a51e3082360a70089ed420206cc5c0de2ae6871622eb831d338a26c8533
|
File details
Details for the file pyscarcopula-0.19.1-cp314-cp314-macosx_10_15_universal2.whl.
File metadata
- Download URL: pyscarcopula-0.19.1-cp314-cp314-macosx_10_15_universal2.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.14, macOS 10.15+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69561277d0032aa1d1f28914d64f0d4ea96ce6ed4f870290010b10d7a55fa00d
|
|
| MD5 |
69bc64b6d3b2da7faa6959047ceeb135
|
|
| BLAKE2b-256 |
de8437501330a84a355913865517735b6157531ef5b75d5b707677fe7b1b6415
|
File details
Details for the file pyscarcopula-0.19.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: pyscarcopula-0.19.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 720.5 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9dd6d562e442f049cdafb7e25c6816e373ffa01eff08909071686db69c35f60
|
|
| MD5 |
33738c7bcd5a736fe12b7844746050f4
|
|
| BLAKE2b-256 |
25a5c4f3c69019d6c5fa4624296593b43845df90ae47e71c9ee16ee4475e685e
|
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
- Download URL: pyscarcopula-0.19.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 908.1 kB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
154c2152f30c2c1285567331d66deea682e9de7cdfd55dd5f80a5d2df4e502a7
|
|
| MD5 |
78a0437b1e80c64c468295a30ed44de1
|
|
| BLAKE2b-256 |
2de21c42e7ac7eebe543176962e45738e2c64c4013d3fbfb496d4e542e55580d
|
File details
Details for the file pyscarcopula-0.19.1-cp313-cp313-macosx_10_13_universal2.whl.
File metadata
- Download URL: pyscarcopula-0.19.1-cp313-cp313-macosx_10_13_universal2.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.13, macOS 10.13+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72bed8ad64164a08498c220d4b3ef54f5aaacc061aa4151df10884958faa5b95
|
|
| MD5 |
28aeee1e5c17bbb3e440440c035d6893
|
|
| BLAKE2b-256 |
3359cad0afa92f4839d0453415c9fdaf25bbaff4a35652c114c6e93ef85f6967
|
File details
Details for the file pyscarcopula-0.19.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: pyscarcopula-0.19.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 720.5 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a6595d6f2279c4c3cb77b30425d6afad69df4b596b6978a9d82b8999f946a44
|
|
| MD5 |
9bd2c162aae9933fb57a6309dd44d967
|
|
| BLAKE2b-256 |
787e0963d74ac7fedbb98a7419b8e72c9c69e1270b4b88dd1cebfa01772c5844
|
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
- Download URL: pyscarcopula-0.19.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 908.3 kB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5930b4207ca462bd21d66ea8b08ba0a76027bb2be771b5e6daf195469523824
|
|
| MD5 |
1954cb3e473757d43de1e975a53a05e4
|
|
| BLAKE2b-256 |
09800fa98620b29983508e7d2f2907081fcddb98727cb707e3e3ecbee60298f0
|
File details
Details for the file pyscarcopula-0.19.1-cp312-cp312-macosx_10_13_universal2.whl.
File metadata
- Download URL: pyscarcopula-0.19.1-cp312-cp312-macosx_10_13_universal2.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.12, macOS 10.13+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
380ce3031320e1513f343cfa3fa8007779bb3208fab0403291c8067e0f72ffe6
|
|
| MD5 |
ad3771fb04b16b364f35eb2687dddec2
|
|
| BLAKE2b-256 |
a3721f9919f5906ed7d29b0ef11fa29f61cee5f980e39e75e399fec1065b294a
|
File details
Details for the file pyscarcopula-0.19.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: pyscarcopula-0.19.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 716.1 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74776a7f5ab9adf4c9c62377970ddb8f727f5860e14d2f0e6104648b16100103
|
|
| MD5 |
07329928aa4b5abcc7eb4c02ed34f0e0
|
|
| BLAKE2b-256 |
d930e8b093bbcd94d900afa99e37624f289126f16cfb4640fdb400944a7e2cd8
|
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
- Download URL: pyscarcopula-0.19.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 903.7 kB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
804adbe5ac7d0c07fcbf882e683597421ee9a0e832d91dba922a0c91f368681e
|
|
| MD5 |
444da88df35bc17300d543b163bc2452
|
|
| BLAKE2b-256 |
8722d05e5b40e7ec30f9f2087fdd2341a3a4c7a4a749c0d6794e55ddf102e813
|
File details
Details for the file pyscarcopula-0.19.1-cp311-cp311-macosx_10_9_universal2.whl.
File metadata
- Download URL: pyscarcopula-0.19.1-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a28457782e18d066695d544298ec4bfa445043e0a05b50c330b75b256efc39f7
|
|
| MD5 |
4261c911e44daa9b0637a8d49fabc1d0
|
|
| BLAKE2b-256 |
9d5fa62f0aebc774ccaad1dd92816fb26d3ef4c0bd11952181fa3dc45da0ca9c
|
File details
Details for the file pyscarcopula-0.19.1-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: pyscarcopula-0.19.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 715.1 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff3e10bb09abc5eede97857c9fbfc63eecd1ffbd1b6abaa32b43852031430a10
|
|
| MD5 |
6d4eb0f10e9c041b3b2a5400921e0f89
|
|
| BLAKE2b-256 |
64aa235c8c7d936cddc6dcade50ef9953f743a7d2a3673cbcc5ae2c0e944f0ed
|
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
- Download URL: pyscarcopula-0.19.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 901.1 kB
- Tags: CPython 3.10, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2833a3b6ff9c412800a3f39dfd2c7c98732666dbf4a2acf262477a35e3c1b142
|
|
| MD5 |
9eb65b9e1c2b2ee2af3461810fe6a130
|
|
| BLAKE2b-256 |
2fb3d9bd31987a18c3986a8cbc925984a945fb32d8792d8d7e6d9c207cfb5024
|
File details
Details for the file pyscarcopula-0.19.1-cp310-cp310-macosx_10_9_universal2.whl.
File metadata
- Download URL: pyscarcopula-0.19.1-cp310-cp310-macosx_10_9_universal2.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78c9fb5328235427ed3bd61b83cd2b8655c6eab4b1c8d165e65c6eed2ace97c6
|
|
| MD5 |
afec5175ba92a4134f4dac25819561c0
|
|
| BLAKE2b-256 |
33092aa9183e2517529f9ee01fd17e33adc6b0ceee1fe41948696653a59eadc1
|