Skip to content
Back to formatted view

Raw Message

Message-ID: <c2776ddd83aa452d9cbee0dff710da0a@MBX084-W1-CA-3.exch084.serverpod.net>
Date: 2018-05-03T17:52:27Z
From: Michael Ashton
Subject: adding overall constraint in optim()

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!

Mike

Michael Ashton, CFA
Managing Principal

Enduring Investments LLC
W: 973.457.4602
C: 551.655.8006


	[[alternative HTML version deleted]]