0% found this document useful (0 votes)
114 views

HW 2

This document contains the homework assignment of a student named Yik Lun Kei. It involves calculating stock returns, means, variances, and covariances of 5 stocks. It then performs multiple portfolio optimizations to find the combinations of stocks that minimize risk for a given return or maximize return for a given risk. This includes calculating the efficient frontier and optimal portfolios. It also involves solving systems of equations to find optimal portfolio weights.

Uploaded by

api-285777244
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views

HW 2

This document contains the homework assignment of a student named Yik Lun Kei. It involves calculating stock returns, means, variances, and covariances of 5 stocks. It then performs multiple portfolio optimizations to find the combinations of stocks that minimize risk for a given return or maximize return for a given risk. This includes calculating the efficient frontier and optimal portfolios. It also involves solving systems of equations to find optimal portfolio weights.

Uploaded by

api-285777244
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

C183 Homework2

YIK LUN, KEI


704-115-065
2017/4/25

Exercise 1

(a)

a <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c183_c283/statc183c283_5stocks.txt",
header=T)
r1 <- (a$P1[-length(a$P1)]-a$P1[-1])/a$P1[-1]
r2 <- (a$P2[-length(a$P2)]-a$P2[-1])/a$P2[-1]
r3 <- (a$P3[-length(a$P3)]-a$P3[-1])/a$P3[-1]
r4 <- (a$P4[-length(a$P4)]-a$P4[-1])/a$P4[-1]
r5 <- (a$P5[-length(a$P5)]-a$P5[-1])/a$P5[-1]

(b)

returns <- as.data.frame(cbind(r1,r2,r3,r4,r5))


colMeans(returns)

## r1 r2 r3 r4 r5
## 0.0027625075 0.0035831363 0.0066229478 0.0004543727 0.0045679106
cov(returns)

## r1 r2 r3 r4 r5
## r1 0.005803160 0.001389264 0.001666854 0.000789581 0.001351044
## r2 0.001389264 0.009458804 0.003944643 0.002281200 0.002578939
## r3 0.001666854 0.003944643 0.016293581 0.002863584 0.001469964
## r4 0.000789581 0.002281200 0.002863584 0.009595202 0.003210827
## r5 0.001351044 0.002578939 0.001469964 0.003210827 0.009242440

(c)

x1_min <- (var(r5)-cov(r1,r5))/(var(r1)+var(r5)-2*cov(r1,r5))


x2_min <- 1-x1_min
rp_bar_min <- x1_min*mean(r1)+x2_min*mean(r5)
sd_min <- sqrt(x1_min^2*var(r1)+x2_min^2*var(r5)+2*x1_min*x2_min*cov(r1,r5))

x1_min

## [1] 0.6393153
x2_min

## [1] 0.3606847

1
rp_bar_min

## [1] 0.003413689
sd_min

## [1] 0.06478695

(d)

xa <- seq(0,1,0.01)
xb <- 1-xa
r1_bar <- mean(r1);r5_bar <- mean(r5)
var1 <- var(r1);var5 <- var(r5)
cov_15 <- cov(r1,r5)
rp_bar <- xa*mean(r1)+xb*mean(r5)
sd_p <- sqrt(xa^2*var(r1)+xb^2*var(r5)+2*xa*xb*cov(r1,r5))
aa <- as.data.frame(cbind(sd_p,rp_bar))
plot(sd_p,rp_bar, type="l", xlab=expression(sigma[p]),
ylab=expression(bar(R[p])), main="Portfolio possibilities curve of Exxon-Mobil and Boeing")
aa <- as.data.frame(cbind(sd_p,rp_bar))
points(aa[aa$rp_bar>rp_bar_min,], col="green", type="l")

Portfolio possibilities curve of ExxonMobil and Boeing


0.0045
0.0040
Rp

0.0035
0.0030

0.065 0.070 0.075 0.080 0.085 0.090 0.095

(e)

data <- read.table("http://www.stat.ucla.edu/~nchristo/datac183c283/statc183c283_abc.txt", header=T)


sigma_p <- (data$a^2*var(r1)+data$b^2*var(r4)+data$c^2*var(r5)+2*data$a*data$b*cov(r1,r4)+

2
2*data$a*data$c*cov(r1,r5)+2*data$b*data$c*cov(r4,r5))^.5
rp_bar <- data$a*mean(r1)+data$b*mean(r4)+data$c*mean(r5)
plot(sigma_p, rp_bar, xlab=expression(sigma[p]),ylab=expression(bar(R[p])),
main="Portfolio possibilities curve of Exxon-Mobil, McDonalds, and Boeing", cex=0.5)

