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 required pybind11 C++ extension. It provides built-in copula kernels, static likelihoods, GAS, and SCAR-TM-OU numerical evaluation. Official wheels bundle the 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
- 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. A source checkout
without a successfully built extension is incomplete for the default
bivariate GAS workflow.
Optional benchmark checks are disabled by default. Enable them explicitly:
PYSCA_RUN_BENCHMARKS=1 pytest -m benchmark
Core dependencies: numpy, numba, scipy, joblib, tqdm.
Verify a native installation with:
python -m pyscarcopula._native_smoke
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
- Multivariate Gaussian, Student-t, equicorrelation, and stochastic Student models
- Explicit
CopulaBase/BivariateCopula/MultivariateCopulahierarchy with capability-based strategy validation
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
PredictConfigfor explicit prediction options- Reproducible random generation via
rng - JSON persistence through
model.save()andModelClass.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.
SCAR-TM-OU uses the bundled C++ extension as its only production numerical engine. No backend argument is needed.
result = fit(copula, u, method="scar-tm-ou")
GAS uses the compiled numerical evaluator for likelihood, score recursion, state updates, prediction, and Rosenblatt paths. There is no backend selector or silent Python fallback:
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 C++
families and numerical options.
Custom Python copulas remain useful with custom Python strategies, sampling, and diagnostics. Built-in native production strategies do not execute arbitrary Python copula kernels: unsupported classes fail before optimization.
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/:
01_basic_api.ipynb02_bivariate.ipynb03_multivariate.ipynb04_vine.ipynb05_risk_metrics.ipynb06_pyvinecopulib_comparison.ipynb
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.
Migration notes for the native-core and multivariate namespace changes are in
docs/release-notes/native-core-migration.md.
License
MIT License. See LICENSE.txt.
Project details
Release history Release notifications | RSS feed
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.17.1.tar.gz.
File metadata
- Download URL: pyscarcopula-0.17.1.tar.gz
- Upload date:
- Size: 368.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d92acd0cd203de9797cae3e1aa7fea3d4b399f00fe99e86a92ddf0456f82138
|
|
| MD5 |
ca329224eafda5dc45a70f30623308c9
|
|
| BLAKE2b-256 |
5169a14424be1671c77a95b169ce7a23e2de2b0aa23abcc3042933c22f518436
|
File details
Details for the file pyscarcopula-0.17.1-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 510.2 kB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
811567553129800a705bee58647e4b4fa3f1496609f84aec24bb293128048b17
|
|
| MD5 |
abed0e152a6b0458828082592c909b71
|
|
| BLAKE2b-256 |
88383f1661dcc7d82f1c9aa8e329336a52bcfb952697442fb7115fc27b9ab3ef
|
File details
Details for the file pyscarcopula-0.17.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 608.7 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.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4e40a6ebcb72176acfcb3c8cf084ac7454c3a11919e7e73f7d6532d5358eca9
|
|
| MD5 |
536c50cf7a691b1e1bfb95f2ecc7df0f
|
|
| BLAKE2b-256 |
34580027986d2d2defbf5374550faa8ef218ada9bb8853825d56dcbd8b901c22
|
File details
Details for the file pyscarcopula-0.17.1-cp314-cp314-macosx_10_15_universal2.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp314-cp314-macosx_10_15_universal2.whl
- Upload date:
- Size: 841.1 kB
- 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.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51ad234d9556d802feb44500a15ea87a24c6501e6e7fed4334f81abef6ca5601
|
|
| MD5 |
194ea525b949ac7afd630291239ad2f5
|
|
| BLAKE2b-256 |
361f3578b93278d0257337f33625cb1d4a98340f7ef3a5705dbfdb61edcdb56f
|
File details
Details for the file pyscarcopula-0.17.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 502.8 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f73dc6af939716b2634d05bd6530143589b6baf32e511d57def585f0ade60e1c
|
|
| MD5 |
0e046308a58e9c3f64b3ff9a5229a964
|
|
| BLAKE2b-256 |
7be8e862c1bc914220f79bb393e9b516a874dbb8faa11a794e7886e6f162ed07
|
File details
Details for the file pyscarcopula-0.17.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 608.5 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.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ebca7fd55b150291245238c8a8cab1fcbcf41a8416e584c34c65ed3e96ec8ca
|
|
| MD5 |
713e482cfd67055e12e14bfc3d3f8c17
|
|
| BLAKE2b-256 |
f66ffc1324f0bf0798940f65372c1d145d656176a8140cf38e563d500164deb4
|
File details
Details for the file pyscarcopula-0.17.1-cp313-cp313-macosx_10_13_universal2.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp313-cp313-macosx_10_13_universal2.whl
- Upload date:
- Size: 840.2 kB
- 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.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9eede106af2319baf7f2dd50d05837f33bf092258776cee17e94b32fa1198ae1
|
|
| MD5 |
178670376757669e0547cdd6dc02fa75
|
|
| BLAKE2b-256 |
b09047242633b1f8b92426e1af99d7ce4650783556bdb573c5f5ede819e1bdc1
|
File details
Details for the file pyscarcopula-0.17.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 502.7 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83ade625eb3ed025da411a52d7a004ebdbb7ef7c3a0cff700972c3c0d430fe0e
|
|
| MD5 |
2ad1e71667247283a415ae5f405b7085
|
|
| BLAKE2b-256 |
ac379e8ae856bb3d2062705cb28f772511e60a4208727da73fd7ef1ac5b7c676
|
File details
Details for the file pyscarcopula-0.17.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 608.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.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d182fcc1a59a9b241ca7d10b7cfcda0586c5abdbf61c6f3175387412445156ba
|
|
| MD5 |
a1ce4e48a421a02c80042d031ea5a2d4
|
|
| BLAKE2b-256 |
d8acb024038e9ae8adae5414820d5ef68371b5d730c0787e3cab95923b8e3f61
|
File details
Details for the file pyscarcopula-0.17.1-cp312-cp312-macosx_10_13_universal2.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp312-cp312-macosx_10_13_universal2.whl
- Upload date:
- Size: 840.0 kB
- 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.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b649073578823a118be24ca9ab4c5fb3d6f45e98ebdcb706df6a02c8b612bff1
|
|
| MD5 |
711ccb90731a89272be043de5a62cdfd
|
|
| BLAKE2b-256 |
a59d1dfb891d447e9589dea5ed7ba556efabcb87c961c8cbc56bffe2269e014b
|
File details
Details for the file pyscarcopula-0.17.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 498.5 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
882db60390796498067cfe4910bcc6cdcbfb1975e372bc0fe952fb35672d9f7f
|
|
| MD5 |
4ec474d1f395de6e05252fde5b7bb833
|
|
| BLAKE2b-256 |
8c16da6237b21acade5a61f5b9404b5ad0e22b88fdbbfadb3a8788f9bc0c2089
|
File details
Details for the file pyscarcopula-0.17.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 605.6 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.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38e7d1864026b0d9f7315a013c69678f7d46d6802f9fedbffdd989285372c9fa
|
|
| MD5 |
4183312d25634e9baa38b24ab132b1d8
|
|
| BLAKE2b-256 |
79390f6d427d5a5f0677c77ccc6375c0d5ed83a3c87d9739b3d2f7c55acdd971
|
File details
Details for the file pyscarcopula-0.17.1-cp311-cp311-macosx_10_9_universal2.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 832.4 kB
- 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.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53daa7db615ee193fad1ca2796d4ae216520a98fa557e4924935eb8a6be6c2d1
|
|
| MD5 |
c37aabce7ef7e50fc9f2ef2b3a178472
|
|
| BLAKE2b-256 |
752a8fc32ad737afd71948a46cba25228c731ed0d472d734d104f4d6322acb75
|
File details
Details for the file pyscarcopula-0.17.1-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 496.8 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43561789717989c696612d663287d8ae24e9be7ac3edfaeba2d712bd7284f59f
|
|
| MD5 |
b47634dfcb42d3a1a319397e9f223428
|
|
| BLAKE2b-256 |
49b035a3a545b1114f07ab26d1fada5ce7c42e96851614becd58d9da6c8df22a
|
File details
Details for the file pyscarcopula-0.17.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 602.3 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.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a6dfac15db6bf4111718a253a7bb7c4dffe8afaa674da608e2e944d09ee04ef
|
|
| MD5 |
910b1ea187a5987a27f6523fe80e6876
|
|
| BLAKE2b-256 |
8c6f6efdf513f0c6025c1ab9326e580736c73c97c05389e97cc4aecd9f251f2f
|
File details
Details for the file pyscarcopula-0.17.1-cp310-cp310-macosx_10_9_universal2.whl.
File metadata
- Download URL: pyscarcopula-0.17.1-cp310-cp310-macosx_10_9_universal2.whl
- Upload date:
- Size: 829.5 kB
- 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.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d87fdb0fd7f2483b782de8b2f14d8689bacc30bbb3f4fcfd45855f3ad6f658a3
|
|
| MD5 |
0fdf06c163adadce24b35d4184c007b1
|
|
| BLAKE2b-256 |
29f15141676b9fc7ebcd5a4ed0c994dbd486dc602a55d5ddc6b743e5ac2295b4
|