solve.QP (for portfolio optimization)
On Wednesday 10 January 2007 02:49, guillaume.nicoulaud at halbis.com wrote:
Dear all, I use solve.QP for Markowitz-like portfolio optimization purposes and I am trying to set some basic constraints. So far I have achieved to pass the followings:
<...>
And now here is what I would like to do: - Setting a target number of non-zero weights (I want - say - 30 longs and shorts...) - Setting a target gross exposure e.g. sum(abs(wi)) == 2 Does anybody has a piece of code I could adapt to do this? Is there any other function that I could use with same level of flexibility than solve.QP?
I see the Patrick and Christian have already replied to this post as well, so I'll try not to be redundant. If you can define your constraints as linear constraints, you may be able to use linear programming such as the simplex() fn in R to construct the surface to optimize over. It appears to be a general truism that I've discovered as I dig deeper into the optimization problem that the more constraints you place on a portfolio, the more likely you are to not create a smooth surface, and open yourself to problems of local maxima/minima. In one of my early forrays into optimization in R, Patrick suggested 'A Data-driven optimization heuristic for downside risk minimization' by Gilli et al. which discussed a technique called threshold accepting which allows the setting of multiple arbitrary heuristic and quantitative constraints. This would be very useful as an optimization mechanism, but also be quite problem-dependent, and not simple to implement in R. Techniques such as threshold accepting (suggested by Patrick to me), genetic algorithm (suggested to you by Christian), simulated annealing, bayesian optimization, or utility function based optimization (using brute force or sub-sampling) can avoid the local maxima/minima problem. Since you appear to want to stick with Markowitz-style optimization for now, one "easy" approach that I can recommend is to use a pricing model, such as CAPM or Arbitrage Pricing Theory, that is appropriate to your problem space to separate your long and short portfolios *before* attempting optimization. Markowitz or similar optimizations will work fine for your long portfolio, and you'll need to evaluate whether Markowitz will work well for your short portfolio. You may find, as many others in the optimization literature have, that the short portfolio requires a different optimization approach. If you're looking for a reference, Introduction to Modern Portfolio Optimization with NuOPT, S-PLUS and S+Bayes by Bernd Scherer, R. Douglas Martin Is quite a good overview, and although the code is for S-Plus, many/most of the functions have good analogs in R. Regards, - Brian