Portfolio possibilities curve of ExxonMobil, McDonalds, and Boeing


0.015
0.010
Rp

0.005
0.000

0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40

(f)

a1 <- as.data.frame(cbind(r1,r4,r5))
R_ibar <- as.matrix(colMeans(a1))
R <- R_ibar-0.001
var_covar <- cov(a1)
var_covar_inv <- solve(var_covar)
z <- var_covar_inv %*% R
x <- z/sum(z)
x

## [,1]
## r1 0.5284782
## r4 -0.4955882
## r5 0.9671100
R_Gbar <- t(x) %*% R_ibar
var_G <- t(x) %*% var_covar %*% x
sd_G <- (t(x) %*% var_covar %*% x)^.5
R_Gbar

## [,1]
## [1,] 0.005652415

3
sd_G

## [,1]
## [1,] 0.1025256
slope <- (R_Gbar-0.001)/(sd_G)
r11 <- .001+slope*.25
plot(sigma_p, rp_bar, xlab=expression(sigma[p]),ylab=expression(bar(R[p])),
main="Portfolio possibilities curve of Exxon-Mobil, McDonalds, and Boeing", cex=0.5)
segments(0,.001, sd_G, R_Gbar)
segments(sd_G, R_Gbar, .25, r11)
points(sd_G, R_Gbar, cex=1, pch=19,col="red")
text(sd_G, R_Gbar+0.001, "G")

Portfolio possibilities curve of ExxonMobil, McDonalds, and Boeing


0.015
0.010

G
Rp

0.005
0.000

0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40

(g)

Rc_bar <- 0.60*R_Gbar + 0.40*0.001


sd_c <- 0.60*sd_G
Rc_bar

## [,1]
## [1,] 0.003791449
sd_c

## [,1]
## [1,] 0.06151535
plot(sigma_p, rp_bar, xlab=expression(sigma[p]),ylab=expression(bar(R[p])),
main="Portfolio possibilities curve of Exxon-Mobil, McDonalds, and Boeing", cex=0.5)

4
segments(0,.001, sd_G, R_Gbar)
segments(sd_G, R_Gbar, .25, r11)
points(sd_c, Rc_bar, cex=1, pch=19,col="red")
text(sd_c, Rc_bar+0.001, "C")

Portfolio possibilities curve of ExxonMobil, McDonalds, and Boeing


0.015
0.010
Rp

0.005

C
0.000

0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40

(h)

(1)

a1 <- as.data.frame(cbind(r1,r4,r5))
R_ibar <- as.matrix(colMeans(a1))
R2 <- R_ibar-0.002
var_covar <- cov(a1)
var_covar_inv <- solve(var_covar)
z2 <- var_covar_inv %*% R2
x2 <- z2/sum(z2)
x2

## [,1]
## r1 0.5312205
## r4 -1.8026632
## r5 2.2714427
R_Bbar <- t(x2) %*% R_ibar
var_B <- t(x2) %*% var_covar %*% x2
sd_B <- (t(x2) %*% var_covar %*% x2)^.5
R_Bbar

## [,1]

5
## [1,] 0.01102417
sd_B

## [,1]
## [1,] 0.2365542
slope2 <- (R_Bbar-0.002)/(sd_B)
r22 <- 0.002+slope2*0.25

R <- R_ibar-0.001
var_covar <- cov(a1)
var_covar_inv <- solve(var_covar)
z <- var_covar_inv %*% R
x <- z/sum(z)
R_Gbar <- t(x) %*% R_ibar
var_G <- t(x) %*% var_covar %*% x
sd_G <- (t(x) %*% var_covar %*% x)^.5
slope <- (R_Gbar-0.001)/(sd_G)
r11 <- .001+slope*.25

plot(sigma_p, rp_bar, xlab=expression(sigma[p]),ylab=expression(bar(R[p])),


main="Portfolio possibilities curve of Exxon-Mobil, McDonalds, and Boeing", cex=0.5)

segments(0,.001, sd_G, R_Gbar)


segments(sd_G, R_Gbar, .25, r11)

points(sd_G, R_Gbar, cex=1, pch=19,col="red")


text(sd_G, R_Gbar+0.001, "G")

