Non-Linear Shrinkage Estimator from Ledoit and Wolf (2018)
Project description
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 nonlinshrink
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
.
For running the tests do
git clone https://github.com/matzhaugen/analytic_shrinkage.git
cd analytic_shrinkage
pip install -e . # install the package
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for nonlinshrink-0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bbc13ddc9283993dc08f89b90f160c3b389aa30f12d55282436bf9785e2471c |
|
MD5 | 424c8163236ff48e58066e0dd172211c |
|
BLAKE2b-256 | 8b0aaeb20552a2db5cfcc9e1c5b831295ef9785ea2eb9d428dce2d23d16c0da3 |