summaryrefslogtreecommitdiffstats
path: root/bandit.R
diff options
context:
space:
mode:
Diffstat (limited to 'bandit.R')
-rw-r--r--bandit.R45
1 files changed, 32 insertions, 13 deletions
diff --git a/bandit.R b/bandit.R
index 0d35758..1acb59a 100644
--- a/bandit.R
+++ b/bandit.R
@@ -31,7 +31,8 @@ N <- 1000000
W <- N
for(day in 1:length(returns[,1])){
r <- as.vector(exp(returns.subset[day,])-1)
- r[is.na(r)] <- 0 #NA means we don't know the vector that day, but next return will catch up
+ r[is.na(r)] <- 0 #NA means we don't have quotes that day, but next return
+ #will catch up
dN <- N*crossprod(w,r)
N <- N+dN
W <- c(W,N)
@@ -47,19 +48,37 @@ for(day in 1:length(returns[,1])){
W <- c(W,N*mean(R))
}
-indexchange <- read.table("IndexChange_500.csv",sep="\t",header=T,quote="")
+indexchange <- read.table("IndexChange_500.csv",sep="\t",header=T,quote="",
+ colClasses="character")
#cleanup tickers
attach(indexchange)
-Ticker.add <- sub('/', '-',Ticker.add)
-Ticker.add <- sub('.wi', '',Ticker.add,fixed=T)
-Ticker.add <- sub('wi', '',Ticker.add)
-Ticker.add <- sub('.', '-',Ticker.add,fixed=T)
-Ticker.del <- sub('/', '-',Ticker.del)
-Ticker.del <- sub('.wi', '',Ticker.del,fixed=T)
-Ticker.del <- sub('wi', '',Ticker.del)
-Ticker.del <- sub('.', '-',Ticker.del,fixed=T)
-Date <- as.Date(Date,format="%m/%d/%y")
-for( jour in Date){
-
+indexchange$Ticker.add <<- sub('/', '-',indexchange$Ticker.add)
+indexchange$Ticker.add <- sub('.wi', '',indexchange$Ticker.add,fixed=T)
+indexchange$Ticker.add <- sub('wi', '',indexchange$Ticker.add)
+indexchange$Ticker.add <- sub('.', '-',indexchange$Ticker.add,fixed=T)
+indexchange$Ticker.del <- sub('/', '-',indexchange$Ticker.del)
+indexchange$Ticker.del <- sub('.wi', '',indexchange$Ticker.del,fixed=T)
+indexchange$Ticker.del <- sub('wi', '',indexchange$Ticker.del)
+indexchange$Ticker.del <- sub('.', '-',indexchange$Ticker.del,fixed=T)
+
+#rollback sp500 changes
+sp500.historic <- sp500
+for( i in 1:100){
+ #Ticker.add empty means index is <500 for a while
+ if(indexchange$Ticker.add[i]!=""){
+ if(!is.na(match(indexchange$Ticker.add[i],sp500.historic$ticker))){
+ sp500.historic <-
+ sp500.historic[-match(indexchange$Ticker.add[i],sp500.historic$ticker),]
+ }else{
+ cat(paste("ticker",indexchange$Ticker.add[i],"not found\n"))
+ }
+ }
+ #add ticker that was removed
+ if(indexchange$Ticker.del[i]!=""){
+ sp500.historic <- rbind(sp500.historic,
+ c(indexchange$Company.Deletions[i],
+ indexchange$Ticker.del[i]))
+ }
+}
detach(indexchange)