<div dir="ltr">Brian,<div><br></div><div style>I really like your thoughts on separating constraints and objectives. I learned objectives and constraints in the same way that you mention them. Intuitively, it is easier to understand that the user would create the constraint object, the objective object, and then combine in a portfolio object.</div>
<div style><br></div><div style>Separating out the objectives and creating templates of objectives for minimum variance and other basic objective functions should make it easy to understand for the user as well how it is handled with the solvers.</div>
<div style><br></div><div style>The way the constraints object looks today seems to be very similar to what you have in mind for the portfoliospec object. Was that your intent so that the solvers see pretty much the same  object in the call to optimize.portfolio? Only now the portfoliospec object will be passed instead of the constraints object, is my understanding of your intentions correct?</div>
<div style><br></div><div style>This is what I am thinking the code will look *something* like to run a simple optimization problem.</div><div style><br></div><div style>#### Example R code</div><div style><br></div><div style>
# Specify a constraints object and add box constraints</div><div style>gen.constr = constraint(assets, min_sum=1, max_sum=1)</div><div style>gen.constr = add.constraint(gen.constr, min_weight=0.10, max_weight=0.4, type="box")</div>
<div style><br></div><div style># Specify an objective object for global minimum variance</div><div style>gen.obj = objective(type="GMV")</div><div style><br></div><div style># Specify a portfolio object</div><div style>
port.spec = portfoliospec(gen.constr, gen.obj)</div><div style><br></div><div style># Run the optimization</div><div style>solution = optimize.portfolio(data, port.spec)</div><div style>#####</div><div style><br></div><div style>
Thanks,</div><div style>Ross Bennett</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 17, 2013 at 6:51 AM, Brian G. Peterson <span dir="ltr"><<a href="mailto:brian@braverock.com" target="_blank">brian@braverock.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've been thinking a lot about this over the last week, and I'm going to propose an architecture for discussion.<br>

<br>
Right now, we have an object of type 'constraints' which also includes 'objectives'.<br>
<br>
I have always logically separated objectives from constraints in my head by saying that<br>
- constraints are something that are:<br>
  1. operable only on the weight vector and<br>
  2. metadata information about the portfolio (e.g. groups, asset names)<br>
  3. describe the *inputs* to the objective function<br>
<br>
- objectives are part of the *objective function* that<br>
  1. you calculate on the weight vector<br>
  2. describe business objectives for the *outcome* of the optimization<br>
<br>
I think we need to split these apart explicitly, and make the distinctions, and why they exist, more obvious to the user.<br>
<br>
First, I think we need a container object of type 'portfolio' or 'portfoliospec' that know what assets you have, and how you want to group them (e.g. sectors, size, whatever).  This is data about the portfolio, and is *independent* of and constraints or objectives you might have on that portfolio.<br>

<br>
Next, I think we need a constraints object.  Constraints, by their nature, are tied to the portfolio that they are created for.  They require knowledge of the portfolio metadata, or at the very least things like box constraints are typically derived from the size of the portfolio.<br>

<br>
Finally, I think we need a separate 'objectives' object.  To have objectives objects, with names, that specify things like minimum variance, maximum Sharpe ratio, or risk parity objectives.  These can be completely separate from the assets in the portfolio, and we could provide a number of template objective objects with the package.  I think the current way objectives are added and manipulated is fine, we just need to break it off a bit.<br>

<br>
For the template objectives that can be acted on by specific more efficient solvers, I think separating the objectives out will make it easier to identify that.<br>
<br>
optimize.portfolio needs all three of these components, even today, to do anything.  So I think we need to sort out how to specify them, then how to combine them.<br>
<br>
I suggest that we start by getting these specifications right first. Then we can start surgery in other parts of the code to use the new specification forms.<br>
<br>
My current thoughts are that a portfolio *contains* one or more constraints objects, since the constraints objects are dependent on the portfolio composition.  Then you optimize a portfolio by passing a portfolio specification into the optimizer, and telling it which constraints object to use (if you have more than one attached to the portfolio) and what objectives object you want to apply.<br>

<br>
Hopefully this is clear.  It's a proposal, so comments/critique/ideas always welcome.<br>
<br>
Today is officially the first day of coding, so we need to get moving.<br>
<br>
Regards,<br>
<br>
Brian<br>
<br>
<br>
<br>
<br>
On 06/06/2013 06:54 AM, Ross Bennett wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Professor Martin,<br>
<br>
Thank you for the feedback. Based on the suggestions from yourself and<br>
Brian Peterson, I will start with the constraints portion. I'll spend<br>
some more time looking at Kirk Li's code to understand it better and<br>
think about how to best integrate into PortfolioAnalytics. I should be<br>
able to use some ideas from it.<br>
<br>
I have been reviewing the code for PortfolioAnalytics and it seems that<br>
there is already a lot of the infrastructure in place for the constraint<br>
object and the optimizer so I don't want to maintain the interface to<br>
the optimize.portfolio function as much as possible.<br>
<br>
As an example, here is a code snippet of how box constraints and group<br>
constraints are currently specified.<br>
# General constraints object<br>
# Box constraints of minimum weight = 0.1 and maximum weight = 0.5 for<br>
assets<br>
gen.constr <- constraint(assets = colnames(edhec), min=0.1, max =0.5,<br>
min_sum=1, max_sum=1)<br>
<br>
# Add group constraints to the gen.constr object<br>
groups <- c(3,3,3,4)<br>
gen.constr$groups <- groups<br>
gen.constr$cLO <- rep(0.15,length(groups))<br>
gen.constr$cUP <- rep(0.30,length(groups))<br>
<br>
Following the outline on the GSOC2013 PortfolioAnalytics rwiki page, we<br>
would remove box constraints from the constraint() function and create<br>
an add.constraint() function to add/update box, group, and other<br>
constraint types as applicable.<br>
<br>
# Create the initial constraint object<br>
# Pass in a character vector of asset names for assets<br>
# Portfolio weights must sum to 1 (min_sum=1 and max_sum=1)<br>
gen.constr <- constraint(assets = colnames(edhec), min_sum=1, max_sum=1)<br>
<br>
# Add box constraints with asset weights greater than 0.1 and less than 0.5<br>
gen.constr <- add.constraint(constraints=<u></u>gen.constr, type="box",<br>
                                           min=0.1, max=0.5)<br>
