[R-SIG-Finance] correction

Dominykas Grigonis dominykasgrigonis at gmail.com
Mon Aug 17 20:12:14 CEST 2015


One (very crude) approach would be to take DE or SA optimisers and introduce constraints like (a + b - 2)^1000 in your target SSE function

> On 17 Aug 2015, at 18:25, Mark Leeds <markleeds2 at gmail.com> wrote:
> 
> Hi Eric: A friend of mine pointed out that my answer to your question about
> constraining the regression is incorrect because the way I recommended
> bounding the parameters won't guarantee feasibility.
> 
> Below is a small example that implements what I described but note that the
> sum constraint won't necessarily hold if the other 2 parameters end up both
> being greater than 0.5. ( it does in this example I created but that's just
> fortunate ). So don't use my approach.
> 
> There are probably optimizers out there that handle sum constraints. One
> that does but I have little experience with it is Ravi Varadhan's BB
> package. Also, check out John Nash's book
> if you have it because that gives nice coverage of a lot ( if not all ) of
> all of the optimization packages available in R.
> 
> Or as you noted, there is probably an R package that estimates that type of
> regression directly. Good luck and sorry for noise.
> 
> #====================================================================
> 
> set.seed(123)
> x1 <- rnorm(1000)
> x2 <- rnorm(1000)
> x3 <- rnorm(1000)
> y <- rnorm(1000, 2 + .5 * x1 + .3 * x2 + .2 * x3)
> 
> residsfunc <- function(par, x1,x2,x3,y) {
>  Xmod <- cbind(par[1], par[2]*x1, par[3]*x2, (1-par[2]-par[3])*x3)
>  sum((y - Xmod)^2)
> }
> 
> mypar <- c(mean(y),0.9,0.9)
> 
> result <- optim(par = mypar, fn=residsfunc, method = "L-BFGS-B", lower =
> c(0,0,0), upper = c(Inf,1,1),
>      x1 = x1, x2 = x2, x3 = x3, y = y)
> 
> lastpar <- 1-result$par[2]-result$par[3]
> print(c(result$par,lastpar))
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.



More information about the R-SIG-Finance mailing list