segments(0,.002, sd_B, R_Bbar)


segments(sd_B, R_Bbar, .25, r22)

points(sd_B, R_Bbar, cex=1, pch=19,col="green")


text(sd_B, R_Bbar+0.001, "B")

6
Portfolio possibilities curve of ExxonMobil, McDonalds, and Boeing

0.015

B
0.010

G
Rp

0.005
0.000

0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40

(2)

cov_AB <- t(x) %*% var_covar %*% x2


cov_AB

## [,1]
## [1,] 0.02264823

(3)

xa <- runif(2000, -1.5,2.5)


xb <- 1-xa
sd_t <- (xa^2*var_G + xb^2*var_B + 2*xa*xb*cov_AB)^0.5
R_tbar <- xa*R_Gbar + xb*R_Bbar

plot(sigma_p, rp_bar, xlab=expression(sigma[p]),


ylab=expression(bar(R[p])),
main="Portfolio possibilities curve of Exxon-Mobil, McDonalds, and Boeing", cex=0.1)

points(sd_t, R_tbar, col="green", cex=0.5)

7
Portfolio possibilities curve of ExxonMobil, McDonalds, and Boeing

0.015
0.010
Rp

0.005
0.000

0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40

(4)

xA_min <- (var_B - cov_AB)/(var_B + var_G - 2*cov_AB)


xB_min <- 1-xA_min
#Composition in terms of Exxon-Mobil, McDonalds, and Boeing:
x_xom <- xA_min * x[1] + xB_min * x2[1]
x_mcd <- xA_min * x[2] + xB_min * x2[2]
x_boe <- xA_min * x[3] + xB_min * x2[3]
x_xom

## [,1]
## [1,] 0.5269063
x_mcd

## [,1]
## [1,] 0.2536533
x_boe

## [,1]
## [1,] 0.2194404
rbar_3 <- x_xom*mean(r1) + x_mcd*mean(r4) + x_boe*mean(r5)
sd_3 <- (x_xom^2*var(r1) + x_mcd^2*var(r4) + x_boe^2*var(r5)+2*x_xom*x_mcd*cov(r1,r4)+
2*x_xom*x_boe*cov(r1,r5) + 2*x_mcd*x_boe*cov(r4,r5))^0.5
rbar_3

## [,1]
## [1,] 0.00257322

8
sd_3

## [,1]
## [1,] 0.05961942

Exercise 2

(a)

0.12 0.04 = 0.04ZA + 0.0016ZB


RB 0.04 = 0.0016ZA + 0.0064ZB
ZA = ZB
0.08 = 0.0416ZA
ZA = 1.923077
RB = 0.04 + (0.0016 + 0.0064) 1.923077
RB = 0.05538462

(b)

0.12 0.04 = 0.04ZA + 0.0016ZB


RB 0.04 = 0.0016ZA + 0.0064ZB
ZB = 0
0.08 = 0.04ZA
ZA = 2
RB = 0.0016 2 + 0.04
RB = 0.0432

Exercise 3

(a)
1
4 (0.16) + 14 (0.25) + 2 12 12 AB = 0.0525
AB = 0.1

(b)

RC = (1 x)Rf + xRG = 0.11


(1 x)0.05 + x(0.6 0.14 + 0.4 0.1) = 0.11
x = 0.81
we need to invest 81% in portfolio G and 19% in the risk free asset.

9
(c)

(1 x)(0.05) + x(0.6 0.14 + 0.4 0.1) = 0.1


x = 0.676
xA = 0.676 0.6 = 0.41
xB = 0.676 0.4 = 0.27
1 x = 0.32
we need to invest 41% in stock A, 27% in stock B and 32% in the risk free asset.

Exercise 4

(a)
Pn
cov( i=1 xi Ri , Rm )
Pn
= cov( n1 i=1 (i + i Rm + i ), Rm )
Pn
= cov( + Rm + n1 i=1 i , Rm )
= cov(Rm , Rm )
2
= m

(b)
Pn
var( i=1 xi Ri )
n
= var( n1 i=1 Ri )
P

1
Pn
= n2 var( i=1 0 + i Rm + i )
1
Pn
= n2 var( i=1 i )
1
Pn Pn Pn
= n2 ( i=1 var(i ) + i=1 j6=i cov(i , j ))
1 2
= n2 (n + n(n 1)k 2 )
2 n1 2
= n + n k

p2 = k 2
as n gets large

