Skip to main content

randomcov

Generating random covariance and correlation matrices with beautiful geodesic interpolation visualizations! 🎯

Install

pip install randomcov 

or for latest

pip install git+https://github.com/microprediction/randomcov.git

Example

from randomcov import random_covariance_matrix
cov = random_covariance_matrix(n=50, corr_method='residuals', var_method='lognormal')

Motivation

To collect standard but also novel correlation and covariance generation methods, in order to better understand when some estimation methods work better than others in different contexts: such as the construction of machine learning model ensembles, combinations of forecasts, or financial portfolios.

The geodesic interpolation capabilities enable smooth transformations between covariance structures while preserving mathematical properties, making it ideal for portfolio optimization and risk management applications.

Generator catalog

Every method: random_correlation_matrix(n, corr_method="<name>", corr_kwargs={...}). All generators accept rng= (int seed or numpy Generator) for reproducibility.

method measure / structure reference
lkj LKJ(eta) via Cholesky factor; eta=1 uniform on the elliptope Lewandowski, Kurowicka & Joe 2009
onion extended onion, exact LKJ(eta) Ghosh & Henderson 2003; LKJ 2009
vine C-vine partial correlations, Beta margins (LKJ-exact) Joe 2006
archakov_hansen Gaussian in matrix-log space + unit-diagonal fixed point Archakov & Hansen 2021
spectrum prescribed random eigenvalues (exp / dirichlet / marchenko_pastur / spiked), Haar frame, Givens diagonal restoration Bendel & Mickey 1978; Davies & Higham 2000; Johnstone 2001
wishart normalized Wishart sample correlation classical
residuals sample correlation of residual-driven paths this package
factor k factors + idiosyncratic, optional sparse links approximate-factor literature
hierarchical ultrametric / cophenetic from a random dendrogram Tumminello, Lillo & Mantegna
block_equicorr constant within/between blocks (DECO, block form) Engle & Kelly 2012
ar1 Toeplitz rho^ i-j
kernel RBF / Matern field on a random point cloud spatial statistics
sparse_precision random Gaussian graphical model (sparse inverse) graphical-model literature
walk perturbation random walk on the elliptope, nearest-corr projected this package
animals agent-based interacting sizes (emergent correlation) this package

There is no canonical "uniform" measure over covariance matrices, and the elliptope-uniform (LKJ eta=1) concentrates on weak correlations as n grows; robust conclusions require batteries across NAMED ensembles, which is what this catalog is for.

Correlation Inflation

An example of the kind of thing I wish to test against generative models.

Correlation Inflation: A Working Paper

The transformation preserves geometric properties while smoothly interpolating towards perfect correlation structure using differential geometry on the manifold of positive definite matrices.

Geodesic Interpolation Towards Perfect Correlation

Metadata

Release files for randomcov 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for randomcov 0.2.1
File Size Uploaded
randomcov-0.2.1.tar.gz 26.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for randomcov 0.2.1
File Interpreter ABI Platform
randomcov-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 60.0 kB

Release files / randomcov-0.2.1.tar.gz

Download URL randomcov-0.2.1.tar.gz
Size 26.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b3f26689c73a0629c87ae6fa62051fc43d6f74fb7f0897d48881ae7284f67528
BLAKE2b-256 checksum
How to use checksums
c68636b54547b8a8e765001e826c02cd6784e1314c699897736c4af394b2c33c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / randomcov-0.2.1-py3-none-any.whl

Download URL randomcov-0.2.1-py3-none-any.whl
Size 34.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ad857aaacf890a87a5d4429d978a3bd9fdec0d155e72892d6e179825af5aeab
BLAKE2b-256 checksum
How to use checksums
fc84e3088010fe9583fc72f9c37c684fd0dc6ed983aba4461d3f1f82eca64334
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.15

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release 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