[GSoC-PortA] Quick question on multipliers and constrained_objective()
Brian G. Peterson
brian at braverock.com
Sat Jun 22 05:09:58 CEST 2013
On 06/21/2013 08:31 PM, Ross Bennett wrote:
> Hi All,
>
> I have a quick question on how the multiplier is used inside of the
> constrained_objective() function.
>
> The code below is from lines 230-248 in constrained_objective.R for
> objects of class return_objective and portfolio_risk_objective.
>
> # now set the new value of the objective output
> if(inherits(objective,"return_objective")){
> if (!is.null(objective$target) &
> is.numeric(objective$target)){ # we have a target
> out = out +
> penalty*abs(objective$multiplier)*abs(tmp_measure-objective$target)
> }
> # target is null or doesn't exist, just maximize, or
> minimize violation of constraint
> out = out + abs(objective$multiplier)*tmp_measure
> } # end handling for return objectives
>
> if(inherits(objective,"portfolio_risk_objective")){
> if (!is.null(objective$target) &
> is.numeric(objective$target)){ # we have a target
> out = out +
> penalty*abs(objective$multiplier)*abs(tmp_measure-objective$target)
> #should we also penalize risk too low for risk targets?
> or is a range another objective?
> # # half penalty for risk lower than target
> # if( prw < (.9*Riskupper) ){ out = out +
> .5*(penalty*( prw - Riskupper)) }
> }
> # target is null or doesn't exist, just maximize, or
> minimize violation of constraint
> out = out + abs(objective$multiplier)*tmp_measure
> } # univariate risk objectives
>
> When specifying objectives, if we want to maximize return, we would set
> multiplier=-1 and if we wanted to minimize risk we would set
> multiplier=1 in the objective object.
>
> Because the code below takes the absolute value of the multiplier
> (abs(objective$multiplier)), doesn't this make the multiplier have no
> effect?
>
> Any thoughts or insight is much appreciated.
I think your analysis of the code seems correct.
Returns are positive numbers, risk, generally negative numbers.
From the svn logs, the abs was added in revision 2327 by Peter with a
commit log:
- added abs to multiplier when using targets to keep searches
directionally correct
the diff between that revision and the previous revision is here:
https://r-forge.r-project.org/scm/viewvc.php/pkg/PortfolioAnalytics/R/constrained_objective.R?root=returnanalytics&r1=2326&r2=2327
From the comment, it would seem that Peter figured that he needed abs()
when there was a target, and multiplier is just a scalar.
That doesn't explain why it would be applied in all cases.
Maybe Peter remembers why?
I'll update my development environment to current code in the morning
and see if I can't run some of the code from the seminar script:
/pkg/PortfolioAnalytics/sandbox/script.workshop2012.R
usually, when I'm trying to understand what's going on in some of this
code, I use simple objectives (maximize return, minimize risk, etc), a
small portfolio of only a few assets, and random portfolios so that I
can see the entire space and figure out if things are being done correctly.
I'll try to construct some sort of contrived example tomorrow.
Regards,
- Brian
--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock
More information about the GSoC-PortA
mailing list