Housekeeping

  • Today’s plan 📋

    • Comments and Questions from Engagement Questions or about R 🪄

    • Upcoming Dates

    • Review Questions

    • Comparing Portfolios of Stocks

      • Profitability of one stock using geometric mean

      • Weighted Mean of two or more stocks

      • Volatility of One Stock using adjusted standard deviation

      • Volatility of weighted combination of two or more stocks

Upcoming Dates

  • HW 7 is due Wed. 11/5 at midnight.

  • Test 2 is on November 11th and will include material up through Lecture 20.

  • Practice Questions and demo videos are now available.

  • Lecture 21 - Intro to Portfolio Management, will be on Final Exam, not on Test 2.

R and RStudio

  • In this course we will use R and RStudio to understand statistical concepts.

  • You will access R and RStudio through Posit Cloud.

  • I will post R/RStudio files on Posit Cloud that you can access in provided links.

  • I will also provide demo videos that show how to access files and complete exercises.

  • NOTE: The free Posit Cloud account is limited to 25 hours per month.

    • For those who want to go further with R/RStudio:

    • If you are interested in downloading R and RStudio to your own computer, I can guide you through the process.

    • The software is completely free but it does have to be updated a couple times each year.

💥 Lecture 21 In-class Exercises - Q1 💥

Poll Everywhere - My User Name: penelopepoolereisenbies685

Recall that in lecture 20 we discussed \(R_{xy}\), the correlation coefficient.

The matrix shown here shows a correlation matrix for four stocks based on their 2023 - 2024 daily adjusted closing values.

A correlation matrix shows the pairwise correlation between each pair of stocks in the dataset.


Which other stock is most strongly positively correlated with Apple (AAPL)?

AAPL MSFT AMZN NFLX
AAPL 1.00 0.81 0.83 0.86
MSFT 0.81 1.00 0.96 0.88
AMZN 0.83 0.96 1.00 0.96
NFLX 0.86 0.88 0.96 1.00

💥 Lecture 21 In-class Exercises - Q2 💥

Poll Everywhere - My User Name: penelopepoolereisenbies685

Given the non-linear trends in stock prices, does it make sense to calculate the correlation, \(R_{xy}\), between pairs of stocks?

Calculating Average Rate of Return for Each Stock

  • For each of these four companies we have two year of data.

  • We want to know the average rate of return.

  • We could calculate the arithmetic mean of the adjusted close, but the conventional wisdom is that this is not ideal.

  • Instead, we calculate the geometric mean

  • The psych package in R has the geometric.mean command to do this calculation.

Geomtric Mean and Arithmetic Mean

If the Stocks are relatively stable, these values will be similar.

The geometric mean is more reliable because of the compounded interest.


The table below shows the geometric means of three of the stocks:

Stock Arithmetic_Mean Geo_Mean
AAPL 188.4278 186.3504
MSFT 362.8010 356.9529
AMZN 153.1268 NA
NFLX 531.4343 506.6509

💥 Lecture 21 In-class Exercises - Q3-Q4 💥

Poll Everywhere - My User Name: penelopepoolereisenbies685


Question 3. What is the geometric mean for the Amazon (AMZN) stock data?

  • Use the geometric.mean command from the psych package.
  • Round answer to two decimal places.


Question 4. Which of these four stocks shows the largest disparity between the geometric and arithmetic mean?

Calculating the Mean Rate of Return of a Portfolio

  • A primary concern when investing is “not putting all of your eggs in one basket”.

  • In other words, it is important to diversify your portfolio by investing in multiple stocks so that you have some protection if one stock crashes.

  • We can calculate the rate of return of a portfolio


  • To do this we calculate a weighted average of the individual stock geometric means:

    • \(W_{1}\times Geo.Mean_{1} + W_{2}\times Geo.Mean_{2}\)
    • \(W_{1}\) and \(W_{2}\) are the percentage of the portfolio invested in each stock.


  • In our simple examples, we will look at 2 stock portfolios, but the same principles apply to larger more complex portfolios.

  • This weighted average of the stock portfolio is referred to as it’s Expected Value..

Average Rates of Return of Portfolio Options


Example: Calculate the average rate of return of a portfolio where 80% is invested in Apple (AAPL) and 20% is invested in Netflix (NFLX).


w1 <- .8
w2 <- .2

gm_aapl <- geometric.mean(adj_close$AAPL) 
gm_nflx <- geometric.mean(adj_close$NFLX) 

