Wednesday, June 29, 2011

Kenneth French Gift to the Finance World

Kenneth French gives one of the best gifts to the finance world at his website  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
#   require(PerformanceAnalytics)
require(ggplot2)   my.url=""
download.file(my.url, my.tempfile, method="auto",
quiet = FALSE, mode = "wb",cacheOK = TRUE)
#read space delimited text file extracted from zip
french_momentum <- read.table(file=my.usefile,
header = TRUE, sep = "", = TRUE,
skip = 12, nrows=1013)
colnames(french_momentum) <- c(paste("Small",
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],   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)
main="Performance by Kenneth French Size and Momentum
Monthly Since 1927"
side=1,adj=0,cex=0.75)   #jpeg(filename="rolling performance by momentum and size.jpg",quality=100,width=6.25, height = 5, units="in",res=96)
main="Performance by Kenneth French Size and Momentum
36 Month Rolling Since 1927"
legend.loc = "bottomright",
side=1,adj=0,cex=0.75)   #use ggplot2 for boxplot
#could also use chart.Boxplot() from PerformanceAnalytics
df <-
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")

Created by Pretty R at

1 comment:

  1. Is there a way that we can test our own relative strength or momentum strategies in R?

    Take 10 instruments (stocks, ETFs, Mutual Funds, etc)
    Rank them by a measure of goodness ( return, relative strength, etc.)
    Hold the top N ranked instrument
    Sell when the instrument drops out of the top N