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,
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.
Brian G. Peterson
R-SIG-Finance@r-project.org mailing list
-- 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