Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
braverock
GitHub Repository: braverock/portfolioanalytics
Path: blob/master/sandbox/symposium2013/parse.EDHEC.R
1433 views
1
### Construct an xts object of EDHEC composite hedge fund style indexes
2
3
# Peter Carl
4
5
# Used for updating the edhec data object in PerformanceAnalytics
6
7
require(gdata)
8
require(xts)
9
10
11
### Constants
12
filename = "EDHEC-index-history.csv"
13
objectname = "edhec"
14
datadir = "./data"
15
cachedir = "./cache"
16
17
# Download the following file to the working directory:
18
# http://www.edhec-risk.com/indexes/pure_style/data/table/history.csv
19
### @TODO: Is there a way to download it directly? Maybe not, seems to require a login
20
21
### Read data from csv file
22
x=read.csv(file=paste(datadir,filename,sep="/"), sep=";", header=TRUE, check.names=FALSE)
23
x.dates = as.Date(x[,1], format="%d/%m/%Y")
24
x.data = apply(x[,-1], MARGIN=2, FUN=function(x){as.numeric(sub("%","", x, fixed=TRUE))/100}) # get rid of percentage signs
25
edhec = xts(x.data, order.by=x.dates)
26
27
### Add pretty columnnames as an xts attribute?
28
29
30
### Save data into cache
31
save(edhec, file=paste(cachedir, "/", objectname, ".RData", sep=""))
32