Load necessary libraries
x<-c("readr", "ggplot2", "tidyr", "lubridate", "dplyr", "moments", "readxl", "tidyverse")
lapply(x, require, character.only = TRUE)
## Loading required package: readr
## Loading required package: ggplot2
## Loading required package: tidyr
## Loading required package: lubridate
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
## Loading required package: dplyr
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## Loading required package: moments
## Loading required package: readxl
## Loading required package: tidyverse
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ purrr 1.0.2 ✔ tibble 3.2.1
## ── 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
## [[1]]
## [1] TRUE
##
## [[2]]
## [1] TRUE
##
## [[3]]
## [1] TRUE
##
## [[4]]
## [1] TRUE
##
## [[5]]
## [1] TRUE
##
## [[6]]
## [1] TRUE
##
## [[7]]
## [1] TRUE
##
## [[8]]
## [1] TRUE
Read data
df <- read_csv("C:/Users/user/Downloads/6_Portfolios_2x3_CSV/clean.CSV")
## Rows: 1171 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Date
## dbl (6): 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.
Select timeframe from January 1930 to December 2018
df
## # A tibble: 1,171 × 7
## Date `SMALL LoBM` `ME1 BM2` `SMALL HiBM` `BIG LoBM` `ME2 BM2` `BIG HiBM`
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1926/07 1.09 0.908 -0.0695 5.72 1.90 2.01
## 2 1926/08 0.703 1.51 5.38 2.72 2.72 5.68
## 3 1926/09 -2.91 -0.136 -0.437 1.43 0.0808 -0.793
## 4 1926/10 -3.82 -4.36 -2.01 -3.59 -2.34 -4.00
## 5 1926/11 3.18 3.66 2.09 3.13 2.92 3.19
## 6 1926/12 2.69 1.84 3.26 2.97 2.62 2.30
## 7 1927/01 -0.799 -0.378 3.93 -0.262 0.0321 4.09
## 8 1927/02 3.71 6.38 6.62 5.00 3.58 7.99
## 9 1927/03 -1.83 -0.989 -3.17 1.30 0.253 -2.59
## 10 1927/04 -1.67 0.874 3.48 3.05 -0.774 -0.481
## # ℹ 1,161 more rows
df_subset <- df %>%
filter(Date >= 193001 & Date <= 201812)
View(df_subset)
Split sample in half
subset_1 <- slice(df_subset, 1:floor(nrow(df_subset)/2))
subset_2 <- slice(df_subset, (floor(nrow(df_subset)/2)+1):nrow(df_subset))
View(subset_2)
Subset 1 - Average, SD, Skewness, Kurtosis
subset_1_calc <- data.frame(
average = sapply(subset_1[ ,2:7], mean),
sd = sapply(subset_1[ ,2:7], sd),
skew = sapply(subset_1[ ,2:7], skewness),
kurtosis = sapply(subset_1[ ,2:7], kurtosis)
)
print(subset_1_calc)
## average sd skew kurtosis
## SMALL LoBM 1.0225737 8.210600 1.2181616 12.087331
## ME1 BM2 1.1978388 8.365423 1.6744646 16.238385
## SMALL HiBM 1.5499502 10.110287 2.4318043 21.053030
## BIG LoBM 0.7892422 5.755364 0.2765535 9.891562
## ME2 BM2 0.8618081 6.708024 1.7966166 21.004929
## BIG HiBM 1.2723922 8.867830 1.8010769 17.734116
Subset 2 - Average, SD, Skewness, Kurtosis
subset_2_calc <- data.frame(
average = sapply(subset_2[ ,2:7], mean),
sd = sapply(subset_2[ ,2:7], sd),
skew = sapply(subset_2[ ,2:7], skewness),
kurtosis = sapply(subset_2[ ,2:7], kurtosis)
)
print(subset_2_calc)
## average sd skew kurtosis
## SMALL LoBM 1.063030 6.655904 -0.4396068 5.251192
## ME1 BM2 1.412016 5.276177 -0.5671662 6.625842
## SMALL HiBM 1.492872 5.492014 -0.4916183 7.509068
## BIG LoBM 1.025861 4.542403 -0.4544893 4.708999
## ME2 BM2 1.091672 4.299072 -0.4962222 5.725935
## BIG HiBM 1.170037 4.908458 -0.5678354 5.972209
First half shows positive skewness whereas second half shows negative skewness. Also the sd in the 2nd half is lower than that of the first half. This suggests that returns do not come from the same distribution over the entire period
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:
Create dataframe for weights
ch6_10 <- data.frame(
w_bills = seq(0, 1, by = 0.2),
w_index = rev(seq(0, 1, by = 0.2))
)
View(ch6_10)
tbill_rate = 0.05
index_return = 0.08+tbill_rate
index_sd = 0.2
Calculate expected return Expected Return = (Weight of T-bills * Expected Return of T-bills) + (Weight of S&P 500 Index * Expected Return of S&P 500 Index)
ch6_10$e_r <- ch6_10$w_bills*tbill_rate+ch6_10$w_index*index_return
View(ch6_10)
Calculate Variance
ch6_10$var <- ch6_10$w_index^2*index_sd^2
View(ch6_10)
U = E(r) – 0.5 × Aσ2 = E(r) – σ2 Utility level A=2
ch6_10$U1 <- ch6_10$e_r-0.5*2*ch6_10$var
ch6_10
## w_bills w_index e_r var U1
## 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
U1 or U(A=2) suggests that investors with U(A=2) prefer a portfolio that is invested 100% in the market index than any of the other portfolios in the table
Utility level A=3
ch6_10$U2 <- ch6_10$e_r-0.5*3*ch6_10$var
ch6_10
## w_bills w_index e_r var U1 U2
## 1 0.0 1.0 0.130 0.0400 0.0900 0.0700
## 2 0.2 0.8 0.114 0.0256 0.0884 0.0756
## 3 0.4 0.6 0.098 0.0144 0.0836 0.0764
## 4 0.6 0.4 0.082 0.0064 0.0756 0.0724
## 5 0.8 0.2 0.066 0.0016 0.0644 0.0636
## 6 1.0 0.0 0.050 0.0000 0.0500 0.0500
U2 or U(A=3) suggests that risk averse investors prefer the portfolio that is invested 60% in the market, rather than the 100% market weight preferred by investors with A = 2.