> On May 3, 2018, at 10:52 AM, Michael Ashton 
> <m.ash...@enduringinvestments.com> 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))
> 
>     LowerBounds<-c(0.2,0.05,0.1,0,0,0)
>     UpperBounds<-c(0.6,0.3,0.6,0.15,0.1,0.2)
> 
>     OptimSolution<-optim(wgt.vect, fn=opt.fun, 
> method="L-BFGS-B",lower=LowerBounds,upper=UpperBounds)
> 
> 
> Any thoughts are appreciated!

Have you reviewed the documentation for constrOptim {in pkg-stats}?

> 
> 
>       [[alternative HTML version deleted]]

I was surprised that emoji made it through. Nonetheless it is usually much 
safer to posting in plain-text. Didn't seem to be a problem in this case but 
code and data are often mangled.


David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to