## ## read Ken French data. In this example, read 5 industry portfolios and the Fama-French 3 factors ## library(xts) Sys.setlocale(category = "LC_ALL", locale = "C") filename <- "5_Industry_Portfolios_ew.csv" FF5IndusEW <- read.table(filename, header=TRUE,skip=10, na.strings=c(" -99.99","-99.99","-999"), sep=",") # convert to time series dates <- as.yearmon(as.character(FF5IndusEW[,1]),format="%Y%m") FF5IndusEW <- xts(coredata(FF5IndusEW[,2:6]), order.by=dates) # data is in percent, divide by 100 to get returns FF5IndusEW <- FF5IndusEW / 100 # now get 3 factors filename <- "F-F_Research_Data_Factors.csv" FF <- read.table(filename, header=TRUE, skip=3, na.strings=c("-99.99","-999"), sep=",") # make time series dates <- as.yearmon(as.character(FF[,1]),format="%Y%m") FF <- xts(coredata(FF[,2:5]), order.by=dates) # make returns from percentage returns RMRF <- FF$Mkt.RF/100 SMB <- FF$SMB/100 HML <- FF$HML/100 RF <- FF$RF/100 # the market return is the risk free rate plus the market risk premium RM <- RF + RMRF names(RMRF) <- "RMRF" names(RM) <- "RM" names(RF) <- "RF" names(HML) <- "HML" names(SMB) <- "SMB"