Portfolio Theory with Matrix Algebra andNo Short Sales
CFRM 462/Econ 424
Eric Zivot
Summer 2014
Updated: August 12, 2014

© Eric Zivot 2006

3 Asset Example Data
> asset.names <- c("MSFT", "NORD", "SBUX")> mu.vec = c(0.0427, 0.0015, 0.0285)> names(mu.vec)() = asset.namest> sigma.mat = matrix(c(0.0100, 0.0018, 0.0011,+0.0018, 0.0109, 0.0026,+0.0011,, 0.0026,, 0.0199),),+nrow=3, ncol=3)> dimnames(sigma.mat) = list(asset.names, asset.names)> mu.vec
MSFTNORD
SBUX
0.0427 0.0015 0.0285> sigma.mat
MSFTNORDSBUXMSFT 0.0100 0.0018 0.0011
NORD 0.0018 0.0109 0.0026
SBUX 00.00110011 00.00260026 00.01990199© Eric Zivot 2006

Risk-Return Characteristics
Expected Return© Eric Zivot 2006

Standard deviation

Global Minimum Variance Portfolio with No Short Sales# unconstrained solution> gmin.port = globalMin.portfolio(mu.vec,(sigma.mat))> gmin.port
Call:globalMin.portfolio(ergp(= mu.vec,, cov.mat = sigma.mat)g)
Portfolio expected return:Portfolio standard deviation:
P tf li weights:
Portfolioi ht
MSFTNORD
SBUX
0.4411 0.3656 0.1933

0.024890.07268

No short sales constraint is notbinding: unconstrained weights
are all positive !

© Eric Zivot 2006

Global Minimum Variance Portfolio with No Short Sales# set restriction matrices> D.mat = 2*sigma.mat> d.vec = rep(0, 3)> A.mat = cbind(rep(1,3), diag(3))> bb.vec
vec = c(1,c(1 rep(0rep(0,3))
3))> D.mat
MSFTNORDSBUXMSFT 0.0200 0.0036 0.0022
NORD 0.0036 0.0218 0.0052
SBUX 0.0022 0.0052 0.0398> d.vec[1] 0 0 0> A.mat[ 1] [,2][,1][ 2] [,3][ 3] [,4]
[ 4]
[1,]
1
100[2,]
10
10[3,][,]
1001> b.vec[1] 1 0 0 0© Eric Zivot 2006

Global Minimum Variance Portfolio with No Short Sales# use solve.QP
solve QP to minimize portfolio variance> args(solve.QP)
function (Dmat, dvec, Amat, bvec, meq = 0, factorized =FALSE)> qp.out = solve.QP(Dmat=D.mat, dvec=d.vec,+
Amat=A.mat, bvec=b.vec, meq=1)> class(qp.out)[1][] "list"N b off
Numberequality> names(qp.out)
constraints[1] "solution""value"[3] ""unconstrained.solution"t i dl ti " "it"iterations"ti"[5] "Lagrangian""iact"
qp> qp.out$solution[1] 0.4411 0.3656 0.1933# portfolio weights> sum(qp.out$solution)[1] 1> qp.out$value[1] 0.005282# portfolio variance© Eric Zivot 2006

Global Minimum Variance Portfolio with No Short Sales# compute mean, variance and sd> w.gmin.ns = qp.out$solution> names(w.gmin.ns) = names(mu.vec)> w.gmin.nsiMSFTNORD
SBUX
0.4411 0.3656 0.1933> er.gmin.ns = as.numeric(crossprod(w.gmin.ns, mu.vec))> er.gmin.ns[1] 0.02489> var.gmin.ns = as.numeric(t(w.gmin.ns)%*%sigma.mat%*%w.gmin.ns)> var.gmin.ns[1] 0.005282> sqrt(var.gmin.ns)[1] 0.07268© Eric Zivot 2006

Global Minimum Variance Portfolio with No Short Sales# constrained solution using shorts=FALSE# function uses solve.QP()()> gmin.port = globalMin.portfolio(mu.vec, sigma.mat,shorts=FALSE)
gp> gmin.port
Call:globalMin.portfolio(er = mu.vec, cov.mat = sigma.mat)
PortfolioP
tf li expectedt d return:tPortfolio standard deviation:
Portfolio weights:
MSFT
NORD
SBUX
0.4411 0.3656 0.1933

