<html><body><div>I've never been able to get portfolioanalytics to work for me.  It looks like a nice little addition to the R arsenal but we just weren't meant to work together.  I figured what the heck I'll try this code and I got the same error message I usually get:</div><div><br data-mce-bogus="1"></div><div>Error in optimize.portfolio(R = returns, portfolio = pspec, optimize_method = "pso", : <br> unused arguments (R = returns, portfolio = pspec, optimize_method = "pso", trace = TRUE)</div><div><br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>I've installed all the dependent (or at least I think I have) but to no avail.  I installed pso, all the different ROI packages, Rcmdr.  I've seen other people with the same issue but did not see a solution.</div><div><br data-mce-bogus="1"></div><div>Any help is much appreciated.</div><div><br data-mce-bogus="1"></div><div>Jason   </div><div><br>On Sep 19, 2016, at 08:03 AM, "Brian G. Peterson" <brian@braverock.com> wrote:<br><br></div><div><blockquote type="cite"><div class="msg-quote"><div class="_stretch"><span class="body-text-content">On Mon, 2016-09-19 at 20:22 +0530, Abhay Bhadani wrote:<br><blockquote type="cite" class="quoted-plain-text">I just started exploring PortfolioAnalytics package.</blockquote><blockquote type="cite" class="quoted-plain-text"><br></blockquote><blockquote type="cite" class="quoted-plain-text">Similar to setting up custom objective functions, is there a way to set up</blockquote><blockquote type="cite" class="quoted-plain-text">custom constraints too?</blockquote><blockquote type="cite" class="quoted-plain-text"><br></blockquote><blockquote type="cite" class="quoted-plain-text">I would like to know how to set up cardinality constraint (i.e., limiting</blockquote><blockquote type="cite" class="quoted-plain-text">number of assets in a portfolio).</blockquote><br>cardinality constraints are already supported via the 'position_limit'<br>constraint which is an integer constraint limiting the maximum number of<br>non-zero weight positions in the portfolio. It may be added like this:<br><br><br>pspec <- add.constraint(portfolio=pspec,<br> type="position_limit",<br> max_pos=3,<br> enabled=TRUE)<br><br>assuming that your portfolio specification object is 'pspec'.<br><br>As with other constraint types, this may not be efficiently supported by<br>all optimization engines. (This is a limitation of the underlying<br>optimizers/solvers, not of PortfolioAnalytics). <br><br>On a more general note, any constraint may be expressed as an objective<br>by creating a penalty for violating the constraint. As noted above,<br>this may lead to very inefficient or non-converging optimization.<br><br>Regards,<br><br>Brian<br><br>-- <br>Brian G. Peterson<br><a href="http://braverock.com/brian/" data-mce-href="http://braverock.com/brian/">http://braverock.com/brian/</a><br>Ph: 773-459-4973<br>IM: bgpbraverock<br><br>_______________________________________________<br><a href="mailto:R-SIG-Finance@r-project.org" data-mce-href="mailto:R-SIG-Finance@r-project.org">R-SIG-Finance@r-project.org</a> mailing list<br><a href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance" data-mce-href="https://stat.ethz.ch/mailman/listinfo/r-sig-finance">https://stat.ethz.ch/mailman/listinfo/r-sig-finance</a><br>-- Subscriber-posting only. If you want to post, subscribe first.<br>-- Also note that this is not the r-help list where general R questions should go.<br></span></div></div></blockquote></div></body></html>