[GSoC-PortA] add.constraint and optimize.portfolio_v2

Doug Martin martinrd at comcast.net
Wed Jul 17 02:01:47 CEST 2013


The code in testing_ROI_Martin new.R all seems to work.  So I am putting
together all the examples for a section in Chapter 2, hopefully finish by
tomorrow.  But here is a tiny usability improvement needed in the first
example with the new interface.  The following works fine:

 

pspec <- portfolio.spec(assets=funds)

pspec <- add.constraint(portfolio=pspec, type="full_investment",
enabled=TRUE)

pspec <- add.constraint(portfolio=pspec, type="box", min=-Inf, max=Inf,
enabled=TRUE)

pspec <- add.objective_v2(portfolio=pspec, type="risk", name="var",
enabled=TRUE)

 

However, I had expected that the following would also work  fine, but does
not:

 

pspec <- portfolio.spec(assets=funds)

pspec <- add.constraint(portfolio=pspec, type="full_investment",
enabled=TRUE)

pspec <- add.objective_v2(portfolio=pspec, type="risk", name="var",
enabled=TRUE)

 

opt <- optimize.portfolio_v2(R=returns, portfolio=pspec,
optimize_method="ROI")

Error in get_constraints(portfolio) : 

  Box constraints min and max are not enabled or passed in

 

There should be default argument values for box, min and max if not
provided, i.e., if box is not provided and group constraints are not
provided, it should assume an unconstrained portfolio except for the full
investment constraint.

 

Also, note the following behavior:

 

> args(add.constraint)

function (portfolio, type, enabled = FALSE, ..., indexnum = NULL) 

NULL

 

Is it possible for args to result in additional arguments of function that
will make more clear what they are?  Or by design are we stuck with the "."
to indicate all the other arguments possible?

 

Doug

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/gsoc-porta/attachments/20130716/5d7f67a7/attachment.html>


More information about the GSoC-PortA mailing list