Commit 319ae667 authored by Martin Maechler's avatar Martin Maechler

CLA(): plus optional arguments 'give.MS' and 'keep.names'

parent 38b5f1a0
......@@ -77,7 +77,7 @@
}
CLA <- function(mu, covar, lB, uB, tol.lambda = 1e-7) {
CLA <- function(mu, covar, lB, uB, tol.lambda = 1e-7, give.MS = TRUE, keep.names = TRUE) {
## minimal argument checks
n <- length(mu)
if(length(lB) == 1) lB <- rep.int(lB, n)
......@@ -161,9 +161,10 @@
free_indices <- c(free_indices, list(sort(f)))
} #end While
if(keep.names) rownames(weights_set) <- names(mu)
list(weights_set = weights_set,
free_indices = free_indices,
gammas = gammas, lambdas = lambdas,
MS_weights = MS(weights_set = weights_set, mu = mu, covar = covar))
MS_weights = if(give.MS) MS(weights_set = weights_set, mu = mu, covar = covar))
}
......@@ -8,7 +8,7 @@
... TODO: write more; give references (below) ...
}
\usage{
CLA(mu, covar, lB, uB, tol.lambda = 1e-07)
CLA(mu, covar, lB, uB, tol.lambda = 1e-07, give.MS = TRUE, keep.names = TRUE)
}
\arguments{
\item{mu}{numeric vector of length \code{n} containing the expected
......@@ -18,8 +18,11 @@ CLA(mu, covar, lB, uB, tol.lambda = 1e-07)
\item{lB, uB}{vectors of length \code{n} with lower and upper bounds
for the asset weights.}
\item{tol.lambda}{the tolerance when checking for lambda changes or
being zero.
}
being zero.}
\item{give.MS}{\code{\link{logical}} indicating if \code{\link{MS}()}
should be computed (and returned) as well.}
\item{keep.names}{\code{\link{logical}} indicating if the
\code{weights_set} matrix should keep the (asset) \code{names(mu)}.}
}
%% \details{
%% }
......@@ -37,7 +40,8 @@ CLA(mu, covar, lB, uB, tol.lambda = 1e-07)
\references{
TODO
}
\author{Alexander No..., Yanhao Shi, Martin Maechler}
\author{Alexander Norring did the very first version. Current
implementation: Yanhao Shi and Martin Maechler}
%% \note{
%% }
\seealso{
......@@ -45,14 +49,14 @@ TODO
}
\examples{
data(muS.sp500)
## Full data takes too much time for example ?
## NB: lB or uB of length 1 now work :
system.time(# ~ 9 sec
CLs5c.0.120 <- CLA(muS.sp500$mu, muS.sp500$covar, lB=0, uB=1/20)
)
## 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)
if(require(Matrix)) { ## visualize how weights change "along turning points"
image(Matrix(CLs5c.0.120$weights_set, sparse=TRUE),
image(Matrix(CLsp.24$weights_set, sparse=TRUE),
xlab = "turning point", ylab = "asset number")
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment