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
Quick start
pyscarcopula expects a two-dimensional array with observations in rows and
variables in columns. Copula fitting uses pseudo-observations in the open unit
interval. Pass existing pseudo-observations directly, as below, or use
to_pobs=True to rank-transform raw continuous observations during fitting.
import numpy as np
from pyscarcopula import GumbelCopula
rng = np.random.default_rng(2026)
source = GumbelCopula(rotate=180)
u = source.sample_at_parameter(
400,
r=np.full(400, 1.8),
rng=rng,
)
model = GumbelCopula(rotate=180)
result = model.fit(u, method="mle")
forecast = model.predict(1_000, rng=np.random.default_rng(2027))
print(result.log_likelihood)
print(forecast.shape) # (1000, 2)
The fitted result is returned by fit and also stored as
model.fit_result. sample(...) reproduces the fitted model, while
predict(...) draws from its predictive distribution; this distinction
matters for dynamic models. See the complete
Quick Start and
Prediction Semantics.
Choose the model surface before tuning an estimation method:
| Task | Start with |
|---|---|
| Two-variable dependence | GumbelCopula, ClaytonCopula, FrankCopula, JoeCopula, or BivariateGaussianCopula |
| Static unrestricted multivariate dependence | GaussianCopula or StudentCopula |
| Scalar dynamic multivariate dependence | EquicorrGaussianCopula or StochasticStudentCopula |
| Flexible high-dimensional pair decomposition | VineCopula |
See Choosing a Model for the corresponding correlation modes, estimation methods, and limitations.
Features
Vine copulas
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:
import numpy as np
from pyscarcopula import VineCopula
rng = np.random.default_rng(2028)
vine_data = rng.random((400, 4))
# Data-driven regular vine
auto = VineCopula().fit(vine_data, method="mle")
# Fixed standard structures
c_vine = VineCopula.cvine(d=4).fit(vine_data, method="mle")
d_vine = VineCopula.dvine(d=4).fit(vine_data, method="mle")
For an arbitrary valid regular-vine tree sequence, construct
RVineMatrix.from_trees(...) and pass it as VineCopula(structure=...).
The Vine guide defines the decoded tree format and
explains family selection, truncation, and conditional sampling.
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
Release files for pyscarcopula 0.20.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyscarcopula-0.20.2.tar.gz | 883.9 kB | Details |
Built distributions (wheels)
Total release size:16.7 MB
Release files / pyscarcopula-0.20.2.tar.gz
| Download URL | pyscarcopula-0.20.2.tar.gz |
|---|---|
| Size | 883.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f14f61c32ac10547d59882c6d34f414376a5fc8c51888456a91ee16429d3ef5e
|
|
BLAKE2b-256 checksum How to use checksums |
5bd8a06fb417cfe70f535e9708e6b54605d768d42280f87df057cafba8a814ce
|
| 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.2-cp314-cp314-win_amd64.whl
| Download URL | pyscarcopula-0.20.2-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 771.1 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
a025fb6803f05a37a76b430987f1d97f8d7cb81812c1306e03214262a137232a
|
|
BLAKE2b-256 checksum How to use checksums |
8883c6c44bc98f77f87a2ca455e39f0c30e67b9ce569aaeb0e43795c70969a82
|
| 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.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pyscarcopula-0.20.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
37d1398eff029a3a9ee02781183c50bfe2d8bfa4113ecc230db365bd88d10dd7
|
|
BLAKE2b-256 checksum How to use checksums |
cda49ee4dca4b2e3b7d519bea205ca36585b5b35856dfb9637d42af7a1ce8f65
|
| 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.2-cp314-cp314-macosx_10_15_universal2.whl
| Download URL | pyscarcopula-0.20.2-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 |
1e26fbf9a10430ed8519850bb8b90948f8b99fe48064a7fcb90cfd82a7aa6350
|
|
BLAKE2b-256 checksum How to use checksums |
b474286a6aa563898d0a4ee64a342cb59a28a1daede143cde1e568896868e53c
|
| 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.2-cp313-cp313-win_amd64.whl
| Download URL | pyscarcopula-0.20.2-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 759.7 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
dcaed6ee4e1c7ca853819bfefc8383f7cd8ba1ce133065c38756d85cfa66d6ea
|
|
BLAKE2b-256 checksum How to use checksums |
d0348ddc61dadc0170886d2fe2e4d3df73313f00e6c3a3b4823437da3b2a2d7c
|
| 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.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pyscarcopula-0.20.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
b62c23788b24b37c7221b40f3698ff9f94b3c89e95658a9cfb80eeb15786fdf9
|
|
BLAKE2b-256 checksum How to use checksums |
eda40c376a761264be8bc4e747d1b588e023e93ab12e82fb1f2435653648f822
|
| 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.2-cp313-cp313-macosx_10_13_universal2.whl
| Download URL | pyscarcopula-0.20.2-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 |
1e38758008a22efd5f8e7646c6876dce72043679a20b05a8e1fa3e23cf6a31f9
|
|
BLAKE2b-256 checksum How to use checksums |
b41fbe845b0ddba911d5e7e6110654eef8b2f18c2db6788c937db2a64e2f618a
|
| 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.2-cp312-cp312-win_amd64.whl
| Download URL | pyscarcopula-0.20.2-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 759.6 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
15d8c35277016615498c46309bc8ccc6d3a66177e17311ab3bb7299d4b6f21d0
|
|
BLAKE2b-256 checksum How to use checksums |
467e5e9f903fddf1593368ce941b73521db4c8053ca0273b7b8a013052a5f500
|
| 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.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pyscarcopula-0.20.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
a84ffec6e45c9e925ab5919fa4fdfa8161913ef26e6ff565859263919e08b328
|
|
BLAKE2b-256 checksum How to use checksums |
6e0a428e2e969fffa547adc462ef0a3322fb0f3e447e6f908a19be0989250a96
|
| 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.2-cp312-cp312-macosx_10_13_universal2.whl
| Download URL | pyscarcopula-0.20.2-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 |
85dfbd95042644095e759f1c9821d05f85ce9c2174443d7a7b5adb7d76ba6c36
|
|
BLAKE2b-256 checksum How to use checksums |
85ff61a86da38115348246e8a99368159f343e786a816ed9bc106d0cdf39e7ea
|
| 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.2-cp311-cp311-win_amd64.whl
| Download URL | pyscarcopula-0.20.2-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 756.9 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
7756c0ec69bfe244175159ee8bb95b6c1ddd37b2d4f2919b07d8f80e6cc6cf8e
|
|
BLAKE2b-256 checksum How to use checksums |
c99ec3409f9c2dd4df7a987477574589e42a9d19a673183974717263ed413496
|
| 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.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pyscarcopula-0.20.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
45c5f68325720d57261b3c7ea1aa8ffd167b3c8f4329bc5c06ff107c466a013a
|
|
BLAKE2b-256 checksum How to use checksums |
82ee6b0157833bfeb97a7ef1d756ebb5148a9ee1dcf6f035a5fbefd4cd2abf90
|
| 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.2-cp311-cp311-macosx_10_9_universal2.whl
| Download URL | pyscarcopula-0.20.2-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 |
f740c793c01bb343ae4f7371874454c7c9d810ca56c944bb88226cb751d4fbf4
|
|
BLAKE2b-256 checksum How to use checksums |
7dbea1224babe7ba0e800e6dbef53dd8ca82f941cf2bb7c7e8cee589c208d51e
|
| 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.2-cp310-cp310-win_amd64.whl
| Download URL | pyscarcopula-0.20.2-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 756.0 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
987c587bf830247e33ce2bb588f27bf19b7f1c96bdb66e215c71fd3fc907f70b
|
|
BLAKE2b-256 checksum How to use checksums |
f414f025eb2df4c5c03c92933d81f3015534748294df8aa2710de9e743297337
|
| 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.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pyscarcopula-0.20.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
24a59799878b94899eff771d916a402760781101a8349a75a79ace4f33298638
|
|
BLAKE2b-256 checksum How to use checksums |
43b523266528df25f6ccc4003dfd8cfb85002941e94c7c82f23994827f81f31f
|
| 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.2-cp310-cp310-macosx_10_9_universal2.whl
| Download URL | pyscarcopula-0.20.2-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 |
f832450f55e454ee5f12f7cdb53f8f343d69ec0cc04a03befe9f411bf7be8598
|
|
BLAKE2b-256 checksum How to use checksums |
b85efe212972508d99fce100981b7d892f9b36d52174ed3e911b03d30d7f1e66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|