<br>
# Group constraints for 10 assets<br>
# Separate assets into groups of 3, 3, and 4 assets<br>
# Specify the group weights as a vector<br>
# The first 3 assets shall have a group weight of greater than 0.15 and<br>
less than 0.3<br>
# The next 3 assets shall have a group weight of greater than 0.1 and<br>
less than 0.35<br>
# The last 4 assets shall have a group weight greater than 0 and less<br>
than 0.4<br>
constr <- add.constraint(constraints=<u></u>constr, type="group",<br>
                                     groups=c(3, 3, 4),<br>
                                     group_min=c(0.15, 0.1, 0),<br>
                                     group_max=c(0.3, 0.35, 0.4))<br>
<br>
This keeps the constraint object and interface to optimize.portfolio()<br>
consistent with the existing code, but simplifies it and makes adding<br>
box and group constraints very similar.<br>
<br>
I will continue to review the PortfolioAnalytics source code and we can<br>
revisit this so that I can hit the ground running when finals are over<br>
and start as soon as possible.<br>
<br>
Regards,<br>
Ross Bennett<br>
<br>
<br>
On Wed, Jun 5, 2013 at 9:23 AM, Doug Martin <<a href="mailto:martinrd@comcast.net" target="_blank">martinrd@comcast.net</a><br>
<mailto:<a href="mailto:martinrd@comcast.net" target="_blank">martinrd@comcast.net</a>>> wrote:<br>
<br>
    Ross and all,____<br>
<br>
    __ __<br>
<br>
    I think starting with the constraints is a good idea.  But I think a<br>
    review of where PortfolioAnalytics functionality is as of last<br>
    year’s GSoC should be the first priority.  How planning on that week<br>
    after next (Guy, Eric and I all have finals week to get out of the<br>
    way next week).____<br>
<br>
    __ __<br>
<br>
    With regard to constraints, that approach that Kirk Li (UW<br>
    Statistics Ph.D. student and AMATH 543 TA this spring) developed<br>
    looks useful.  Ross you already have the code which I posted to the<br>
    class web site.  I have attached it here for others on this project<br>
    to have a look at.   Let’s review that after the end of next week<br>
    when final exams and the spring quarter are completely behind us.____<br>
<br>
    __ __<br>
<br>
    Doug____<br>
<br>
    __ __<br>
<br>
    __ __<br>
<br>
    *From:*<a href="mailto:gsoc-porta-bounces@lists.r-forge.r-project.org" target="_blank">gsoc-porta-bounces@<u></u>lists.r-forge.r-project.org</a><br>
    <mailto:<a href="mailto:gsoc-porta-bounces@lists.r-forge.r-project.org" target="_blank">gsoc-porta-bounces@<u></u>lists.r-forge.r-project.org</a>><br>
    [mailto:<a href="mailto:gsoc-porta-bounces@lists.r-forge.r-project.org" target="_blank">gsoc-porta-bounces@<u></u>lists.r-forge.r-project.org</a><br>
    <mailto:<a href="mailto:gsoc-porta-bounces@lists.r-forge.r-project.org" target="_blank">gsoc-porta-bounces@<u></u>lists.r-forge.r-project.org</a>>] *On Behalf<br>
    Of *Ross Bennett<br>
    *Sent:* Wednesday, June 05, 2013 4:22 AM<br>
    *To:* <a href="mailto:gsoc-porta@lists.r-forge.r-project.org" target="_blank">gsoc-porta@lists.r-forge.r-<u></u>project.org</a><br>
    <mailto:<a href="mailto:gsoc-porta@lists.r-forge.r-project.org" target="_blank">gsoc-porta@lists.r-<u></u>forge.r-project.org</a>><br>
    *Subject:* [GSoC-PortA] Schedule for PortfolioAnalytics Coding____<br>
<br>
    __ __<br>
<br>
    All,____<br>
<br>
    __ __<br>
<br>
    In my GSOC proposal, the order of what components I planned to write<br>
    code for was as follows:____<br>
<br>
     1. Utility Functions (print, summary, plot, etc.)____<br>
     2. Constraints____<br>
     3. Example Functionality____<br>
<br>
    In speaking with Brian Peterson at R/Finance, he suggested that the<br>
    constraints portion be done first. I am fine with doing constraints<br>
    first. Would you like me to submit a revised schedule and<br>
    implementation plan with constraints first?____<br>
<br>
    __ __<br>
<br>
    Thanks,____<br>
<br>
    Ross Bennett____<br>
</blockquote>
______________________________<u></u>_________________<br>
GSoC-PortA mailing list<br>
<a href="mailto:GSoC-PortA@lists.r-forge.r-project.org" target="_blank">GSoC-PortA@lists.r-forge.r-<u></u>project.org</a><br>
<a href="http://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/gsoc-porta" target="_blank">http://lists.r-forge.r-<u></u>project.org/cgi-bin/mailman/<u></u>listinfo/gsoc-porta</a><br>
</blockquote></div><br></div>