The most robust solver for non-smooth functions I know of in R is
Nelder-Mead
in the 'dfoptim' package (that also allows for box constraints).
First throw out the equality constraint by using c(w1, w1, 1-w1-w2) as
input.
This will enlarge the domain a bit, but comes out allright in the end.
sharpe2 <- function(w) {
w <- c(w[1], w[2], 1-w[1]-w[2])
- (t(w) %*% y) / cm.CVaR(M, lgd, w, N, n, r, rho, alpha, rating)
}
nmkb(c(1/3,1/3), sharpe2, lower=c(0,0), upper=c(1,1))
## $par
## [1] 0.1425304 0.1425646
## $value
## [1] -0.03093439
This is still in the domain of definition, and is about the same optimum
that
solnp() finds.
There are some more solvers, especially aimed at non-smooth functions, in
the
making. For low-dimensional problems like this Nelder-Mead is a reasonable
choice.