Chapter 3: Portfolio Returns

Key Issues

portfolio returns = returns of basket of securities benchmark portfolio = hypothetical portfolio that we can compare the performance of our portf

3.1 Constructing Portfolio Returns (Long Way)

Portfolio return is the weighted average of the returns of the individual securities in the portfolio. Suppose we invested $40K in AMZN, $10 in Microsoft, $10 in Apple, $20 in Tesla, $10 in IBM and $10 in Facebook between December 31, 2013 and September 31, 2017.

Step 0: Import Price Data

# To clean up the memory of your current R session run the following line
rm(list=ls(all=TRUE))

library(quantmod)
library(xts)

#Importing Price Data
data.AMZN <- getSymbols("AMZN", from = "2013-12-31", to = "2017-10-01", auto.assign = FALSE)
data.TSLA <- getSymbols("TSLA", from = "2013-12-31", to = "2017-10-01", auto.assign = FALSE)
data.IBM <- getSymbols("IBM", from = "2013-12-31", to = "2017-10-01", auto.assign = FALSE)
data.AAPL <- getSymbols("AAPL", from = "2013-12-31", to = "2017-10-01", auto.assign = FALSE)
data.FB <- getSymbols("FB", from = "2013-12-31", to = "2017-10-01", auto.assign = FALSE)
data.MSFT <- getSymbols("MSFT", from = "2013-12-31", to = "2017-10-01", auto.assign = FALSE)

#to = "2013-12-31" in the book was replaced by to = "2017-10-01"
#B/c that code doesn't produce the output that includes stock price of 2013-12-31the date. 

multi <- data.AMZN[, 6] # Need to create a new data object before cbinding
multi <- cbind(multi, data.TSLA[, 6], data.IBM[, 6], data.AAPL[, 6], data.FB[, 6], data.MSFT[, 6])

Step 1: Find First and Last Adjusted Closing Price for Each Security Over the Investmet Period

period.ret <- multi[c(1, nrow(multi)), ]
period.ret
##            AMZN.Adjusted TSLA.Adjusted IBM.Adjusted AAPL.Adjusted
## 2013-12-31        398.79        150.43      166.089      74.57128
## 2017-09-29        961.35        341.10      145.080     154.11999
##            FB.Adjusted MSFT.Adjusted
## 2013-12-31       54.65      33.91713
## 2017-09-29      170.87      74.49000

Step 2: Calculate Returns for Each Security Over the Investment Period

rets <- lapply(period.ret, Delt) # lapply returns output in a list
rets
## $AMZN.Adjusted
##            Delt.1.arithmetic
## 2013-12-31                NA
## 2017-09-29          1.410667
## 
## $TSLA.Adjusted
##            Delt.1.arithmetic
## 2013-12-31                NA
## 2017-09-29            1.2675
## 
## $IBM.Adjusted
##            Delt.1.arithmetic
## 2013-12-31                NA
## 2017-09-29        -0.1264924
## 
## $AAPL.Adjusted
##            Delt.1.arithmetic
## 2013-12-31                NA
## 2017-09-29          1.066747
## 
## $FB.Adjusted
##            Delt.1.arithmetic
## 2013-12-31                NA
## 2017-09-29          2.126624
## 
## $MSFT.Adjusted
##            Delt.1.arithmetic
## 2013-12-31                NA
## 2017-09-29          1.196236
#rets <- mapply(Delt, data.frame(period.ret)) #mapply does the same but returns output in DF

Step 3: Convert to a data.frame and Clean up Data

rets <- data.frame(rets)
rets
##            Delt.1.arithmetic Delt.1.arithmetic.1 Delt.1.arithmetic.2
## 2013-12-31                NA                  NA                  NA
## 2017-09-29          1.410667              1.2675          -0.1264924
##            Delt.1.arithmetic.3 Delt.1.arithmetic.4 Delt.1.arithmetic.5
## 2013-12-31                  NA                  NA                  NA
## 2017-09-29            1.066747            2.126624            1.196236
rets <- rets[2, ] * 100
names(rets) <- paste(c("AMZN", "TSLA", "IBM","AAPL","FB","MSFT"))
rets
##                AMZN   TSLA       IBM     AAPL       FB     MSFT
## 2017-09-29 141.0667 126.75 -12.64924 106.6747 212.6624 119.6236

