Kenneth French Gift to the Finance World

June 29, 2011
By

(This article was first published on Timely Portfolio, and kindly contributed to R-bloggers)

Kenneth French gives one of the best gifts to the finance world at his website http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html.  I am surprised I have waited so long to write a post about this wonderful resource.  After seeing Systematic Relative Strength’s post The #1 Investment Return Factor No One Wants to Talk About, I thought I would play with Size and Momentum in R, and it is very clear that size and momentum have been very important return factors.

From TimelyPortfolio
From TimelyPortfolio
From TimelyPortfolio

R code (click to download):

#get very helpful Ken French data
#for this project we will look at Momentum Portfolios
#http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/6_Portfolios_ME_Prior_12_2.zip   require(PerformanceAnalytics)
require(quantmod)
require(ggplot2)   my.url="http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/6_Portfolios_ME_Prior_12_2.zip"
my.tempfile<-paste(tempdir(),"\\frenchmomentum.zip",sep="")
my.usefile<-paste(tempdir(),"\\6_Portfolios_ME_Prior_12_2.txt",sep="")
download.file(my.url, my.tempfile, method="auto",
quiet = FALSE, mode = "wb",cacheOK = TRUE)
unzip(my.tempfile,exdir=tempdir(),junkpath=TRUE)
#read space delimited text file extracted from zip
french_momentum <- read.table(file=my.usefile,
header = TRUE, sep = "",
as.is = TRUE,
skip = 12, nrows=1013)
colnames(french_momentum) <- c(paste("Small",
colnames(french_momentum)[1:3],sep="."),
paste("Large",colnames(french_momentum)[1:3],sep="."))     #get dates ready for xts index
datestoformat <- rownames(french_momentum)
datestoformat <- paste(substr(datestoformat,1,4),
substr(datestoformat,5,7),"01",sep="-")   #get xts for analysis
french_momentum_xts <- as.xts(french_momentum[,1:6],
order.by=as.Date(datestoformat))   french_momentum_xts <- french_momentum_xts/100   #jpeg(filename="performance by momentum and size.jpg",quality=100,width=6.25, height = 5, units="in",res=96)
charts.PerformanceSummary(french_momentum_xts,ylog=TRUE,
main="Performance by Kenneth French Size and Momentum
Monthly Since 1927"
,
colorset=c("cadetblue3","cadetblue","cadetblue4",
"darkolivegreen3","darkolivegreen","darkolivegreen4"))
mtext("Source: http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html",
side=1,adj=0,cex=0.75)
#dev.off()   #jpeg(filename="rolling performance by momentum and size.jpg",quality=100,width=6.25, height = 5, units="in",res=96)
chart.RollingPerformance(french_momentum_xts,width=36,
main="Performance by Kenneth French Size and Momentum
36 Month Rolling Since 1927"
,
legend.loc = "bottomright",
colorset=c("cadetblue3","cadetblue","cadetblue4",
"darkolivegreen3","darkolivegreen","darkolivegreen4"))
mtext("Source: http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html",
side=1,adj=0,cex=0.75)
#dev.off()   #use ggplot2 for boxplot
#could also use chart.Boxplot() from PerformanceAnalytics
df <- as.data.frame(
cbind(as.Date(index(french_momentum_xts)),
coredata(french_momentum_xts)))
dfmelt <- melt(df,id.vars=1)
colnames(dfmelt) <- c("date","frenchmomentum","return")
#jpeg(filename="boxplot by momentum and size.jpg",quality=100,width=6.25, height = 5, units="in",res=96)
ggplot(dfmelt,aes(x=frenchmomentum,y=return,colour=frenchmomentum)) +
geom_boxplot() + opts(title="Kenneth French Momentum and Size")
#dev.off()

Created by Pretty R at inside-R.org

To leave a comment for the author, please follow the link and comment on his blog: Timely Portfolio.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , ,

Comments are closed.