[R-SIG-Finance] Rsolnp for Portfolio Optimization with Turnover Constraints

alexios ghalanos alexios at 4dscape.com
Mon Jun 27 23:30:39 CEST 2011


Hi Bob,

This is likely a bug arising when there is no convergence (will upload a
fix for that soon) and introduced in the latest
version.
In your example, this arises because you set the starting parameters to
zero. Try instead:

x.init <- rep(1/14, 14)

Regards,

Alexios



On 6/27/2011 7:49 PM, Robert Harlow wrote:
> Hi,
>    I am trying to use Rsolnp in a portfolio optimization context.  While I
> know that my current example is solvable as QP, my risk function, which is
> variance right now, could become more complicated later.  Basically, I want
> to start with an equal weighted portfolio, and then minimize risk with a
> tracking error constraint.  I was able to achieve this relatively easily
> with fmincon in matlab, so I am wondering what the issue is here.
>
> My reproducible code is below:
>
> library(Matrix)
> library(Rsolnp)
> upper.tri <- c(17.82, 19.84, 4.96, 4, 3.79, 1.62, -.05,
>                35.67, 6.83, 3.52, 2.72, 1.07, -.07,
>                5.12, 3.52, 3.22, 1.81, .01,
>                6.18, 6.36, 3.24, .04,
>                7.95, 3.80, .05,
>                2.47, .06,
>                .04)
> cov.mat <- matrix(0, ncol = 7, nrow = 7)
> cov.mat[lower.tri(cov.mat, diag = TRUE)] <- upper.tri
> cov.mat <- t(cov.mat)
> cov.mat <- as.matrix(forceSymmetric(cov.mat))
> wInit <- rep(1,7)/7
> x.init <- rep(0, 2*7)
> eq.fun <- function(x, sigma, wInit){
>     sum(x[1:7]) - sum(x[8:14])
> }
> ob.fun <- function(x, sigma, wInit){
>     wgts <- wInit + x[1:7] - x[8:14]
>     as.numeric(wgts%*%sigma%*%wgts)
> }
> ineq.fun <- function(x, sigma, wInit){
>     sum(x[1:7])
> }
> tst <- solnp(x.init, fun = ob.fun, eqfun = eq.fun, eqB = 0, ineqfun =
> ineq.fun, ineqLB = 0, ineqUB = .1, LB = rep(0, 14), UB = rep(1,14), sigma =
> cov.mat, wInit = wInit)
>
> Thank you for the help,
> -Bob
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.



More information about the R-SIG-Finance mailing list