Step 4: Calculate Weight of Each Security in the Portfolio

i.AMZN <- 40000
i.TSLA <- 20000
i.IBM <- 10000
i.AAPL <- 10000
i.FB <- 10000
i.MSFT <- 10000


w.AMZN <- i.AMZN / (i.AMZN + i.TSLA + i.IBM+ i.AAPL + i.FB+ i.MSFT)
w.TSLA <- i.TSLA / (i.AMZN + i.TSLA + i.IBM+ i.AAPL + i.FB+ i.MSFT)
w.IBM <- i.IBM / (i.AMZN + i.TSLA + i.IBM+ i.AAPL + i.FB+ i.MSFT)
w.AAPL <- i.AAPL / (i.AMZN + i.TSLA + i.IBM+ i.AAPL + i.FB+ i.MSFT)
w.FB <- i.FB / (i.AMZN + i.TSLA + i.IBM+ i.AAPL + i.FB+ i.MSFT)
w.MSFT <- i.FB / (i.AMZN + i.TSLA + i.IBM+ i.AAPL + i.FB + i.MSFT)
w.AMZN
## [1] 0.4
w.TSLA
## [1] 0.2
w.IBM
## [1] 0.1
w.AAPL
## [1] 0.1
w.FB
## [1] 0.1
w.MSFT
## [1] 0.1

Step 5: Calculate Portfolio Return

port.ret.3asset <- w.AMZN * rets$AMZN + w.TSLA * rets$TSLA + w.IBM * rets$IBM + w.AAPL * rets$AAPL + w.FB * rets$FB + w.MSFT * rets$MSFT
port.ret.3asset 
## [1] 124.4078

Interpretation

The stock that performed the best would be FB, it had the highest net gain of $212.

This portfolio would have had a gross return of $224.4 because the portfolio had a $124 net gain.

# Alternative Portfolio

Chapter 3: Portfolio Returns

Key Issues

portfolio returns = returns of basket of securities benchmark portfolio = hypothetical portfolio that we can compare the performance of our portf

3.1 Constructing Portfolio Returns (Long Way)

Portfolio return is the weighted average of the returns of the individual securities in the portfolio. Suppose we invested $10K in AMZN, $10 in Microsoft, $10 in Apple, $30 in Tesla, $30 in IBM and $10 in Facebook during the same period. How much the alternative portfolio return?

Step 0: Import Price Data

# To clean up the memory of your current R session run the following line
rm(list=ls(all=TRUE))

library(quantmod)
library(xts)

#Importing Price Data
data.AMZN <- getSymbols("AMZN", from = "2013-12-31", to = "2017-10-01", auto.assign = FALSE)
data.TSLA <- getSymbols("TSLA", from = "2013-12-31", to = "2017-10-01", auto.assign = FALSE)
data.IBM <- getSymbols("IBM", from = "2013-12-31", to = "2017-10-01", auto.assign = FALSE)
data.AAPL <- getSymbols("AAPL", from = "2013-12-31", to = "2017-10-01", auto.assign = FALSE)
data.FB <- getSymbols("FB", from = "2013-12-31", to = "2017-10-01", auto.assign = FALSE)
data.MSFT <- getSymbols("MSFT", from = "2013-12-31", to = "2017-10-01", auto.assign = FALSE)

#to = "2013-12-31" in the book was replaced by to = "2017-10-01"
#B/c that code doesn't produce the output that includes stock price of 2013-12-31the date. 

multi <- data.AMZN[, 6] # Need to create a new data object before cbinding
multi <- cbind(multi, data.TSLA[, 6], data.IBM[, 6], data.AAPL[, 6], data.FB[, 6], data.MSFT[, 6])

Step 1: Find First and Last Adjusted Closing Price for Each Security Over the Investmet Period

