[R-SIG-Finance] PortfolioAnalytics: Custom Constraint

Jason Hart jasonhart4 at icloud.com
Tue Sep 20 01:08:22 CEST 2016


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:

Error in optimize.portfolio(R = returns, portfolio = pspec, optimize_method = "pso", : 
unused arguments (R = returns, portfolio = pspec, optimize_method = "pso", trace = TRUE)


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.

Any help is much appreciated.

Jason   

On Sep 19, 2016, at 08:03 AM, "Brian G. Peterson" <brian at braverock.com> wrote:

On Mon, 2016-09-19 at 20:22 +0530, Abhay Bhadani wrote:
I just started exploring PortfolioAnalytics package.

Similar to setting up custom objective functions, is there a way to set up
custom constraints too?

I would like to know how to set up cardinality constraint (i.e., limiting
number of assets in a portfolio).

cardinality constraints are already supported via the 'position_limit'
constraint which is an integer constraint limiting the maximum number of
non-zero weight positions in the portfolio. It may be added like this:


pspec <- add.constraint(portfolio=pspec,
type="position_limit",
max_pos=3,
enabled=TRUE)

assuming that your portfolio specification object is 'pspec'.

As with other constraint types, this may not be efficiently supported by
all optimization engines. (This is a limitation of the underlying
optimizers/solvers, not of PortfolioAnalytics). 

On a more general note, any constraint may be expressed as an objective
by creating a penalty for violating the constraint. As noted above,
this may lead to very inefficient or non-converging optimization.

Regards,

Brian

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock

_______________________________________________
R-SIG-Finance at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20160919/3ffc9bc7/attachment.html>


More information about the R-SIG-Finance mailing list