<div dir="ltr">The check for min_sum and max_sum is done right away in randomize_portfolio_v2. The main reason why I added this check and wiggle room for min_sum and max_sum inside of the function is to speed up generating the random portfolio and ensure that a reasonable number of portfolios can be generated. <div>
<br></div><div>Another logical place for this check would be in the check_constraints function, this would prevent portfolios being eliminated. Even if we do this check here, constrained_objective will penalize a large number of sets of weights that do not sum to exactly 1. I think it also might make sense to add a check in optimize.portfolio and issue a warning to the user that min_sum and max_sum may be too restrictive. This will apply to optimize_method="random" and optimize_method="DEoptim" because we are using logic from random portfolios as a mapping function in DEoptim.</div>
<div><br></div><div style>Ross</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Sep 24, 2013 at 9:52 AM, Peter Carl <span dir="ltr"><<a href="mailto:peter@braverock.com" target="_blank">peter@braverock.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks, that does work.  Should the check done in randomize_portfolio_v2<br>
be moved up the chain to catch that issue earlier?<br>
<div class="HOEnZb"><div class="h5">--<br>
Peter Carl<br>
<a href="http://www.braverock.com/peter" target="_blank">http://www.braverock.com/peter</a><br>
<br>
> The reason for fewer random portfolios being generated is due to the<br>
> leverage constraints in init.portf. There is a block of code in<br>
> randomize_portfolio_v2 (which is called by rp_sample) that will check for<br>
> a<br>
> difference in min_sum and max_sum. For example, if min_sum=1 and<br>
> max_sum=1,<br>
> we temporarily modify min_sum=0.99 and max_sum=1.01 so that random<br>
> portfolios can be generated.<br>
><br>
> Then in random_portfolios, there is a block of code that eliminates<br>
> portfolios that do not satisfy the constraints with the check_constraints<br>
> function. This takes place for random portfolios generated by the sample,<br>
> simplex, and grid method. Because rp_sample will generate portfolios with<br>
> weights that sum from 0.99 to 1.01, there are several portfolios that<br>
> violate leverage constraints of min_sum=1 and max_sum=1 and therefore will<br>
> be eliminated.<br>
><br>
> If you change the init.portf leverage constraints to min_sum=0.99 and<br>
> max_sum=1.01 you should generate 1000 portfolios.<br>
><br>
> I'll add some of this content to the @details in random_portfolios to<br>
> explain how the function is sensitive to leverage constraints.<br>
><br>
> Thanks,<br>
> Ross<br>
><br>
><br>
><br>
><br>
> On Tue, Sep 24, 2013 at 8:15 AM, Ross Bennett<br>
> <<a href="mailto:rossbennett34@gmail.com">rossbennett34@gmail.com</a>>wrote:<br>
><br>
>> Thanks for making me aware of this. I'll take a closer look and try to<br>
>> figure out what is going on.<br>
>><br>
>> Ross<br>
>> On Sep 24, 2013 8:03 AM, "Peter Carl" <<a href="mailto:peter@braverock.com">peter@braverock.com</a>> wrote:<br>
>><br>
>>> Fair point.  I get the same result when I use high values for<br>
>>> max_permutations.  That attribute should probably be referenced in the<br>
>>> function documentation under details, so that users know it can be<br>
>>> passed<br>
>>> through dots.<br>
>>><br>
>>> Same result though.  When I call rp_sample directly:<br>
>>> rp_sample(init.portf, permutations=1000)<br>
>>> ... I get 1000 rows back.<br>
>>><br>
>>> So something's happening in the dispatch code?<br>
>>><br>
>>> pcc<br>
>>> --<br>
>>> Peter Carl<br>
>>> <a href="http://www.braverock.com/peter" target="_blank">http://www.braverock.com/peter</a><br>
>>><br>
>>> > On 09/24/2013 09:28 AM, Peter Carl wrote:<br>
>>> >> The random_portfolios function isn't generating the correct number<br>
>>> of<br>
>>> >> permutations.<br>
>>> >><br>
>>> >>> >random_portfolios(portfolio=init.portf, permutations=1000)<br>
>>> >> gives me a result with 317 weight vectors, rather than 1000.<br>
>>> >><br>
>>> >> I think that there's a loop missing: when the number of lines is<br>
>>> less<br>
>>> >> than<br>
>>> >> permutations, the function needs to generate more, check for unique<br>
>>> >> solutions, and repeat until there are (in this case) 1000 weight<br>
>>> >> vectors.<br>
>>> >><br>
>>> >> Although (and it's difficult to tell), on their own the charts seem<br>
>>> to<br>
>>> >> generate about the right number?  Or maybe not...<br>
>>> ><br>
>>> > I suspect that given your constraints you're just hitting<br>
>>> > max_permutations.<br>
>>> ><br>
>>> > All that code is still there, so it seems most likely that you just<br>
>>> > don't have max_permutations high enough, or that your granularity on<br>
>>> the<br>
>>> > sequence is too high (e.g. you're using a step size of .01, and<br>
>>> should<br>
>>> > try .005)<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">773-459-4973</a><br>
>>> > IM: bgpbraverock<br>
>>> > _______________________________________________<br>
>>> > GSoC-PortA mailing list<br>
>>> > <a href="mailto:GSoC-PortA@lists.r-forge.r-project.org">GSoC-PortA@lists.r-forge.r-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-project.org/cgi-bin/mailman/listinfo/gsoc-porta</a><br>
>>> ><br>
>>><br>
>>><br>
>>> _______________________________________________<br>
>>> GSoC-PortA mailing list<br>
>>> <a href="mailto:GSoC-PortA@lists.r-forge.r-project.org">GSoC-PortA@lists.r-forge.r-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-project.org/cgi-bin/mailman/listinfo/gsoc-porta</a><br>
>>><br>
>><br>
> _______________________________________________<br>
> GSoC-PortA mailing list<br>
> <a href="mailto:GSoC-PortA@lists.r-forge.r-project.org">GSoC-PortA@lists.r-forge.r-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-project.org/cgi-bin/mailman/listinfo/gsoc-porta</a><br>
><br>
<br>
<br>
_______________________________________________<br>
GSoC-PortA mailing list<br>
<a href="mailto:GSoC-PortA@lists.r-forge.r-project.org">GSoC-PortA@lists.r-forge.r-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-project.org/cgi-bin/mailman/listinfo/gsoc-porta</a><br>
</div></div></blockquote></div><br></div>