Skip to content

solve.QP

3 messages · guillaume.nicoulaud at halbis.com, Patrick Burns, Brian G. Peterson

#
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:

- Sum of weights = desired target or band

- Target beta = anything I want

- Maximum individual weights (both long and short)

- Minimum individual weights if below 1/n (n being the number of stocks in the investment universe)



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?



Thanks for your help!

G


Les informations contenues dans ce message sont confidentielles et peuvent constituer des informations privilegiees. Si vous n etes pas le destinataire de ce message, il vous est interdit de le copier, de le faire suivre, de le divulguer ou d en utiliser tout ou partie. Si vous avez recu ce message par erreur, merci de le supprimer de votre systeme, ainsi que toutes ses copies, et d en avertir immediatement l expediteur par message de retour.
Il est impossible de garantir que les communications par messagerie electronique arrivent en temps utile, sont securisees ou denuees de toute erreur ou virus. En consequence, l expediteur n accepte aucune responsabilite du fait des erreurs ou omissions qui pourraient en resulter.
--- ----------------------------------------------------- ---
The information contained in this e-mail is confidential. It...{{dropped}}
#
You can have a look at the POP package from
Burns Statistics, but it is commercial software.

Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
guillaume.nicoulaud at halbis.com wrote:

            
#
On Wednesday 10 January 2007 02:49, guillaume.nicoulaud at halbis.com wrote:
<...>
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