[R-SIG-Finance] PortfolioAnalytics: Custom Constraint

Brian G. Peterson brian at braverock.com
Mon Sep 19 17:02:09 CEST 2016


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



More information about the R-SIG-Finance mailing list