Import Libraries

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)
library(readr)
library(readxl)
library(dplyr)
library(moments)
library(ggplot2)

Chapter 5: Risk, Return, and the Historical Record

12. Download the monthly reutrns of “6 portfolios formed on size and book-to-market (2x3).” Choose the value-weighted series for the period from January 1930-December 2018. Split the sample in half and compute the average, SD, skew, and kurtosis for each of the six portfolios for the two havles. Do the six split-havles statistics suggest to you that returns come from the same distribution over the entire period?

X6_Portfolios_2x3 <- read_csv("C:/Users/Admin/OneDrive - 亞洲大學[Asia University]/3rd Year/2nd Sem/1. Investment Portfolio Analysis/6_Portfolios_2x3.CSV")
## New names:
## Rows: 1171 Columns: 7
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," dbl
## (7): ...1, SMALL LoBM, ME1 BM2, SMALL HiBM, BIG LoBM, ME2 BM2, BIG HiBM
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
X6_Portfolios_2x3 <- X6_Portfolios_2x3 %>% 
  rename(Time = ...1)
glimpse(X6_Portfolios_2x3)
## Rows: 1,171
## Columns: 7
## $ Time         <dbl> 192607, 192608, 192609, 192610, 192611, 192612, 192701, 1…
## $ `SMALL LoBM` <dbl> 1.0874, 0.7030, -2.9117, -3.8196, 3.1806, 2.6862, -0.7991…
## $ `ME1 BM2`    <dbl> 0.9081, 1.5075, -0.1359, -4.3572, 3.6608, 1.8411, -0.3782…
## $ `SMALL HiBM` <dbl> -0.0695, 5.3842, -0.4374, -2.0112, 2.0944, 3.2639, 3.9316…
## $ `BIG LoBM`   <dbl> 5.7168, 2.7154, 1.4287, -3.5898, 3.1292, 2.9678, -0.2621,…
## $ `ME2 BM2`    <dbl> 1.8971, 2.7196, 0.0808, -2.3377, 2.9242, 2.6214, 0.0321, …
## $ `BIG HiBM`   <dbl> 2.0066, 5.6796, -0.7928, -3.9998, 3.1934, 2.2990, 4.0885,…

Choose the data from January 1930 to December 2018

X6_Portfolios_2x3_subset <- X6_Portfolios_2x3 %>% 
  filter(Time >= 193001 & Time <= 201812)
View(X6_Portfolios_2x3_subset)

Split the sample in half

first_half <- slice(X6_Portfolios_2x3_subset, 1:floor(nrow(X6_Portfolios_2x3_subset)/2))
second_half <- slice(X6_Portfolios_2x3_subset, (floor(nrow(X6_Portfolios_2x3_subset)/2)+1):nrow(X6_Portfolios_2x3_subset))

Compute the average, SD, skew, and kurtosis

  • First half of the data
first_half_stat <- data.frame(
  average = sapply(first_half[ ,2:7], mean),
  sd = sapply(first_half[ ,2:7], sd),
  skew = sapply(first_half[ ,2:7], skewness),
  kurtosis = sapply(first_half[ ,2:7], kurtosis)
)
print(first_half_stat)
##              average        sd      skew  kurtosis
## SMALL LoBM 0.9797676  8.211286 1.1852484 12.022978
## ME1 BM2    1.1645060  8.398445 1.6200903 15.900982
## SMALL HiBM 1.4797768 10.164258 2.3471818 20.526106
## BIG LoBM   0.7670809  5.706153 0.1649981  9.985251
## ME2 BM2    0.8096833  6.720350 1.7538693 20.724012
## BIG HiBM   1.1905485  8.894354 1.7614099 17.444886
  • Second half of the data
second_half_stat <- data.frame(
  average = sapply(second_half[ ,2:7], mean),
  sd = sapply(second_half[ ,2:7], sd),
  skew = sapply(second_half[ ,2:7], skewness),
  kurtosis = sapply(second_half[ ,2:7], kurtosis)
)
print(second_half_stat)
##              average       sd       skew kurtosis
## SMALL LoBM 1.0019361 6.706654 -0.4118103 5.098164
## ME1 BM2    1.3557082 5.301509 -0.5449690 6.447799
## SMALL HiBM 1.4333116 5.520811 -0.4718186 7.297837
## BIG LoBM   0.9783442 4.700226 -0.3331759 4.982826
## ME2 BM2    1.0637648 4.329627 -0.4583647 5.580251
## BIG HiBM   1.1273449 4.926489 -0.5464998 5.840163

The statistics from the two halves bear noticeable differences from each other (the sd of the first half of the data is higher than that of the second half, the skewness of the first half is all positve whereas that of the second half is all negative, etc.). For that reason, the six split-havles statistics do not suggest that returns come from the same distribution over the entire period.

CFA1: Given $100,000 to invest, what is the expected risk premium in dollars of investing in equities versus risk-free T-bills (U.S. Treasury bills) based on the following table?

