Path: blob/master/sandbox/script.buildEDHEC.R
1433 views
### Construct an xts object of EDHEC composite hedge fund style indexes12# Peter Carl34# Used for updating the edhec data object in PerformanceAnalytics56require(gdata)7require(xts)89# Download the following file to the working directory:10# http://www.edhec-risk.com/indexes/pure_style/data/table/history.csv11### @TODO: Is there a way to download it directly? Maybe not, seems to require a login12x<-read.csv(file=download.file("http://www.edhec-risk.com/indexes/pure_style/data/table/history.csv"), sep=";", header=TRUE, check.names=FALSE)13#x=read.csv(file="history.csv", sep=";", header=TRUE, check.names=FALSE)14x.dates = as.Date(x[,1], format="%d/%m/%Y")15x.data = apply(x[,-1], MARGIN=2, FUN=function(x){as.numeric(sub("%","", x, fixed=TRUE))/100}) # get rid of percentage signs16edhec = xts(x.data, order.by=x.dates)17colnames(edhec)1819# calculate a wealth index20edhec.idx = apply(edhec, MARGIN=2, FUN=function(x){cumprod(1 + na.omit(x))})21# identify quarters22edhec.Q.idx=edhec.idx[endpoints(edhec.idx, on="quarters"),]23# calculate quarterly returns24edhec.Q.R=ROC(edhec.Q.idx)25# trim the last data point, if needed26# dim(edhec.Q.R)27# edhec.Q.R=edhec.Q.R[-61,]28# reclass the object29edhec.Q.R=as.xts(edhec.Q.R)30# lm requires safe names31colnames(edhec.Q.R)=make.names(colnames(edhec))32333435