Download and parse EDHEC hedge fund indexes

In our pre-conference workshop, Brian Peterson and I worked with the EDHEC hedge fund indexes as a way to demonstrate how to use PortfolioAnalytics within the context of long-term allocation problems.

Although they are not investible, these indexes are probably more representative than most given that they are, in fact, meta-indexes. Other indexes might be preferable when considering a specific portfolio, however.

Here’s how to parse the data. Unfortunately, there’s no good way to download the data directly (as far as I can figure), so you’ll have to have to log in (registration is free) and download the data manually. The code shown here only requires PerformanceAnalytics.

Here’s a parser for once you have the history.csv file in a local directory.

require(xts)
# Download the following file to the working directory:
# http://www.edhec-risk.com/indexes/pure_style/data/table/history.csv
x=read.csv(file="history.csv", sep=";", header=TRUE, check.names=FALSE)
x.dates = as.Date(x[,1], format="%d/%m/%Y")
x.data = apply(x[,-1], MARGIN=2, FUN=function(x){as.numeric(sub("%","", x, fixed=TRUE))/100}) # get rid of percentage signs
edhec = xts(x.data, order.by=x.dates)

Now we can draw some pictures. Here are cumulative returns and drawdowns through time.

# Drop some indexes and reorder
edhec.R = edhec[,c("Convertible Arbitrage", "Equity Market Neutral","Fixed Income Arbitrage", "Event Driven", "CTA Global", "Global Macro", "Long/Short Equity")]

require(PerformanceAnalytics)
# Cumulative returns and drawdowns
par(cex.lab=.8) # should set these parameters once at the top
op <- par(no.readonly = TRUE)
layout(matrix(c(1, 2)), height = c(2, 1.3), width = 1)
par(mar = c(1, 4, 4, 2))
chart.CumReturns(edhec.R, main = "EDHEC Index Returns", xaxis = FALSE, legend.loc = "topleft", ylab = "Cumulative Return", colorset= rainbow8equal, ylog=TRUE, wealth.index=TRUE, cex.legend=.7, cex.axis=.6, cex.lab=.7)
par(mar = c(5, 4, 0, 2))
chart.Drawdown(edhec.R, main = "", ylab = "Drawdown", colorset = rainbow8equal, cex.axis=.6, cex.lab=.7)
par(op)

Cumulative returns since inception


Here are the monthly returns of these series with estimates of VaR and ETL. Note that the axes are scaled the same for each series, which makes certain attributes easier to compare, visually.

# Generate charts of EDHEC index returns with ETL and VaR through time
par(mar=c(3, 4, 0, 2) + 0.1) #c(bottom, left, top, right)
charts.BarVaR(edhec.R, p=(1-1/12), gap=36, main="", show.greenredbars=TRUE, 
              methods=c("ModifiedES", "ModifiedVaR"), show.endvalue=TRUE, 
              colorset=rep("Black",7), ylim=c(-.1,.15))
par(op)

Monthly returns and estimated risk


Similarly, here is a view that compares the distributions of each. This graphic is a bit more complicated, but I think I like it well enough to consider functionalizing it.

op <- par(no.readonly = TRUE)
# c(bottom, left, top, right)
par(oma = c(5,0,2,1), mar=c(0,0,0,3))
layout(matrix(1:28, ncol=4, byrow=TRUE), widths=rep(c(.6,1,1,1),7))
# layout.show(n=21)
chart.mins=min(edhec.R)
chart.maxs=max(edhec.R)
row.names = sapply(colnames(edhec.R), function(x) paste(strwrap(x,10), collapse = "\n"), USE.NAMES=FALSE)
for(i in 1:7){
  if(i==7){
    plot.new()
    text(x=1, y=0.5, adj=c(1,0.5), labels=row.names[i], cex=1.1)
    chart.Histogram(edhec.R[,i], main="", xlim=c(chart.mins, chart.maxs), breaks=seq(-0.15,0.10, by=0.01), show.outliers=TRUE, methods=c("add.normal"))
    abline(v=0, col="darkgray", lty=2)
    chart.QQPlot(edhec.R[,i], main="", pch="*", envelope=0.95, col=c(1,"#005AFF"), ylim=c(chart.mins, chart.maxs))
    abline(v=0, col="darkgray", lty=2)
    chart.ECDF(edhec.R[,i], main="", xlim=c(chart.mins, chart.maxs), lwd=2)
    abline(v=0, col="darkgray", lty=2)
  }
  else{
    plot.new()
    text(x=1, y=0.5, adj=c(1,0.5), labels=row.names[i], cex=1.1)
    chart.Histogram(edhec.R[,i], main="", xlim=c(chart.mins, chart.maxs), breaks=seq(-0.15,0.10, by=0.01), xaxis=FALSE, yaxis=FALSE, show.outliers=TRUE, methods=c("add.normal"))
    abline(v=0, col="darkgray", lty=2)
    chart.QQPlot(edhec.R[,i], main="", xaxis=FALSE, yaxis=FALSE, pch="*", envelope=0.95, col=c(1,"#005AFF"), ylim=c(chart.mins, chart.maxs))
    abline(v=0, col="darkgray", lty=2)
    chart.ECDF(edhec.R[,i], main="", xlim=c(chart.mins, chart.maxs), xaxis=FALSE, yaxis=FALSE, lwd=2)
    abline(v=0, col="darkgray", lty=2)
  }
}
par(op)

About these ads

3 thoughts on “Download and parse EDHEC hedge fund indexes

  1. This is great stuff and I’m trying to replicate it, but I can’t seem to download PortfolioAnalytics. Something about “failed to build”. Can you direct me as to how to do this? Many thanks, Sean

  2. Hi Peter,
    have a look at a fully automated way how to do it:

    library(RCurl)
    loginurl = “http://www.edhec-risk.com/login_form”
    dataurl = “http://www.edhec-risk.com/indexes/pure_style/data/table/history.csv”
    pars=list(
    “__ac_name”=”yourname”,
    “__ac_password”=”yourpassword”
    )
    agent=”Mozilla/5.0″ #or whatever
    curl = getCurlHandle()
    curlSetOpt(cookiejar=”cookies.txt”, useragent = agent, followlocation = TRUE, curl=curl)
    html=postForm(loginurl, .params = pars, curl=curl)
    html=getURLContent(dataurl, curl=curl)

    rm(curl)

    out <- read.csv(textConnection(html), sep=";", check.names=F)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: