Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
braverock
GitHub Repository: braverock/portfolioanalytics
Path: blob/master/sandbox/script.buildEDHEC.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
# Download the following file to the working directory:
11
# http://www.edhec-risk.com/indexes/pure_style/data/table/history.csv
12
### @TODO: Is there a way to download it directly? Maybe not, seems to require a login
13
x<-read.csv(file=download.file("http://www.edhec-risk.com/indexes/pure_style/data/table/history.csv"), sep=";", header=TRUE, check.names=FALSE)
14
#x=read.csv(file="history.csv", sep=";", header=TRUE, check.names=FALSE)
15
x.dates = as.Date(x[,1], format="%d/%m/%Y")
16
x.data = apply(x[,-1], MARGIN=2, FUN=function(x){as.numeric(sub("%","", x, fixed=TRUE))/100}) # get rid of percentage signs
17
edhec = xts(x.data, order.by=x.dates)
18
colnames(edhec)
19
20
# calculate a wealth index
21
edhec.idx = apply(edhec, MARGIN=2, FUN=function(x){cumprod(1 + na.omit(x))})
22
# identify quarters
23
edhec.Q.idx=edhec.idx[endpoints(edhec.idx, on="quarters"),]
24
# calculate quarterly returns
25
edhec.Q.R=ROC(edhec.Q.idx)
26
# trim the last data point, if needed
27
# dim(edhec.Q.R)
28
# edhec.Q.R=edhec.Q.R[-61,]
29
# reclass the object
30
edhec.Q.R=as.xts(edhec.Q.R)
31
# lm requires safe names
32
colnames(edhec.Q.R)=make.names(colnames(edhec))
33
34
35