<div>Brian,</div><div><br></div><div>Thanks for sharing the paper and your ideas for the mapping function.</div><div><br></div><div>One of the main point I got from the methodology described in the paper is that the sets of weights are omitted instead of transformed if they do not meet the constraints.</div>
<div><ul><li>generate random portfolios</li><li>test each set of portfolio weights</li><li>if a constraint is violated, omit that set of weights</li><li>compute the objective function on each remaining set of weights</li>
<li>select the set of optimal weights</li></ul><div>Is this what you were getting at here?</div></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">"A slightly more rigorous treatment of the problem is given here:</span><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1680224" target="_blank" style="color:rgb(17,85,204);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">http://papers.ssrn.com/sol3/<u></u>papers.cfm?abstract_id=1680224</a><br style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">It is possible that can use this method directly for random portfolios."</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br>
</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">I could add a block of code at the end of random_portfolios that tests each set of weights against the constraints and only keeps the weights that </span><font color="#222222" face="arial, sans-serif">satisfy the constraints. Thoughts?</font></div>
<div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><br></span></div>If we have to transform the weights, here are my thoughts looking at the specific cases for constraint types<div>
Constraint Type</div><div><ul><li>Leverage (min_sum and max_sum)</li><ul><li>This is done in randomize_portfolio by randomly permuting and increasing or decreasing an individual element (asset weight) until min_sum and max_sum constraints are satisfied while taking into account box constraints. These constraints are satisfied based on the way random portfolios are constructed.</li>
<li>This is done in constrained_objective by transforming the entire vector (</li><ul><li>if(sum(w)>max_sum) { w<-(max_sum/sum(w))*w } # normalize to max_sum</li><li>if(sum(w)<min_sum) { w<-(min_sum/sum(w))*w } # normalize to min_sum</li>
</ul><li>Implement by moving this into the mapping function... correct?</li></ul><li>Box (min and max)</li><ul><li>This is done in randomize_portfolio by construction</li><li>This is done in constrained_objective by penalizing weights outside box constraints.</li>
<li>Implement by using logic from randomize_portfolio to transform weights instead of penalizing them. Goal is to transform the weights vector instead of penalize... correct?</li></ul><li>Group (cLO and cUP)</li><ul><li>One approach is to normalize the weights in each given group that violate cLO or cUP so that the group weights sum to cLO or cUP. This changes the sum of weights, so when the weights vector is normalized the group constraints will likely be violated, but it gets us close. See sandbox/testing_constrained_group.R</li>
<li>Another approach is to add this to randomize_portfolio so the group constraints as well as box and leverage are satisfied by construction. Need to spend more time understanding code in randomize_portfolio to see how feasible this is.</li>
</ul><li>turnover</li><ul><li>Could we include this in constrained_objective as a penalty?</li></ul><li>diversification</li><ul><li>Could we include this in constrained_objective as a penalty?</li></ul><li>volatility</li>
<ul><li>Could we include this in constrained_objective as a penalty?</li></ul><li>position_limit</li><ul><li>This may be able to be implemented in randomize_portfolio by generating portfolios with the number of non-zero weights equal to max.pos, then fill in weights of zero so the length of the weights vector is equal to the number of assets, then scramble the weights vector. The number of non-zero weights could also be random so that the number of non-zero weights is not always equal to max.pos. This could be implemented in the DEoptim solver with the mapping function. This might be do-able in Rglpk for max return and min ETL. Rglpk supports mixed integer types, but solve.QP does not. May be able to use branch-and-bound technique using solve.QP, but needs more research.</li>
</ul></ul></div><div><br></div><div>Regards,</div><div>Ross</div><div><br></div>
<div>
<br><div class="gmail_quote">On Sat, Jun 29, 2013 at 8:45 AM, Brian G. Peterson <span dir="ltr"><<a href="mailto:brian@braverock.com" target="_blank">brian@braverock.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Based on side conversations with Ross and Peter, I thought I should talk a little bit about next steps related to the mapping function.<br>
<br>
Apologies for the long email, I want to be complete, and I hope that some of this can make its way to the documentation.<br>
<br>
The purpose of the mapping function is to transform a weights vector that does not meet all the constraints into a weights vector that does meet the constraints, if one exists, hopefully with a minimum of transformation.<br>
<br>
In the random portfolios code, we've used a couple of techniques pioneered by Pat Burns. The philosophical idea is that your optimum portfolio is most likely to exist at the edges of the feasible space.<br>
<br>
At the first R/Finance conference, Pat used the analogy of a mountain lake, where the lake represents the feasible space. With a combination of lots of different constraints, the shore of the lake will not be smooth or regular. The lake (the feasible space) may not take up a large percentage of the terrain.<br>
<br>
If we randomly place a rock anywhere in the terrain, some of them will land in the lake, inside the feasible space, but most will land outside, on the slopes of the mountains that surround the lake. The goal should be to nudge these towards the shores of the lake (our feasible space).<br>
<br>
Having exhausted the analogy, let's talk details.<br>
<br>
A slightly more rigorous treatment of the problem is given here:<br>
<a href="http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1680224" target="_blank">http://papers.ssrn.com/sol3/<u></u>papers.cfm?abstract_id=1680224</a><br>
It is possible that can use this method directly for random portfolios (and that we could add the ectra constraint types to DEoptim). If so, much of the rest of what I'll write here is irrelevant. I strongly suspect that there will be some constraint types that will still need to be 'adjusted' via a mapping method like the one laid out below, since a stochastic solver will hand us a vector that needs to be transformed at least in part to move into the feasible space. It's alsom not entirely clear to me that the methods presented in the paper can satisfy all our constraint types.<br>
<br>
<br>
I think our first step should be to test each constraint type, in some sort of hierarchy, starting with box constraints (almost all solvers support box constraints, of course), since some of the other transformations will violate the box constraints, and we'll need to transform back again.<br>
<br>
Each constraint can be evaluated as a logical expression against the weights vector. You can see code for doing something similar with time series data in the sigFormula function in quantstrat. It takes advantage of some base R functionality that can treat an R object (in this case the weights vector) as an environment or 'frame'. This allows the columns of the data to be addressed without any major manipulation, simply by column name (asset name in the weights vector, possibly after adding names back in).<br>
<br>
The code looks something like this:<br>
eval(parse(text=formula), data)<br>
<br>
So, 'data' is our weights vector, and 'formula' is an expression that can be evaluated as a formula by R. Evaluating this formula will give us TRUE or FALSE to denote whether the weights vector is in compliance or in violation of that constraint. Then, we'll need to transform the weight vector, if possible, to comply with that constraint.<br>
<br>
Specific Cases:<br>
I've implemented this transformation for box constraints in the random portfolios code. We don't need the evaluation I'll describe next for box constraints, because each single weight is handled separately.<br>
<br>
min_sum and max_sum leverage constraints can be evaluated without using the formula, since the formula is simple, and can be expressed in simple R code. The transformation can be accomplished by transforming the entire vector. There's code to do this in both the random portfolios code and in constrained_objective. It is probably preferable to do the transformation one weight at a time, as I do in the random portfolios code, to end closer to the edges of the feasible space, while continuing to take the box constraints into account.<br>
<br>
linear (in)equality constraints and group constraints can be evaluated generically via the formula method I've described above. Then individual weights can be transformed taking the value of the constraint (<,>,=) into account (along with the box constraints and leverage constraints).<br>
<br>
and so on...<br>
<br>
Challenges:<br>
- recovering the transformed vector from a optimization solver that doesn't directly support a mapping function. I've got some tricks for this using environments that we can revisit after we get the basic methodology working.<br>
<br>
-allowing for progressively relaxing constraints when the constraints are simply too restrictive. Perhaps Doug has some documentation on this as he's done it in the past, or perhaps we can simply deal with it in the penalty part of constrained_objective()<br>
<br>
Hopefully this was helpful.<br>
<br>
Regards,<br>
<br>
Brian<span><font color="#888888"><br>
<br>
-- <br>
Brian G. Peterson<br>
<a href="http://braverock.com/brian/" target="_blank">http://braverock.com/brian/</a><br>
Ph: <a href="tel:773-459-4973" value="+17734594973" target="_blank">773-459-4973</a><br>
IM: bgpbraverock<br>
______________________________<u></u>_________________<br>
GSoC-PortA mailing list<br>
<a href="mailto:GSoC-PortA@lists.r-forge.r-project.org" target="_blank">GSoC-PortA@lists.r-forge.r-<u></u>project.org</a><br>
<a href="http://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/gsoc-porta" target="_blank">http://lists.r-forge.r-<u></u>project.org/cgi-bin/mailman/<u></u>listinfo/gsoc-porta</a><br>
</font></span></blockquote></div><br></div>