w1*gm_aapl + w2*gm_nflx
[1] 250.4105

💥 Lecture 21 In-class Exercises - Q5-Q6 💥

Poll Everywhere - My User Name: penelopepoolereisenbies685

Round answer to both questions below to two decimal places.


Question 5: What is the average rate of return of a portfolio with 60% investment in Amazon (AMZN) and 40% investment in Microsoft (MSFT)?


Question 6: What is average rate of return of a portfolio with 70% investment in Amazon (AMZN) and 30% investment in Apple (AAPL)?

Volatility of a single Stock Rate of Return

Volatility is a measure of variability and risk associated with a stocks rate of return over time.

Volatlity for a single stock: \(Volatility = SD \times \sqrt{T} = \sqrt{VAR \times T}\)

  • T = number of time periods.

  • In these two years, there were 502 trading days, T = 502.

    • Examine imported data to verify T.

Variances, standard deviations, and volatilities for each of these stocks:

Stock Variance Std_Dev Volatility
AAPL 791.9415 28.14146 630.5193
MSFT 3906.1799 NA NA
AMZN 1332.0236 36.49690 817.7260
NFLX 27399.7493 165.52870 3708.7295

💥 Lecture 21 In-class Exercises - Q7 💥

Poll Everywhere - My User Name: penelopepoolereisenbies685

Question 7: What is the volatility of the Microsoft (MSFT) stock? Round answer to two decimal places.


Volatlity for a single stock: \[ Volatility = SD \times \sqrt{T} = \sqrt{VAR \times T} \]


Stock Variance Std_Dev Volatility
AAPL 791.9415 28.14146 630.5193
MSFT 3906.1799 NA NA
AMZN 1332.0236 36.49690 817.7260
NFLX 27399.7493 165.52870 3708.7295

Variance of a Two Stock Portfolio

Recall our portfolio where 80% is invested in Apple and 20% is invested in Netflix

Calculating the volatility of a portfolio little more complex, but it is easier if we break it down into steps.

Step 1: Calculate variance of portfolio of stocks 1 and 2, which is the sum of three parts:

Part 1: \(W_{1}^2 \times Variance_{1}\)
Part 2: \(W_{2}^2 \times Variance_{2}\)
Part 3: \(2 \times W_{1} \times W_{2} \times COV_{1,2}\)

Portfolio Variance = Part 1 + Part 2 + Part 3

w1 <- .8
w2 <- .2
var1 <-  var(adj_close$AAPL)                                  # Var 1
var2 <- var(adj_close$NFLX)                                   # Var 2
cov12 <- cov(adj_close$AAPL, adj_close$NFLX)                  # Cov 1 & 2
(portfolio_var <- w1^2*var1 + w2^2*var2 + 2*w1*w2*cov12)      # Part 1 + Part 2 + Part 3
[1] 2889.715

Volatility of Two Stock Portfolio

Step 1: Calculate variance of portfolio of stocks 1 and 2, sum of these three parts:

Part 1: \(W_{1}^2 \times Variance_{1}\)
Part 2: \(W_{2}^2 \times Variance_{2}\)
Part 3: \(2 \times W_{1} \times W_{2} \times COV_{1,2}\)

Portfolio Variance = Part 1 + Part 2 + Part 3

w1 <- .8
w2 <- .2
var1 <-  var(adj_close$AAPL)                                  # Var 1
var2 <- var(adj_close$NFLX)                                   # Var 2
cov12 <- cov(adj_close$AAPL, adj_close$NFLX)                     # Cov 1 & 2
(portfolio_var <- w1^2*var1 + w2^2*var2 + 2*w1*w2*cov12)   # Part 1 + Part 2 + Part 3
[1] 2889.715

Step 2: Calculate Volatility from Variance

\[ Volatlity = SD \times \sqrt{T} = \sqrt{VAR \times T}\]

T <- 502
(portfolio_volatility <- sqrt(portfolio_var*T)) 
[1] 1204.424

💥 Lecture 21 In-class Exercises - Q8-Q9 💥

Poll Everywhere - My User Name: penelopepoolereisenbies685

Round answer to both questions below to two decimal places.


Question 8: What is the volatility of a portfolio with 60% investment in Amazon and 40% investment in Microsoft?


Question 9: What is the volatility of a portfolio with 70% investment in Amazon and 30% investment in Apple?