9.tangent_example

9.tangent_example - University of California Los Angeles Department of Statistics Statistics C183/C283 Instructor Nicolas Christou Point of

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: University of California, Los Angeles Department of Statistics Statistics C183/C283 Instructor: Nicolas Christou Point of tangency - example We will use an example with 5 stocks. The data can be accessed at a <- read.table("http://www.stat.ucla.edu/~nchristo/statistics_c183_c283/ returns_5stocks.txt", header=TRUE) Compute the mean returns and the variance-covariance matrix Σ: > R_ibar <- as.matrix(mean(a)) > R_ibar [,1] R1 0.006362437 R2 0.002201256 R3 0.011741093 R4 0.010026242 R5 0.013801266 #Compute the variance-covariance matrix: > var_covar <- cov(a) > var_covar R1 R2 R3 R4 R1 0.010231184 0.004570583 0.004178472 0.0012245825 R2 0.004570583 0.012351573 0.002601227 0.0011180271 R3 0.004178472 0.002601227 0.012070071 0.0014954732 R4 0.001224582 0.001118027 0.001495473 0.0142320539 R5 0.004369937 0.002211725 0.005854583 0.0005037049 R5 0.0043699375 0.0022117252 0.0058545832 0.0005037049 0.0145066003 Compute the inverse of the variance-covariance matrix Σ−1 : > var_covar_inv <- solve(var_covar) > var_covar_inv R1 R2 R3 R1 137.702357 -40.5528945 -26.449937 R2 -40.552894 97.6584652 -6.636531 R3 -26.449937 -6.6365311 111.785787 R4 -5.018123 -3.4895385 -7.679539 R5 -24.449410 0.1262702 -35.868378 R4 R5 -5.018123 -24.4494104 -3.489538 0.1262702 -7.679539 -35.8683780 71.682853 2.6539836 2.653984 90.6636067 Create the vector R (assume Rf = 0.002): > Rf <- 0.002 > R <- R_ibar-Rf >R [,1] R1 0.0043624371 R2 0.0002012564 R3 0.0097410929 R4 0.0080262421 R5 0.0118012661 1 Compute the vector Z = Σ−1 R: > z <- var_covar_inv %*% R >z [,1] R1 0.006094381 R2 -0.248419860 R3 0.487263793 R4 0.509263661 R5 0.635216055 Compute the vector X : > x <- z/sum(z) >x [,1] R1 0.004386283 R2 -0.178794182 R3 0.350696322 R4 0.366530195 R5 0.457181382 Compute the expected return of portfolio G: > R_Gbar <- t(x) %*% R_ibar > R_Gbar [,1] [1,] 0.01373650 Compute the variance and standard deviation of portfolio G: > var_G <- t(x) %*% var_covar %*% x > var_G [,1] [1,] 0.008447059 > sd_G <- var_G^0.5 > sd_G [,1] [1,] 0.09190788 Compute the slope of the tangent line to the efficient frontier: > slope <- (R_Gbar-Rf)/(sd_G) > slope [,1] [1,] 0.1276985 We can now draw the line because we have two points (0, 0.002) and (sd G, R Gbar). Let’s find one more point (borrowing segment): (1.3*sd_G, 0.002+slope*(1.3*sd_G)) 2 Before we draw the tangent, let’s create many portfolios using different combinations of the five stocks: return_p <- rep(0,10000000); sd_p <- rep(0,10000000); j <- 0 i <- 0 for (a in seq(-.2, 1, 0.1)) { for (b in seq(-.2, 1, 0.1)) { for(c in seq(-.2, 1, 0.1)){ for(d in seq(-.2, 1, 0.1)){ for(e in seq(-.2, 1, 0.1)){ if(a+b+c+d+e==1) { j=j+1 return_p[j]=a*mean(data[,1])+b*mean(data[,2])+ c*mean(data[,3])+d*mean(data[,4])+e*mean(data[,5]) sd_p[j]=(a^2*var(data[,1]) + b^2*var(data[,2])+ c^2*var(data[,3])+ d^2*var(data[,4])+ e^2*var(data[,5])+ 2*a*b*cov(data[,1],data[,2])+ 2*a*c*cov(data[,1],data[,3])+ 2*a*d*cov(data[,1],data[,4])+ 2*a*e*cov(data[,1],data[,5])+ 2*b*c*cov(data[,2],data[,3])+ 2*b*d*cov(data[,2],data[,4])+ 2*b*e*cov(data[,2],data[,5])+ 2*c*d*cov(data[,3],data[,4])+ 2*c*e*cov(data[,3],data[,5])+ 2*d*e*cov(data[,4],data[,5]))^.5 } } } } } } R_p <- return_p[1:j] sigma_p <- sd_p[1:j] 3 We can get the same results if we use vectors and matrices as follows: j <- 0 return_p <- rep(50000) sd_p <- rep(0,50000) vect_0 <- rep(0, 50000) fractions <- matrix(vect_0, 10000,5) for (a in seq(-.2, 1, 0.1)) { for (b in seq(-.2, 1, 0.1)) { for(c in seq(-.2, 1, 0.1)){ for(d in seq(-.2, 1, 0.1)){ for(e in seq(-.2, 1, 0.1)){ if(a+b+c+d+e==1) { j=j+1 fractions[j,] <- c(a,b,c,d,e) sd_p[j] <- (t(fractions[j,]) %*% var_covar %*% fractions[j,])^.5 return_p[j] <- fractions[j,] %*% R_ibar } } } } } } R_p <- return_p[1:j] sigma_p <- sd_p[1:j] On the expected return standard deviation space we can plot all these portfolios, place the five stocks, and draw the tangent line: plot(sigma_p, R_p,xlab="Risk (standard deviation)", ylab="Expected return", xlim=c(0.0,.12), ylim=c(0.0,.016),axes=FALSE, cex=0.4) axis(1, at=c(0, 0.02, 0.04, 0.06, 0.08, 0.10, 0.12)) axis(2,at=c(0,0.002, 0.004, 0.006, 0.008, 0.010, 0.012, 0.014, 0.016)) lines(c(0,sd_G, 1.3*sd_G),c(.002,R_Gbar,0.002+slope*(1.3*sd_G))) #Identify portfolio G: points(sd_G, R_Gbar, cex=2, col="blue", pch=19) text(sd_G, R_Gbar+.0005, "G") #Plot the 5 stocks: points(sd(data), mean(data), pch=19, cex=2.3, col="green") 4 0.000 0.002 0.004 0.006 0.008 0.010 0.012 0.014 0.016 Expected return The plot: q q qq qqq q q q q q q q q q qq q q q q q q q qq q q q q qq q q q q qq q q q q qq q qq q q qq q q q qqq q q qq qq qq q q q q qq q q q q q q q q q q qqq q qq q q q q qq q q q q q q qq q qq q q qq q qq q q q qq q q q q q qq q qq q qq qqq q qq q q qq q q q qq q q qqq q qq q q q q qq q q q q q q qq q qq q q q qq qq qq qq q q q qqq qq q q q q q q q q qq qq q q q q q q q qq q q qq q q q q q qq q q q q q qq q qq q q q qq q q qqq q q q qq q qq q q q qq q q q qq q q q q q qq q q qq q q qq q qq q qqq q q qq q qq q qq q q q q q q q qq qq qq qq qq q q q q qq q qq q qqq q q q q q qq q q q qq q q q qq q q q qq q q q q q q qqq q q q q q q qq q q q q q q q qq q q q q qq qq q q qq q q qq qq q q q q q q q q q qq q qq q q q qq q q q q q qqq q q q q qq q q q q q qq qq q q q qqq q q qq q q q q qq q q q q qq qq q q q q q qq q qq q q q q q qq q q qq q q q qq qq q qq q q qq qqq q q qq q q q qq q q q qq q q q q qq qq q q q qq q q qq q qq q qq q qq q q q qq q q qq qq q q q q q qq qq q q qqqq q q qq q q q q q q q q q q q q q q qq qq q q q qq q q q q q qq qq q q qq q qqq q qq qq q q q qq q q qq qq qq qq qq q q q q qq qq q q qq qq q q q qq q q q q q qq qqq qq q q qqq q qq qqq q q qq qq qq q q q q q qq qq q qq q q qq q q q q q q q q q q q qq q q qqq q q q q q q qq q qq q qq qq q q q qq q q qq q q qq q q qq q q q q q q q q qq q q qq q q q qq q q q qq qq qq q q q q qq qq q q qq q q q qq q qq qq qq q q q q q q q q q q qq qq q qq q qq q q qqq qq q q qq q q q q q qq q q qq q q qq qq qq q q q q q q qq qq q q q qq q q q q q q q qq q qqq q q qq q q q q qq q qq qq q q q q q qq q qq q q q qq q q qq q q q q q q q q qq q q q qq qq q q q qq q q q q q qq q q q qq q q q q q q qq q q q q qq q q qq q qq q qq q qq qq qq q q q qqq q q qqq q q qq q q qq q q qq q q q q q qqq q qq qq qq qqq q q q q q qq q q q qq q qq q q qq qqq q q q qq q q q qq q q q qq q q qq qq q q q q qq q q qqqqqqq qq q qq q q qq q qq q q q q q qq q q q q qq qq q q q q q q q qq q qq q q q q qq qq q qq q q q q qq q q qqqqq q q q q q q qqq q qq q qq q qqq q q q qq q q qq q q q qq q q qqq q qq q q q qq q q q qq q qq q q q q qq q q q q q qq q qq q qqq qq q qqq qq q q q qqqq q q q q q q qq q qq q qq q qqq q q q q qq q q q q q q q q q q qq q qq q q q q q q qq q qq q qq qq q q q qqqqq qq q q qq q qq q q q qq q q q q q q qq qq q q qq q q q qq q qq q q q qq qq q qq qqq qq qq q q qq q q qq qq q qq qq q q qq q q q q q q qqq qq q q q q q qq qq q qqq q q q q q q q q q q q qq q q q q q q qq q q q q qq q qq q q q q q q q qq q q qq q qq qq q qq qq qq q q q q qq q q qq q qq q qq qqq q qq qq qq qq q q q q q qq q qq qq q qq q q q q q qq q qq q q qq q q qqq q qq q q q qq q q qq q q qq q q q q qq qq q q qq q qq q q qq q qq qq q q q q q q q qq q q qq q q qq q q q qq q qq q q q q q q q q q q qqqq q qq q qq q qq q qq q q q qq qq q q qq qqq q q q q q qq q q qqqqq q qq q q q q q q q qq q qq q qq q q qq q q q qq qq qq q qqq q q q q qq q q q qq q q qq qqq q q q qq q qq q qq q q q q q q qq q qq q qqqq q qq q q q qq q q q q q q qq qq q q q q q qqqq qq q q q qq q qq q q qq q q q q q q q q q q qq q qq q q qq q qq q qq q q qq qq q q q q q q qq q q q q q q qq q q qq qq qq qq q q q q qqqqq q qq q qq q q qq q q qq q qqq q q q q qq q q qq q q q qq q q qq q q q qqq q qq q q qq qq q q q q q qq q q qqq q qq qqq q q qq q q qqq q q q q q q q q q q qq q q q qq q q q q q q q q q q qq q qq q q q q q qq q qq q q q q q q qq q q qq q q qq q qq qq qq q q q qq qq q q q qq q q q qq q qq q q qqq q q qqq q q qq qq q q qq q q q qq q q q q q q qq q qq q q q q qqq q q qqqq q q qq q qq q q q qq q q q qq q q q qqq q q q q q q q q q q qqq q q q q q qq qq q qq q q qq q qq q qq qq q q q q q q q qq q q q q q qq q q q q q q qq q qq q q q q q q qq q qqq q q q q q q qq q q q q q q qq q q qq q q q q q q qq q q q q q q qqqq q q q qqq q qq q q q qqq q q qqq qq q q q q qq q q qq q q q qq qq q q q q q q qq q q q q q q qq q q q q q q q q qq qq q q q q q qqq q qq q q q q qq q qq q q q qq q q q q qq q q qqq qq q q q q qqq q qqq q q q q qq q qq q q q q q q qqq q q qq qq q q q q qq q q q q q qqq q q q q qq qq q q q qq q qqq q q q q q q qq q q q qqq q q q qq q qq qq qqq q q qqqqqq q qq q q q q q qq q q q q q q q q q q qqq qq q qq qqq q qq q q qq q q q q q q qq qq q q q q qqqq q qq q q q q qq q q q q q q qq q qq q q qq qq q q q qq q qqq q q qq q q q q q qq q q q q q q q q qq q q q qqq q q q q q qqq q qq q q q q qqq q q q q qq q q q q q qq q qq qq qq qq q q q q qq q q qq qq q qq q q q q qqq q qqq q qq q q q q qq q q q q qq qq q q qqq q q q q q q q q q q q qq q q qq q qqq q q q q q q q q q qq q q q q q qqq q q qq q q q q q q q q qq qq q q qq qq q q q qqq q q q q qqq qq q q qq qqq q q qq q q q q q q qq q q q qq q qq q q q q qq q q q q q q q q q q qq q q q q q q q q q q q qqq q q qqq q qq q q q q q q q q qq qq q qq qq q q q q q q q q q q q q qq q q qq q qqq q q qq q qq q q q qq q q q qq q q q q q qq q q qq q qq q q q q q q qq qq qqq qq q q q qqq q q qq q qqq qqq q q qq qqq q q q q q qq q qq qq qq q qq q qq q q qq q q q q q q qq q q q qq q q q q q q qq qq q q qq q q q q q qq q q q qq q q qq qqq q q qqqqq qq q qq q q qq q q qq q q q qq q q q q q q qq qq q qq qq q q qq q q q qq q q qq q q q q q q qq q q qq q q q q q qq q qq q q q q qq qq qq q q qq q q qq qq qq q qq q q q qq q q q qq q qq q q qq q qq qq qq q q q q q q q q q q qq qq q qqq q q q qq qq q qq qq qq q q qq q q q q qq qq qq q qq q q q q q q qq q qq q q q qqq q q qq q qq q q q q q q q q q q q qq q q q q q q qq q q q qq q qqq q q q q qq q q q q qq qqq q qq q q q qq qq q qq qq qq q q q q qq q qq q q q qq q q q q q q q q qq qq q q q qq q q q q qq q qq q q qq q q q qq q q q q q qq q q q qq qq q q q qq q qq q q q q q q q q q q qq q q qq q qqq q q q qqq q q q qq q qqqqq qq q q qq q q q q qq qq qq qq q q q q qq q qq q q qq q q q qq q qq q q q qq q qq qq q q qq qq q q q q qq q q qq q q qq q qq q q q q q qq q qq q q q q qq q q q qq q q q q qq q q qqqq q qq qq qq q q q q qq q q q qq q qq q q q q q qq q q q q qq qq qq qq q q qq q q qqq qq qq q q q q q q q q q q qq q q q q q q qq q qq q qqq q qq qq q q q q q q q q qq q q q qq q qqq qq qq q q q q q qq q q q q qq q q qq q qqq q q q qq qq q q q qqq q q q q q qq q q q q q q qqq q q q q q q qq q q q q q q q q qq q q q q q q q q q qq qq q q q q q qq q q qq q q q q q qq q q q q q q q qq q qq q q q q q qq q q q q qq q q qq q q q q qq q q q q qq q qq q qq qqq qq q q q q q q q qq q q q q q qq q q q qq q q q qq q q q q q q q q qq q q q q qq qq q q qq q q q q q qq q q q q q q q q qq q qq qq q q q q qq qq qq q q qq q qq q q qq q qq q q q q q qq q q qq q q q q q q q qq qq q q qq q q q q q q q q qq qq q qq qq q q q qq q q q q q q qq qq qq q q q q q qq qq q qqq q q qq q q q q q qq q q q q q q q qq q q q qq q q qq q qq q q q qq q q q q qq q q q q q qq qq q qq q q q qq qq qq q q q q q qq q qq q q q qq q q q q qq q q q q qq qq qqq q q q qq qqq q qq qq qq q q q q q qq q q q q q qqq q qqq q q qq q q q q qq q q qq q q q qq q q qq qq qq q q qqq q qq q qq q qq q q q q q qq q q q qq qq q qq q q qq q qq q q q q q q qq q qq qq q q qq q q q qq q q q qq qq q qq q q qq qq q qq q qq q q q q qq q q qq q q q qq qq q q q qqqq q qq q qq q q q qq q qq q qq q q q qq q q qq qq qq q q q q q q qqq q q q q qq qqq q qq q q q qq q qq q q q qq q q qq q q q q q q q q q q qq q qqq qq q q q q q q qq q qq q qq q q q q q qq q qq q q q qq q q q q q q q qq q q q qq q q qq q q q qq qq q q q qq q q qq q qq q q q q q q qq q q q qq q q qq q q qq q q qq q q q q q q qq q qq q qq q q qq qq q q q qq qq qq qq q q q qq q qq q q q q q qq q q qq qq q qq qq q q q q qq q qq q q q qq q q qq qq q q q q q q q q q qq q q q qq qq q q q q q q q qqq q q qq q q q q q q q q q G q q q q q q q q q q q 0.00 0.02 0.04 0.06 0.08 Risk (standard deviation) 5 0.10 0.12 q qq q ...
View Full Document

This note was uploaded on 06/02/2011 for the course STATS 183 taught by Professor Nicolas during the Spring '11 term at UCLA.

Ask a homework question - tutors are online