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

Doug Martin martinrd at comcast.net
Wed Jul 17 20:44:59 CEST 2013


Thanks!  Doug

 

 

From: gsoc-porta-bounces at lists.r-forge.r-project.org
[mailto:gsoc-porta-bounces at lists.r-forge.r-project.org] On Behalf Of Ross
Bennett
Sent: Tuesday, July 16, 2013 6:55 PM
To: PortfolioAnalytics
Subject: Re: [GSoC-PortA] add.constraint and optimize.portfolio_v2

 

 

On Tue, Jul 16, 2013 at 7:01 PM, Doug Martin <martinrd at comcast.net> wrote:

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.

 

I just committed a revision (r2583) that fixes this and sets default values
if leverage and box constraints are not specified. The default is set to
full investment constraint (min_sum=1 and max_sum=1) if leverage constraints
are not specified. The default is set to infinite bounds (min=rep(-Inf,
nassets) and max=rep(Inf, nassets)) if box constraints are not specified.

 

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?

 

I think we are stuck with "..." to indicate all other arguments for the
add.constraint function. However, I have links to the other functions that
add the constraints.

?add.constraint and check the "See Also" section. 

 

Alternatively, if you know the type of constraint and the function, you can
get the args of that function.

> args(box_constraint)

function (type, assets, min, max, min_mult, max_mult, enabled = TRUE, 

    ...) 

NULL

 

Thanks for the suggestions and feedback!

Ross

 

 

Doug

 

 


_______________________________________________
GSoC-PortA mailing list
GSoC-PortA at lists.r-forge.r-project.org
http://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/gsoc-porta

 

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


More information about the GSoC-PortA mailing list