Non-Linear Shrinkage
Provides a function that calculates an estimate of the covariance matrix shrunk using a non-linear analytic formula provided by the working paper Ledoit and Wolf (2018), entitled ['Analytical Nonlinear Shrinkage of Large-Dimensional Covariance Matrices'] (http://www.econ.uzh.ch/static/wp/econwp264.pdf).
Installation
pip install non-linear-shrinkage
Usage
import numpy as np
import nonlinshrink as nls
p = 2
n = 13
sigma = np.eye(p, p)
data = np.random.multivariate_normal(np.zeros(p), sigma, n)
sigma_tilde = nls.shrink_cov(data)
The data is automatically demeaned unless otherwise specified. In the case where the data has been pre-processed and the effective degrees of freedom of the dataset is decreased, e.g. through an OLS regression, the user can specify this through a parameter k which signifies the degrees of freedom already subtracted. For example,
import numpy as np
import nonlinshrink as nls
p = 2
n = 14
sigma = np.eye(p, p)
data = np.random.multivariate_normal(np.zeros(p), sigma, n) + np.arange(n)[:, np.newaxis] + 1
x = np.vstack((np.ones(n).T, np.arange(n).T)).T
betahat = np.linalg.solve(np.dot(x.T, x), np.dot(x.T, data))
datahat = np.dot(x, betahat)
res = data - datahat
sigma_tilde = nls.shrink_cov(res, k=2) # corresponding to 2 degrees of freedom
Developing
Please submit a PR! The shrinkage function itself is located in nonlinshrink.py.
If using conda, set up the project by doing the following:
# Create conda env
conda env create -f environment.yml
# Activate env
conda activate non_linear_shrinkage
# Perform local editable install
pip install -e . --no-deps
If using pip or other venv manager:
pip install -e .
Then you can run the tests with the following command:
pytest
Metadata
Release files for non-linear-shrinkage 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| non-linear-shrinkage-1.0.0.tar.gz | 4.9 kB | Without provenance | Details for non-linear-shrinkage-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| non_linear_shrinkage-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for non_linear_shrinkage-1.0.0-py3-none-any.whl |
Total release size: 10.1 kB
Release files / non-linear-shrinkage-1.0.0.tar.gz
| Download URL | non-linear-shrinkage-1.0.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f3ad517f49ba884fa86663d29f06bb5f7bae73cb4f5a5507dc3f66771d7d3310
|
|
BLAKE2b-256 checksum How to use checksums |
86a2a450ef0ed35c984ba811410b7807436ccc1db296a0d9930e0302753b9a90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/0.0.0 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
|
Release files / non_linear_shrinkage-1.0.0-py3-none-any.whl
| Download URL | non_linear_shrinkage-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
047c432bc3a1f9fbc0cb5631f3b5d92b7b6be98766620ce23fb08db831bf98d6
|
|
BLAKE2b-256 checksum How to use checksums |
d36feadaaac16395411543a41763ad51cf25b5966d30590e49c0b85e7bd16d44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/0.0.0 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
|
Security for non-linear-shrinkage 1.0.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.