Building Ledoit–Wolf Minimum-Variance Weights from a Shrunk Covariance
Summary
The document presents an attempted minimum-variance portfolio calculation for stock returns. It estimates each asset’s market beta and residuals, forms a covariance estimate from a market factor and residual variances, applies covariance shrinkage, then computes weights proportional to the inverse covariance matrix multiplied by a vector of ones and normalized to sum to one.
The reported obstacle is a numerical singularity when inverting the shrunk covariance matrix. The discussion contains no answer or diagnosis, so it does not establish whether the estimator, data, or implementation is responsible. The code also leaves the number of assets undefined and gives no details about the shrinkage function or the dataset. It is therefore an illustration of the intended calculation and a troubleshooting question, rather than evidence that the method or implementation works as shown.
Key ideas
- The example estimates asset exposures to a market return and uses residual variances to construct a covariance estimate.
- Covariance shrinkage is applied before calculating global minimum-variance weights.
- The weights are obtained by inverse-covariance weighting and normalized to sum to one.
- The reported inverse fails numerically, and the document offers no resolution or validation.
Tags
Full text
# Ledoit-Wolf portfolio weights calculation
# Ledoit-Wolf portfolio weights calculation
I am trying to implement the Ledoit-Wolf minimum variance portfolio strategy on a real-world stock dataset.
```
library(quadprog)
library(Rsolnp)
#first I read in the data and the corresponding market rates:
data<-read.table("https://dl.dropboxusercontent.com/u/22681355/data.txt")
market.rate <-read.table("https://dl.dropboxusercontent.com/u/22681355/market.rate.txt")
sample.data<-data[1:120, ]
sample.market.rate<-market.rate[1:120]
# I calculate the Ledoit-Wulf portfolio strategy:
Te <- nrow(sample.data)
s2<-var(sample.market.rate)
estimates<-sapply(1:N, function(x) lm(sample.data[,x]~sample.market.rate ))
slopes<-sapply(1:N,function(x) estimates[,x]$coefficients[2])
residuals<-sapply(1:N, function(x) estimates[,x]$residuals)
B<-as.vector(slopes)
D<-diag(N)
diag(D)<-diag(cov(residuals))
Fe<- s2 * B %*% t(B) + D
S.hat<-cov_shrink(Fe)
cov.Rt<-S.hat
inv.cov<-solve(cov.Rt)
one.vec<-rep(1,N)
weights<-as.vector(inv.cov%*%one.vec)/( t(one.vec) %*% inv.cov %*% one.vec)
}
```
However, I get the following error:
```
Error in solve.default(cov.Rt) :
system is computationally singular: reciprocal condition number = 2.08164e-18
```
I must be doing something wrong because according to Ledoit Wolf their covariance estimator should not be computationally singular by construction.
Any ideas?Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.