Re: [R] adding overall constraint in optim()

2018-05-06 Thread Eric Berger
typo: lambda * (sum(wgt.wect) - 1) On Sun, May 6, 2018 at 10:51 AM, Eric Berger wrote: > Hi Michael, > A few comments > 1. To add the constraint sum(wgt.vect=1) you would use the method of > Lagrange multipliers. > What this means is that in addition to the w_i (the components of the > weig

Re: [R] adding overall constraint in optim()

2018-05-06 Thread Eric Berger
Hi Michael, A few comments 1. To add the constraint sum(wgt.vect=1) you would use the method of Lagrange multipliers. What this means is that in addition to the w_i (the components of the weight variables) you would add an additional variable, call it lambda. Then you would modify your opti

Re: [R] adding overall constraint in optim()

2018-05-05 Thread Ravi Varadhan
Here is what you do for your problem: require(BB) 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.

[R] adding overall constraint in optim()

2018-05-05 Thread Ravi Varadhan
Hi, You can use the projectLinear argument in BB::spg to optimize with linear equality/inequality constraints. Here is how you implement the constraint that all parameters sum to 1. require(BB) spg(par=p0, fn=myFn, project="projectLinear", projectArgs=list(A=matrix(1, 1, length(p0)), b=1,

Re: [R] adding overall constraint in optim()

2018-05-03 Thread Joshua Ulrich
On Thu, May 3, 2018 at 2:03 PM, Michael Ashton wrote: > Thanks Bert. But everyone on that forum wants to use finance tools rather > than general optimization stuff! And I am not optimizing a traditional > Markowitz mean-variance problem. Plus, smarter people here. :-) > I'm very confused by thes

Re: [R] adding overall constraint in optim()

2018-05-03 Thread John C. Nash
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

Re: [R] adding overall constraint in optim()

2018-05-03 Thread David Winsemius
> On May 3, 2018, at 10:52 AM, 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 parameter

Re: [R] adding overall constraint in optim()

2018-05-03 Thread Michael Ashton
Thanks Bert. But everyone on that forum wants to use finance tools rather than general optimization stuff! And I am not optimizing a traditional Markowitz mean-variance problem. Plus, smarter people here. :-) > On May 3, 2018, at 3:01 PM, Bert Gunter wrote: > > You can't -- at least as I read

Re: [R] adding overall constraint in optim()

2018-05-03 Thread Bert Gunter
You can't -- at least as I read the docs for ?optim (but I'm pretty ignorant about this, so maybe there's a way to tweak it so you can). See here: https://cran.r-project.org/web/views/Optimization.html for other R optimization capabilities. Also, given your credentials, the r-sig-finance list

[R] adding overall constraint in optim()

2018-05-03 Thread Michael Ashton
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