[R] adding overall constraint in optim()
jo@h@m@u|r|ch @end|ng |rom gm@||@com
Fri May 4 04:18:54 CEST 2018
On Thu, May 3, 2018 at 2:03 PM, Michael Ashton
<m.ashton using enduringinvestments.com> 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 these statements. Most of the "finance tools"
use general-purpose global and/or stochastic optimization packages
(e.g. rugarch uses nloptr and Rsolnp, PortfolioAnalytics uses DEoptim,
pso, GenSA). And most (all?) of those optimization packages have ways
to specify box, equality, and nonlinear inequality constraints.
And I can't recall the last time someone emailed the list about
optimizing a traditional Markowitz mean-variance problem... maybe 10
>> On May 3, 2018, at 3:01 PM, Bert Gunter <bgunter.4567 using gmail.com> wrote:
>> 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 might be a
>> better place for you to post your query.
>> Bert Gunter
>> "The trouble with having an open mind is that people keep coming along
>> and sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>> On Thu, May 3, 2018 at 10:52 AM, Michael Ashton
>> <m.ashton using 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))
>>> 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.
> 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.
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
R/Finance 2018 | www.rinfinance.com
More information about the R-help