Description Usage Arguments Value References Examples
View source: R/CovEst.2003LW.R
Ledoit and Wolf (2003, 2004) proposed a linear shrinkage strategy to estimate covariance matrix with an application to portfolio optimization. An optimal covariance is written as a convex combination as follows,
\hat{Σ} = δ \hat{F} + (1-δ) \hat{S}
where δ \in (0,1) a control parameter/weight, \hat{S} an empirical covariance matrix, and \hat{F} a target matrix. Although authors used F a highly structured estimator, we also enabled an arbitrary target matrix to be used as long as it's symmetric and positive definite of corresponding size.
1 | CovEst.2003LW(X, target = NULL)
|
X |
an (n\times p) matrix where each row is an observation. |
target |
target matrix F. If |
a named list containing:
a (p\times p) covariance matrix estimate.
an estimate for convex combination weight according to the relevant theory.
ledoit_improved_2003CovTools
\insertRefledoit_well-conditioned_2004CovTools
\insertRefledoit_honey_2004CovTools
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | ## CRAN-purpose small computation
# set a seed for reproducibility
set.seed(11)
# small data with identity covariance
pdim <- 5
dat.small <- matrix(rnorm(20*pdim), ncol=pdim)
# run the code with highly structured estimator
out.small <- CovEst.2003LW(dat.small)
# visualize
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,3), pty="s")
image(diag(5)[,pdim:1], main="true cov")
image(cov(dat.small)[,pdim:1], main="sample cov")
image(out.small$S[,pdim:1], main="estimated cov")
par(opar)
## Not run:
## want to see how delta is determined according to
# the number of observations we have.
nsamples = seq(from=5, to=200, by=5)
nnsample = length(nsamples)
# we will record two values; delta and norm difference
vec.delta = rep(0, nnsample)
vec.normd = rep(0, nnsample)
for (i in 1:nnsample){
dat.norun <- matrix(rnorm(nsamples[i]*pdim), ncol=pdim) # sample in R^5
out.norun <- CovEst.2003LW(dat.norun) # run with default
vec.delta[i] = out.norun$delta
vec.normd[i] = norm(out.norun$S - diag(pdim),"f") # Frobenius norm
}
# let's visualize the results
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,2))
plot(nsamples, vec.delta, lwd=2, type="b", col="red", main="estimated deltas")
plot(nsamples, vec.normd, lwd=2, type="b", col="blue",main="Frobenius error")
par(opar)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.