data(muS.sp500)
## Full data taking too much time for example
set.seed(47)
iS <- sample.int(length(muS.sp500$mu), 24)
CLsp.24 <- CLA(muS.sp500$mu[iS], muS.sp500$covar[iS, iS], lB=0, uB=1/10)
CLsp.24 # using the print() method for class "CLA"
plot(CLsp.24)
if(require(Matrix)) { ## visualize how weights change "along turning points"
show(image(Matrix(CLsp.24$weights_set, sparse=TRUE),
main = "CLA(muS.sp500 ) $ weights_set",
xlab = "turning point", ylab = "asset number"))
}
## A 3x3 example (from real data) where CLA()'s original version failed
## and 'check.f = TRUE' produces a warning :
mc3 <- list(
mu = c(0.0408, 0.102, -0.023),
cv = matrix(c(0.00648, 0.00792, 0.00473,
0.00792, 0.0334, 0.0121,
0.00473, 0.0121, 0.0793), 3, 3,
dimnames = list(NULL,
paste0(c("TLT", "VTI","GLD"), ".Adjusted"))))
rc3 <- with(mc3, CLA(mu=mu, covar=cv, lB=0, uB=1, trace=TRUE))
Run the code above in your browser using DataLab