# Regression - Single Factor Model Estimation of Beta, CAPM Estimation of Jensen's Alpha #Import processed indices dataset# —> students should change the import path according to their desktop(or save CAPM text file to downloads) library(readr) CAPM <- read_delim("Downloads/CAPM.txt", "\t", escape_double = FALSE, trim_ws = TRUE) View(CAPM) #Install and load required packages# install.packages("fBasics") library(fBasics) #Verify first few lines of dataset (Optional)# da <- CAPM head(da) #Summarise statistics# cols <- c("RtnInf","RtnSp500","Tb10y","InfrMTb10","Sp500MTb10") basicStats(da[cols]) #Reference --> Tsay, 2014. #Run single factor model to estimate beta# summary(lm(da$RtnInf~da$RtnSp500)) summary(aov(da$RtnInf~da$RtnSp500)) #Show the fitted line using scatter plot# plot(da$RtnSp500, da$RtnInf, pch = 19, xlab = "Log Return on S&P 500 (RtnSp500)", ylab = "Log Return on Infrastructure Index(RtnInf)", col = "cadetblue3") abline(lm(da$RtnInf~da$RtnSp500), col = "deepskyblue4") legend("bottomright",legend = c("RtnInf","Fitted values"), pch = c(19,NA), lty = c(NA,1), col = c("cadetblue3","deepskyblue4"), cex = 0.75) #Use CAPM to estimate Jensen's alpha --> Ri-Rf = alpha + Beta (ERP) + u# summary(lm(da$InfrMTb10~da$Sp500MTb10)) summary(aov(da$InfrMTb10~da$Sp500MTb10)) #Show the fitted line using scatter plot# plot(da$Sp500MTb10, da$InfrMTb10, pch = 19, xlab = "Sp500MTb10", ylab = "InfrMTb10", col = "cadetblue3") abline(lm(da$InfrMTb10~da$Sp500MTb10), col = "deepskyblue4") legend("bottomright",legend = c("InfrMTb10","Fitted values"), pch = c(19,NA), lty = c(NA,1), col = c("cadetblue3","deepskyblue4"), cex = 0.5)