[R] adding overall constraint in optim()
John C. Nash
pro|jcn@@h @end|ng |rom gm@||@com
Thu May 3 22:49:16 CEST 2018
This looks like what I call a sumscale problem i.e., some sort of simple
function of the parameters sums to a constant. I've done some work on
these, but don't have it with me just now. There are several approaches,
but they can be quite tricky. Will send some info in about a week or so
if you are still stuck and contact me offline.
(you'll see my name on 3/5 of optim routines via ?optim)
On 2018-05-03 01:52 PM, Michael Ashton wrote:
> Hi –
> This is giving me a headache. I’m trying to do a relatively simple optimization – actually trying to approximate the output from the Excel Solver function but at roughly 1000x the speed. 😊
> The optimization parameters look like this. The only trouble is that I want to add a constraint that sum(wgt.vect)=1, and I can’t figure out how to do that in optim.
> Mo.vect <- as.vector(tail(head(mo,i),1))
> wgt.vect <- as.vector(tail(head(moWeightsMax,i),1))
> cov.mat <- cov(tail(head(morets,i+12),12))
> opt.fun <- function(wgt.vect) -sum(Mo.vect %*% wgt.vect) / (t(wgt.vect) %*% (cov.mat %*% wgt.vect))
> OptimSolution<-optim(wgt.vect, fn=opt.fun, method="L-BFGS-B",lower=LowerBounds,upper=UpperBounds)
> Any thoughts are appreciated!
> Michael Ashton, CFA
> Managing Principal
> Enduring Investments LLC
> W: 973.457.4602
> C: 551.655.8006
> [[alternative HTML version deleted]]
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help