[R] The best solver for non-smooth functions?
Hans W Borchers
hwborchers at googlemail.com
Thu Jul 19 00:10:43 CEST 2012
Cren <oscar.soppelsa <at> bancaakros.it> writes:
>
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.
> # Whoops! I have just seen there's a little mistake
> # in the 'sharpe' function, because I had to use
> # 'w' array instead of 'ead' in the cm.CVaR function!
> # This does not change the main features of my,
> # but you should be aware of it
>
> ---
>
> # The function to be minimized
>
> sharpe <- function(w) {
> - (t(w) %*% y) / cm.CVaR(M, lgd, ead, N, n, r, rho, alpha, rating)
> }
>
> # This becomes...
>
> sharpe <- function(w) {
> - (t(w) %*% y) / cm.CVaR(M, lgd, w, N, n, r, rho, alpha, rating)
> }
>
> # ...substituting 'ead' with 'w'.
>
More information about the R-help
mailing list