period.ret <- multi[c(1, nrow(multi)), ]
period.ret
##            AMZN.Adjusted TSLA.Adjusted IBM.Adjusted AAPL.Adjusted
## 2013-12-31        398.79        150.43      166.089      74.57128
## 2017-09-29        961.35        341.10      145.080     154.11999
##            FB.Adjusted MSFT.Adjusted
## 2013-12-31       54.65      33.91713
## 2017-09-29      170.87      74.49000

Step 2: Calculate Returns for Each Security Over the Investment Period

rets <- lapply(period.ret, Delt) # lapply returns output in a list
rets
## $AMZN.Adjusted
##            Delt.1.arithmetic
## 2013-12-31                NA
## 2017-09-29          1.410667
## 
## $TSLA.Adjusted
##            Delt.1.arithmetic
## 2013-12-31                NA
## 2017-09-29            1.2675
## 
## $IBM.Adjusted
##            Delt.1.arithmetic
## 2013-12-31                NA
## 2017-09-29        -0.1264924
## 
## $AAPL.Adjusted
##            Delt.1.arithmetic
## 2013-12-31                NA
## 2017-09-29          1.066747
## 
## $FB.Adjusted
##            Delt.1.arithmetic
## 2013-12-31                NA
## 2017-09-29          2.126624
## 
## $MSFT.Adjusted
##            Delt.1.arithmetic
## 2013-12-31                NA
## 2017-09-29          1.196236
#rets <- mapply(Delt, data.frame(period.ret)) #mapply does the same but returns output in DF

Step 3: Convert to a data.frame and Clean up Data

rets <- data.frame(rets)
rets
##            Delt.1.arithmetic Delt.1.arithmetic.1 Delt.1.arithmetic.2
## 2013-12-31                NA                  NA                  NA
## 2017-09-29          1.410667              1.2675          -0.1264924
##            Delt.1.arithmetic.3 Delt.1.arithmetic.4 Delt.1.arithmetic.5
## 2013-12-31                  NA                  NA                  NA
## 2017-09-29            1.066747            2.126624            1.196236
rets <- rets[2, ] * 100
names(rets) <- paste(c("AMZN", "TSLA", "IBM","AAPL","FB","MSFT"))
rets
##                AMZN   TSLA       IBM     AAPL       FB     MSFT
## 2017-09-29 141.0667 126.75 -12.64924 106.6747 212.6624 119.6236

Step 4: Calculate Weight of Each Security in the Portfolio

i.AMZN <- 10000
i.TSLA <- 30000
i.IBM <- 30000
i.AAPL <- 10000
i.FB <- 10000
i.MSFT <- 10000


w.AMZN <- i.AMZN / (i.AMZN + i.TSLA + i.IBM+ i.AAPL + i.FB+ i.MSFT)
w.TSLA <- i.TSLA / (i.AMZN + i.TSLA + i.IBM+ i.AAPL + i.FB+ i.MSFT)
w.IBM <- i.IBM / (i.AMZN + i.TSLA + i.IBM+ i.AAPL + i.FB+ i.MSFT)
w.AAPL <- i.AAPL / (i.AMZN + i.TSLA + i.IBM+ i.AAPL + i.FB+ i.MSFT)
w.FB <- i.FB / (i.AMZN + i.TSLA + i.IBM+ i.AAPL + i.FB+ i.MSFT)
w.MSFT <- i.FB / (i.AMZN + i.TSLA + i.IBM+ i.AAPL + i.FB + i.MSFT)
w.AMZN
## [1] 0.1
w.TSLA
## [1] 0.3
w.IBM
## [1] 0.3
w.AAPL
## [1] 0.1
w.FB
## [1] 0.1
w.MSFT
## [1] 0.1

Step 5: Calculate Portfolio Return

port.ret.3asset <- w.AMZN * rets$AMZN + w.TSLA * rets$TSLA + w.IBM * rets$IBM + w.AAPL * rets$AAPL + w.FB * rets$FB + w.MSFT * rets$MSFT
port.ret.3asset 
## [1] 92.23296

Interpretation

This portfolio would have had a gross return of $192.2 because the portfolio had a $92.23 net gain. This portfolio did not perform as well as the original. The original is better due to weights, the higher weight in better performing stocks in the first portfolio out preformed this one.