00.02489
02489
0.07268© Eric Zivot 2006

Force no-short sales
constraint on all assets

Compute Efficient Frontier Allowing Short Sales# compute and plot efficient frontier with short-sales> ef <- efficient.frontier(mu.vec, sigma.mat, alpha.min=0,+alpha.max=1, nport=10)> ef$weights
MSFTNORD
SBUX
Some efficient portfolios
port 1 0.8275 -0.09075 0.2633
have short sales
port 2 0.7845 -0.04004
0.04004 0.2555
port 3 0.7416 0.01067 0.2477
port 4 0.6987 0.06138 0.2399
port 5 0.6557 0.11209 0.2322
port 6 00.6128
6128 00.16279
16279 00.2244
2244port 7 0.5699 0.21350 0.2166
port 8 0.5270 0.26421 0.2088
port 9 0.4840 0.31492 0.2010
p
port 10 0.4411 0.36563 0.1933© Eric Zivot 2006

Efficient Frontier with Allowing Short Sales
These portfolios havenegative weights in NORD

© Eric Zivot 2006

Compute Efficient Frontier without Short Sales# compute efficient frontier with no-short sales> mu.vals = seq(er.gmin.ns, max(mu.vec), length.out=10)> ww.matmat = matrix(0,matrix(0 length(mulength(mu.vals),vals) 3)> sd.vec = rep(0, length(sd.vec))> colnames(w.mat) = names(mu.vec)> D.mat = 2*sigma.mat> d.vec = rep(0, 3)> A.mat = cbind(mu.vec, rep(1,3), diag(3))> for (i in 1:length(mu.vals)) {+b.vec = c(mu.vals[i],1,rep(0,3))+
qp.out = solve.QP(Dmat=D.mat, dvec=d.vec,+
Amat=A.mat, bvec=b.vec, meq=2)+
w.mat[i, ] = qp.out$solution+
sd.vec[i]d[i] = sqrt(qp.out$value)t(t$ l )+ }2 equality
constraints!

© Eric Zivot 2006

Compute Efficient Frontier without Short Sales> w.mat
MSFTNORD
SBUX[1,] 0.4411Frontier
3.656e-01
1.933e-01
allowing
short sales (blue)[2,] 0.4840 3.149e-01 2.010e-01[3,] 0.5270 2.642e-01 2.088e-01[4 ] 0[4,]
0.56995699 22.135e
135e-01
01 2.166e2 166e-0101[5,] 0.6128 1.628e-01 2.244e-01[6,] 0.6557 1.121e-01 2.322e-01[7,] 0.6987 6.138e-02 2.399e-01
Frontier not allowing short sales (red)[8,] 0.7416 1.067e-02 2.477e-01[9,] 0.8607 3.532e-17 1.393e-01[10,] 1.0000 9.257e-17 2.220e-16© Eric Zivot 2006

Compute Efficient Frontier Not Allowing Short Sales# compute and plot efficient frontier without short-sales> ef.ns <- efficient.frontier(mu.vec, sigma.mat,+alpha.min=0, alpha.max=1,+
nport=10, shorts=FALSE)> ef.ns$weights
All efficient portfolios have
MSFT
NORD
SBUX
positive weights
pg
port 1 1.0000 0.00000 0.0000
port 2 0.8607 0.00000 0.1393
port 3 0.7416 0.01067 0.2477
port 4 0.6987 0.06138 0.2399
port 5 00.6557
6557 00.11209
11209 00.2322
2322
port 6 0.6128 0.16279 0.2244
port 7 0.5699 0.21350 0.2166
port 8 0.5270 0.26421 0.2088
p
port 9 0.4840 0.31492 0.2010
port 10 0.4411 0.36563 0.1933© Eric Zivot 2006

Example: Infeasible Frontier Portfolio# illustrate infeasible portfolio# set target return equal to 0.08
> b.vec = c(0.08,1,rep(0,3))(, , p( , ))> qp.out = solve.QP(Dmat=D.mat, dvec=d.vec,+Amat=A.mat, bvec=b.vec, meq=2)
Error in solve.QP(Dmat = D.mat, dvec = d.vec, Amat =A mat bvec = b.vec,A.mat,b vec:
constraints are inconsistent, no solution!

© Eric Zivot 2006