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.0

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.0
File Size Uploaded
randomcov-0.2.0.tar.gz 24.8 kB Details

Built distribution (wheel)

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

Total release size: 57.6 kB

Release files / randomcov-0.2.0.tar.gz

Download URL randomcov-0.2.0.tar.gz
Size 24.8 kB
Tags Source
SHA-256 checksum
How to use checksums
49af3f3cebaec1291acc997e6dca6305a24cc150ba03a3c1bf29a5dfa4a8224c
BLAKE2b-256 checksum
How to use checksums
ceeeb2c0f38fd1ff210d23c8ea73e62943035a93bcc88e997bf5720cffd02154
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 22, 2026.

Transparency log

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

Download URL randomcov-0.2.0-py3-none-any.whl
Size 32.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58b060a5bc869c8160217beb16aea5e7659624857104709ac381ca088ce57592
BLAKE2b-256 checksum
How to use checksums
84ca8ae5459efd63cbf0ac0124a088632be7515ebbad50e40dab2a1f955f9818
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 22, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.1

2 release files

This release

0.2.0 This release

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