diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2011-10-09 17:21:01 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2011-10-09 17:21:01 -0400 |
| commit | 146e3e1b1276c71d2467202b9aa85fbdc127d6eb (patch) | |
| tree | 73438b614da7c532e67769e577911052f3a4aaef /bandit.R | |
| parent | b9d26539cb63226365722bc4b535416dc2c08e8d (diff) | |
| download | bandit-146e3e1b1276c71d2467202b9aa85fbdc127d6eb.tar.gz | |
Progress on getting the rolled back sp500 index
Diffstat (limited to 'bandit.R')
| -rw-r--r-- | bandit.R | 45 |
1 files changed, 32 insertions, 13 deletions
@@ -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) |