Chapter5CFA1 <- read_excel("C:/Users/Admin/OneDrive - 亞洲大學[Asia University]/3rd Year/2nd Sem/1. Investment Portfolio Analysis/Chapter5CFA1.xlsx")
glimpse(Chapter5CFA1)
## Rows: 3
## Columns: 3
## $ Action             <chr> "Invest in equities", "Invest in equities", "Invest…
## $ Probability        <dbl> 0.6, 0.4, 1.0
## $ `Expected Returns` <dbl> 50000, -30000, 5000
equites_expected_returns = 0.6*50000+0.4*-30000
tbills_expected_returns = 1*5000
risk_premium = equites_expected_returns - tbills_expected_returns
risk_premium
## [1] 13000

The expected risk premium in dollars of investing in equities versus risk-free T-bills is $13,000

Chapter 6: Capital Allocation to Risky Assets

For Problems 10 through 12: Consider historical data showing that the average annual rate of return on the S&P 500 portfolio over the past 90 years has averaged roughly 8% more than the Treasury bill return and that the S&P 500 standard deviation has been about 20% per year. Assume these values are representative of investors’ expectations for future performance and that the current T-bill rate is 5%.

10. Calculate the expected return and variance of portfolios invested in T-bills and the S&P 500 index with weights as follows:

Chapter6_10 <- data.frame(
  w_bills = seq(0, 1, by = 0.2),
  w_index = rev(seq(0, 1, by = 0.2))
)
print(Chapter6_10)
##   w_bills w_index
## 1     0.0     1.0
## 2     0.2     0.8
## 3     0.4     0.6
## 4     0.6     0.4
## 5     0.8     0.2
## 6     1.0     0.0
tbill_return = 0.05
index_return = tbill_return+0.08
index_sd = 0.2
#Expected return
Chapter6_10$E_p <- Chapter6_10$w_bills*tbill_return+Chapter6_10$w_index*index_return
Chapter6_10
##   w_bills w_index   E_p
## 1     0.0     1.0 0.130
## 2     0.2     0.8 0.114
## 3     0.4     0.6 0.098
## 4     0.6     0.4 0.082
## 5     0.8     0.2 0.066
## 6     1.0     0.0 0.050
#Variance
Chapter6_10$V_p <- Chapter6_10$w_index^2*index_sd^2
Chapter6_10
##   w_bills w_index   E_p    V_p
## 1     0.0     1.0 0.130 0.0400
## 2     0.2     0.8 0.114 0.0256
## 3     0.4     0.6 0.098 0.0144
## 4     0.6     0.4 0.082 0.0064
## 5     0.8     0.2 0.066 0.0016
## 6     1.0     0.0 0.050 0.0000

Calculate the utility levels of each portfolio of Problem 10 for an investor with A = 2. What do you conclude?

Chapter6_10$U <- Chapter6_10$E_p-0.5*2*Chapter6_10$V_p
Chapter6_10
##   w_bills w_index   E_p    V_p      U
## 1     0.0     1.0 0.130 0.0400 0.0900
## 2     0.2     0.8 0.114 0.0256 0.0884
## 3     0.4     0.6 0.098 0.0144 0.0836
## 4     0.6     0.4 0.082 0.0064 0.0756
## 5     0.8     0.2 0.066 0.0016 0.0644
## 6     1.0     0.0 0.050 0.0000 0.0500

With A=2, the utility score is the highest when the portfolio consists of all risky asset

12. Repeat Problem 11 for an investor with A = 3. What do you conclude?

Chapter6_10$U <- Chapter6_10$E_p-0.5*3*Chapter6_10$V_p
Chapter6_10
##   w_bills w_index   E_p    V_p      U
## 1     0.0     1.0 0.130 0.0400 0.0700
## 2     0.2     0.8 0.114 0.0256 0.0756
## 3     0.4     0.6 0.098 0.0144 0.0764
## 4     0.6     0.4 0.082 0.0064 0.0724
## 5     0.8     0.2 0.066 0.0016 0.0636
## 6     1.0     0.0 0.050 0.0000 0.0500

With A=3, the ulitity score is the highest when the portfolio is diversified, with the weights of the risk-free and risky assets being 0.4 and 0.6

CFA Problems

Chapter6CFA <- read_excel("C:/Users/Admin/OneDrive - 亞洲大學[Asia University]/3rd Year/2nd Sem/1. Investment Portfolio Analysis/Chapter6CFA.xlsx")
View(Chapter6CFA)

1. Which investment would you select if you were risk averse with A = 4?

Chapter6CFA$U <- Chapter6CFA$Er-0.5*4*Chapter6CFA$sd^2
Chapter6CFA
## # A tibble: 4 × 4
##   Investment    Er    sd      U
##        <dbl> <dbl> <dbl>  <dbl>
## 1          1  0.12  0.3  -0.06 
## 2          2  0.15  0.5  -0.35 
## 3          3  0.21  0.16  0.159
## 4          4  0.24  0.21  0.152

If we were risk averse with A = 4, we would choose the 3rd investment

2. Which investment would you select if you were risk neutral?

Chapter6CFA$U <- Chapter6CFA$Er-0.5*0*Chapter6CFA$sd^2
Chapter6CFA
## # A tibble: 4 × 4
##   Investment    Er    sd     U
##        <dbl> <dbl> <dbl> <dbl>
## 1          1  0.12  0.3   0.12
## 2          2  0.15  0.5   0.15
## 3          3  0.21  0.16  0.21
## 4          4  0.24  0.21  0.24

If we were risk neutral, we would only consider the expected return of the investment, so we would choose the 4th investment

3. The variable (A) in the utility formula represents the investor’s aversion to risk