Cross Pollination from Systematic Investor

[This article was first published on Timely Portfolio, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

After reading the fine article Style Analysis from Systematic Investor and What we can learn from Bill Miller and the Legg Mason Value Trust from Asymmetric Investment Returns, I thought I should combine the two in R with the FactorAnalytics package.  Let’s explore the Legg Mason Value Trust run by Bill Miller to get some insight into the source of his returns over many years by using the Ken French momentum by size data set as factors.

From TimelyPortfolio
From TimelyPortfolio
From TimelyPortfolio

R code (click to download from Google Docs):

#use Ken French momentum style indexes for style analysis
#   require(PerformanceAnalytics)
require(quantmod)   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=1017)
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   #get price series from monthly returns
#check data for reasonability
plot.zoo(french_price,log="y")   #for this example let's use Bill Miller's fund
getSymbols("LMVTX",from="1896-01-01", to=Sys.Date(), adjust=TRUE)
LMVTX <- to.monthly(LMVTX)
index(LMVTX) <- as.Date(format(as.Date(index(LMVTX)),"%Y-%m-01"))
LMVTX.roc <- ROC(LMVTX[,4],type="discrete",n=1)   perfComp <- na.omit(merge(LMVTX.roc,french_momentum_xts))   chart.RollingStyle(perfComp[,1],perfComp[,2:NCOL(perfComp)],
	main="LMVTX Rolling 36mo French Momentum Weights")
#could use the packaged chart.Style but does not allow the
#flexibility I would like
#	colorset=c("darkseagreen1","darkseagreen3","darkseagreen4","slateblue1","slateblue3","slateblue4"),
#	main="LMVTX French Momentum Weights")   #get weights for the cumulative period
style.weight <- as.matrix([,1],
	main=paste("LMVTX French Momentum Weights
	Since ",format(index(LMVTX)[1],"%b %Y"),sep=""))   #look at total R to determine goodness of fit
style.R <-[,1],
	perfComp[,2:NCOL(perfComp)])$R.squared     styleR <- function(x) {
#convert to matrix since I get
#error "The data cannot be converted into a time series."
#when I use xts as data
style.RollingR <- as.xts(rollapply(data=as.matrix(perfComp),
chart.TimeSeries(style.RollingR,ylab="Rolling 12-mo R",
	main=paste("LMVTX Rolling R versus French Momentum
	Since ",format(index(LMVTX)[1],"%b %Y"),sep=""))
text(x=1,y=style.R,labels="r for entire series",adj=0,col="indianred")

To leave a comment for the author, please follow the link and comment on their blog: Timely Portfolio. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)