(c)

Assume short sales allowed.


1 1
x= 10 1 1

10
(d)
Pn
cov(Rp , Ri ) = cov(p + p Rm + i=1 xi i , i + i Rm + i )
2
= i p m + xi 2i

Exercise 5

(a)

Qinverse <- matrix(c(166.21139,-22.40241,-22.40241,220.41076),byrow=T,nrow=2)


(Qinverse %*% c(1,1)) / as.numeric((t(c(1,1)) %*% Qinverse %*% c(1,1)))

## [,1]
## [1,] 0.4207188
## [2,] 0.5792812

(b)

0.01219724 = (1 x)Rf + xRA


0.01219724 = (1 x)0.011 + x(0.01315856)
x = 0.5546475
x1 = 0.5546475 0.4207 = 0.2333402
x2 = 0.5546475 0.5793 = 0.3213073
Therefore the composition of portfolio B will be 55.5% of portfolio A and 44.5% in risk-free asset. Or 44.5%
in Rf , 23.3% in stock 1 and 32.2% in stock 2.

(c)

A better strategy is to find the point of tangency and move up from point B until we reach the tangent. This
point will be a combination of the point of tangency G and the risk free asset Rf

Exercise 6

(a)

var(X) = E(X 2 ) (E(X))2 = 10 9 = 1


sd(X) = 1
var(Y ) = E(Y ) (E(Y ))2 = 29 4 = 25
2

sd(Y ) = 5
cov(X, Y ) = E(XY ) E(X)E(Y ) = 0 6 = 6
XY = cov(XY )/(var(X) var(Y )) = 6/(5 1) = 1.2
However, 1 1, therefore X and Y cannot have these properties.

11
(b)

AB
AB = A B
A B
qm
2
= q
A
2 2 + 2
m A B2 2 + 2
m B

0.791.120.0022
=
0.792 0.0022+0.0027 1.122 0.0022+0.006
AB = 0.12

(c)
B
B t/2,n2 Pm 2
t=1 (Rmt Rm )

1.12 0.43
0.69 B 1.55

(d)
2
Pm
SST = SSR + SSE = A t=1 (Rmt Rm ) + (m 2)2A
SST = 0.0792 (0.13) + 58 (0.0027)
R2 = SSR/SST
R2 = 0.049

Exercise 7

(a)
P3
p = i=1 xi i = 0.3(1.08) + 0.5(0.8) + 0.2(1.22) = 0.968
P3
p = i=1 xi i = 0.3(0.01) + 0.5(0.04) + 0.2(0.08) = 0.039

(b)

Rp = p + p Rm = 0.039 + 0.968 0.1 = 0.1358


P3
p2 = p2 m
2
+ i=1 x2i 2i
p2 = 0.9682 0.002 + 0.3(0.003) + 0.5(0.006) + 0.2(0.001) = 0.003684048
p = 0.06069636
RC = (1 x)Rf + xRp = 0.6(0.002) + 1.6(0.1358) = 0.21608
C = xp = 1.6(0.06069636) = 0.097

12
data <- read.table("http://www.stat.ucla.edu/~nchristo/datac183c283/statc183c283_abc.txt", header=T)
sigma_p <- (data$a^2*(1.08^2*0.002+0.003)+data$b^2*(0.8^2*0.002+0.006)+data$c^2*(1.22*0.002+0.001)+
2*data$a*data$b*(1.08*0.8*0.002)+2*data$a*data$c*(1.08*1.22*0.002)+
2*data$b*data$c*(0.8*1.22*0.002))^.5
rp_bar <- data$a*(0.01+1.08*0.1)+data$b*(0.04+0.8*0.1)+data$c*(0.08+1.22*0.1)
plot(sigma_p, rp_bar, xlab=expression(sigma[p]),ylab=expression(bar(R[p])),cex=0.5)
points(0.097, 0.21608, col="red", cex=2, pch=19)
0.5
0.4
0.3
Rp

0.2
0.1
0.0

0.05 0.10 0.15 0.20

(c)
2
cov(Rp , Rm ) = p m = 0.968(0.002) = 0.001936

(d)

RC = 0.4(0.002) + 0.6(0.1358) = 0.08228


C = 0.6(0.060696) = 0.03642

(e)
2
cov(R1 , Rm ) = cov(1 + 1 Rm + 1 , Rm ) = 1 m = 1.08(0.002) = 0.00216

13

You might also like