[R-SIG-Finance] Constrained Regression with Intercept in pcls

Enrico Schumann enricoschumann at yahoo.de
Thu Dec 1 22:24:52 CET 2011


Hi Philipp,

you should be able to solve this with package quadprog/solve.QP.

require(quadprog)

p <- 3    ## number of regressors
T <- 100  ## number of obs
X <- array(rnorm(T*p), dim = c(T,p))
X <- cbind(1,X)  ## add a constant
y <- rnorm(T)


## variant 1 -- linear regression
coef(lm(y ~ -1 + X))


## variant 2 -- quadprog (should be the same as variant 1)
Dmat <- crossprod(X)
dvec <- as.vector(t(as.matrix(y)) %*% X)
Amat <- as.matrix(rep(0, p+1))
solve.QP(Dmat = Dmat, dvec = dvec, Amat = Amat)$solution


## variant 3 -- quadprog, now with restrictions
bvec <- c(1, rep(0, p))
Amat <- rbind(1,diag(p))
Amat <- cbind(0, Amat)
w <- solve.QP(Dmat = Dmat, dvec = dvec, Amat = t(Amat), bvec=bvec, 
meq=1)$solution
w          ## result
sum(w[-1]) ## check constraint

see also here http://comisef.wikidot.com/tutorial:minimisevariance

regards,
Enrico




Am 01.12.2011 17:18, schrieb Philipp:
> Dear all,
>
> I already asked about to run a constrained regression like y=b0 +
> b1X1+b2x2+b3x3, with constraints:
>
> b1+b2+b3=1 and b1,b2,b3>=0. I thought it will run with style.QPfit with the
> performance Analytic packages.
>
> However the style.QPfit function does not estimate an intercept. As i really
> can not extend this function for my problem, I noticed pcls. Pcls is maybe
> an alternative for my problem. Can somebody help me to implement the
> constraints in pcls. Maybe it can be done by designing a designed matrix X
> with extra column for the inercept (b0) and to force C in a way. But how I
> do not know.
>
> Your help is greatly appreciated
>
> Philipp
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Constrained-Regression-with-Intercept-in-pcls-tp4129187p4129187.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
>
> _______________________________________________
> 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.
>

-- 
Enrico Schumann
Lucerne, Switzerland
http://nmof.net/



More information about the R-SIG-Finance mailing list