<div dir="ltr">All,<div><br></div><div>With finals being over (for me at least, I do realize that Prof. Yollin and Prof. Martin still have grading) I am anxious to get started today with the first day of coding. </div><div>
<br></div><div>When I am writing or editing code, should I be working directly in the PortfolioAnalytics/R files or should I work in the sandbox folder so that I have a safe area to "play" without worrying about messing up existing code?</div>
<div><br></div><div>With the recent discussions of separating the objectives from the constraints and adding a portfoliospec object, here is a list of functions/features I am proposing to add to accomplish this.</div><div>
<br></div><div>
constraint_v2()</div><div><ul><li>Constraints object constructor as an S3 object that will hold the constraints. Similar to the current constraints_v1 object, but will keep separate from objectives.</li>
</ul><div>add.constraint()</div><div><ul><li>Helper function to add constraints to the constraint_v2 object such as box, group, etc. constraints.</li></ul><div>box_constraint()</div><div>
<ul><li>Function to be called by add.constraint that will set minimum and maximum weight for box constraints</li></ul><div>group_constraint()</div><div><ul><li>Function to be called by add.constraint that will set minimum and maximum group weights for group constraints</li>
</ul></div><div>objective_v2()</div></div></div></div><div><ul><li>Objective object constructor as an S3 object that will hold the objectives. Similar to the current constraints_v1 object, but will be separate from constraints.</li>
</ul></div>
<div>add.objective()</div><div><ul><li>Helper function to add objectives to the objective object.</li></ul><div>Note that there is currently an objective constructor of class=objclass and add.objective() function. These currently update the constraints_v1 object with the objectives. I should be able to re-use most of these and make revisions so that they update the objectives object.</div>
<div><br></div><div>portfoliospec()</div><div><ul><li>Portfolio specification constructor that holds the constraints and objectives. A constraint_v2 object and objective_v2 object will be passed in to create the portfoliospec object.</li>
</ul></div></div><div>may need additional helper functions for portfoliospec that do checks on the portfoliospec and/or the constraints and objectives objects that are passed in.</div><div><br></div><div>
optimize.portfolio() will have to be modified so that it takes in a portfoliospec object instead of a constraints object.</div><div><br></div><div>Thoughts?</div><div><br></div><div>Ross Bennett</div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 17, 2013 at 9:57 AM, Doug Martin <span dir="ltr"><<a href="mailto:martinrd@comcast.net" target="_blank">martinrd@comcast.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Brian and Ross,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I couldn’t agree more with the proposal to separate constraints and objectives (Brian, as you and I have discussed earlier this year or last year).<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I will have further comments on checking validity of adding constraints late tomorrow or early Wed. after I have completed grading of my spring quarter course.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Doug<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> <a href="mailto:gsoc-porta-bounces@lists.r-forge.r-project.org" target="_blank">gsoc-porta-bounces@lists.r-forge.r-project.org</a> [mailto:<a href="mailto:gsoc-porta-bounces@lists.r-forge.r-project.org" target="_blank">gsoc-porta-bounces@lists.r-forge.r-project.org</a>] <b>On Behalf Of </b>Ross Bennett<br>
<b>Sent:</b> Monday, June 17, 2013 7:09 AM<br><b>To:</b> PortfolioAnalytics<br><b>Cc:</b> <a href="mailto:gsoc-porta@r-forge.wu-wien.ac.at" target="_blank">gsoc-porta@r-forge.wu-wien.ac.at</a><br><b>Subject:</b> Re: [GSoC-PortA] structure of the specification objects<u></u><u></u></span></p>
<div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">Brian,<u></u><u></u></p><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">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.<u></u><u></u></p>
</div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">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.<u></u><u></u></p>
</div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">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?<u></u><u></u></p>
</div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">This is what I am thinking the code will look *something* like to run a simple optimization problem.<u></u><u></u></p></div><div><p class="MsoNormal">
<u></u> <u></u></p></div><div><p class="MsoNormal">#### Example R code<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal"># Specify a constraints object and add box constraints<u></u><u></u></p>
</div><div><p class="MsoNormal">gen.constr = constraint(assets, min_sum=1, max_sum=1)<u></u><u></u></p></div><div><p class="MsoNormal">gen.constr = add.constraint(gen.constr, min_weight=0.10, max_weight=0.4, type="box")<u></u><u></u></p>
</div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal"># Specify an objective object for global minimum variance<u></u><u></u></p></div><div><p class="MsoNormal">gen.obj = objective(type="GMV")<u></u><u></u></p>
</div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal"># Specify a portfolio object<u></u><u></u></p></div><div><p class="MsoNormal">port.spec = portfoliospec(gen.constr, gen.obj)<u></u><u></u></p>
</div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal"># Run the optimization<u></u><u></u></p></div><div><p class="MsoNormal">solution = optimize.portfolio(data, port.spec)<u></u><u></u></p></div>
<div><p class="MsoNormal">#####<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">Thanks,<u></u><u></u></p></div><div><p class="MsoNormal">Ross Bennett<u></u><u></u></p></div>
</div><div><p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p><div><p class="MsoNormal">On Mon, Jun 17, 2013 at 6:51 AM, Brian G. Peterson <<a href="mailto:brian@braverock.com" target="_blank">brian@braverock.com</a>> wrote:<u></u><u></u></p>
<p class="MsoNormal">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:<u></u><u></u></p>
<p class="MsoNormal">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=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=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@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@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@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@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-project.org</a><br> <mailto:<a href="mailto:gsoc-porta@lists.r-forge.r-project.org" target="_blank">gsoc-porta@lists.r-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____<u></u><u></u></p><p class="MsoNormal">
_______________________________________________<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-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-project.org/cgi-bin/mailman/listinfo/gsoc-porta</a><u></u><u></u></p>
</div><p class="MsoNormal"><u></u> <u></u></p></div></div></div></div></div><br>_______________________________________________<br>
GSoC-PortA mailing list<br>
<a href="mailto:GSoC-PortA@lists.r-forge.r-project.org">GSoC-PortA@lists.r-forge.r-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-project.org/cgi-bin/mailman/listinfo/gsoc-porta</a><br>
<br></blockquote></div><br></div>