[S] Min variance portfolio

Deric Hetzel (DHetzel@sprintmail.com)
Thu, 2 Jul 1998 08:28:00 -0700


Due to my inexperience, I have been struggling to write a function that
allows me to create min variance portfolios subject to the following
constraints:
no short sales (0<=weights<=1)
setting a limited number of stocks in the portfolio.
any ideas?
My function for min variance w/o the above constrains is:

minvarport<-function(r)
{
# r is the returns matrix of stock returns
# ita is a row vector of 1s equal in length to the number of stocks
# calculate the variables
ita_matrix(1,length(r[1,]),1)
muStocks_apply(r,2,mean)
muStocks_matrix(muStocks,length(r[1,]),1)
VCr_var(r)
# calculate the function (see Campbell, Lo & Mackinley p. 185)
A_t(ita)%*%solve(VCr)%*%muStocks
B_t(muStocks)%*%solve(VCr)%*%muStocks
C_t(ita)%*%solve(VCr)%*%ita
# need to define scalers as vectors insead of matrices
A_as.vector(A)
B_as.vector(B)
C_as.vector(C)
D_B*C-A^2
# solve for weights, portfolio return, var of portfolio
weights_(1/C)*solve(VCr)%*%ita
muPort_A/C
varPort_1/C
# define output

list(weights=weights,muPort=muPort,varPort=varPort)
}

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news