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.1
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.1.tar.gz | 6.4 MB | Details |
Built distributions (wheels)
Total release size:22.2 MB
Release files / pyscarcopula-0.20.1.tar.gz
| Download URL | pyscarcopula-0.20.1.tar.gz |
|---|---|
| Size | 6.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0054d051373387147cfa1d7e07a13a1ccc87a61ad2708c06d5a88809b0962be
|
|
BLAKE2b-256 checksum How to use checksums |
85fd20f4d3d5845ccb3700d4be6e909d432bb78ef0e6725bc2810cd2a0eb864a
|
| 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.1-cp314-cp314-win_amd64.whl
| Download URL | pyscarcopula-0.20.1-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 772.1 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
9b41a66a74a3890531de7d282409f5dcbb74618acad02df0e6e89ba902c368d8
|
|
BLAKE2b-256 checksum How to use checksums |
50a749ae59b5521b5c94787af3ee55f8982219d9852ed364ea6cd6a559e0eea3
|
| 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.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pyscarcopula-0.20.1-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 |
522f8320fe4ca01acdf4a46939133127260ddc5ebc1ff3687d8a6b74360d3f75
|
|
BLAKE2b-256 checksum How to use checksums |
bff92d52d4fbf25cd6e97c33c6270a2534281be9c0dd3b5ac161f7ee387d9489
|
| 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.1-cp314-cp314-macosx_10_15_universal2.whl
| Download URL | pyscarcopula-0.20.1-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 |
57c20eb7063a85e05ae0c3fec56e591476938af30b6867aaa4b7d095517e5c23
|
|
BLAKE2b-256 checksum How to use checksums |
b6303fcad84a23090c63996909ac027220ec96259000df4a28d013f4005e5231
|
| 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.1-cp313-cp313-win_amd64.whl
| Download URL | pyscarcopula-0.20.1-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 760.6 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
919a2c8343043fa75e1f8344324688fe313cc41e8e671b90d108de3dc659a17a
|
|
BLAKE2b-256 checksum How to use checksums |
a462fa4839701fabde6b1304499a9c52415601b7b4c0067caaf99d6bed9025f1
|
| 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.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pyscarcopula-0.20.1-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 |
9081b28e6afdbb0e2dde350b165aba2030133ffc0d632e974e7bcb2268a34faf
|
|
BLAKE2b-256 checksum How to use checksums |
f3af871d0f5f565e45b7cf722474a8120b63d2d279c667677b29a8af6c464e89
|
| 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.1-cp313-cp313-macosx_10_13_universal2.whl
| Download URL | pyscarcopula-0.20.1-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 |
6783296337a2445fcdcf0ec51019134c4884a0a14ffc3139bdccde65746f9958
|
|
BLAKE2b-256 checksum How to use checksums |
b4ac2b7de35adc4d0f20c860bd0c506efb14dc11c965768e9d456b508be914f8
|
| 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.1-cp312-cp312-win_amd64.whl
| Download URL | pyscarcopula-0.20.1-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 760.6 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
2e9614a923a73c370c0a1812744128879d03756e51ebbad7fb96c041aaf45f70
|
|
BLAKE2b-256 checksum How to use checksums |
d6f255f452106697470a628d6a117e85eff8bca434ce69070f52b08a7d996292
|
| 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.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pyscarcopula-0.20.1-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 |
6c6806efcf25d40e6f572d6669ab3ba8195cf388ea134ef076c40a990e123323
|
|
BLAKE2b-256 checksum How to use checksums |
5f51d3a58e0302bbc52a2392d9f97f17cca126092cce94bc3474307d8eefc86b
|
| 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.1-cp312-cp312-macosx_10_13_universal2.whl
| Download URL | pyscarcopula-0.20.1-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 |
520a57b4fabcbeb636262c2cd4f44ac17e7e23dd810991334f42155bc907591d
|
|
BLAKE2b-256 checksum How to use checksums |
7077730008914be429eff06aefdff6d4ef56fe0f6bbd3cd796695e31f8dcea94
|
| 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.1-cp311-cp311-win_amd64.whl
| Download URL | pyscarcopula-0.20.1-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 757.8 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
795e26e91d9f0404b6c9beb542e69d715f17865977fa18dbb3d0d13862a3bab7
|
|
BLAKE2b-256 checksum How to use checksums |
cb2e0c299de0b99ecf84a96e5a4243415525035f9aa366975ca020e4079b866f
|
| 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.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pyscarcopula-0.20.1-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 |
e4f0d6b21a2d5d306ead320a975578f2c55eca1c93813c130a57fbedcb813e88
|
|
BLAKE2b-256 checksum How to use checksums |
5659869d800804b61beb64ed8060bf6aa1c78fd0164661dfc0634f79570a94c1
|
| 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.1-cp311-cp311-macosx_10_9_universal2.whl
| Download URL | pyscarcopula-0.20.1-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 |
bbfe874c7a74978d3760308b0e0e865fc14cbe94e5c03bb6de8d3fe317ca3e64
|
|
BLAKE2b-256 checksum How to use checksums |
7081c1d55a02a80ef0ff2d7ad4023ee66d44d3204758e8823ddacfe48775fd75
|
| 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.1-cp310-cp310-win_amd64.whl
| Download URL | pyscarcopula-0.20.1-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 757.0 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
87f255336536d0102e4103637b72596fa248de8a5433d229fc923a68cabd8ba4
|
|
BLAKE2b-256 checksum How to use checksums |
5b0377a0cc2f84036d89e8df447025c9f693193ae359c30d05c9ffd655bb88ed
|
| 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.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pyscarcopula-0.20.1-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 |
5b9b888ebfdee225ba72ed643e88dfa70807473156d553baae7e8cca3213ef79
|
|
BLAKE2b-256 checksum How to use checksums |
12820e932859d4d57f5b47c130c34303d89f501b4ee3e297294ff3f906e9ed1a
|
| 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.1-cp310-cp310-macosx_10_9_universal2.whl
| Download URL | pyscarcopula-0.20.1-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 |
7d01894a8157adc2938920aa531f96bb0cf6286e7cfd15e3d4c1a1e0507d23f9
|
|
BLAKE2b-256 checksum How to use checksums |
5893ce5f13f8d9514cb769a66d16a622a942c6e7ffee1ccd3c453e70d6a6ec02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|