summaryrefslogtreecommitdiffstats
path: root/getBloombergData.R
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2011-10-14 20:01:02 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2011-10-14 20:01:02 -0400
commite8a5cfea058c145e751fcee27daace0c991d1606 (patch)
tree8ecd611073ee1e355f24833b014b95e11482120e /getBloombergData.R
parent2c2b03d3ade43107a0776468bcf97468a7b81d58 (diff)
downloadbandit-e8a5cfea058c145e751fcee27daace0c991d1606.tar.gz
More bug fixes
should be almost there!
Diffstat (limited to 'getBloombergData.R')
-rw-r--r--getBloombergData.R40
1 files changed, 22 insertions, 18 deletions
diff --git a/getBloombergData.R b/getBloombergData.R
index 302aac9..ccb0b41 100644
--- a/getBloombergData.R
+++ b/getBloombergData.R
@@ -1,23 +1,22 @@
-getBloombergData <- function(conn,ticker,start,date){
+getBloombergData <- function(conn,ticker,start.date){
+ require(TTR)
ohlc <- bdh(conn,paste(ticker,"Equity"),c("PX_OPEN","PX_HIGH","PX_LOW","PX_LAST","VOLUME"),start.date,dates.as.row.names=F)
colnames(ohlc) <- c("Date","Open","High","Low","Close","Volume")
ohlc <- xts(ohlc[,-1],as.Date(ohlc$Date))
#split information
- override_field="DVD_START_DT" #DVD_END_DT
- override_values=format(start,"%Y%M%d")
- spl <- bds(conn,paste(ticker,"Equity"),c("EQY_DVD_ADJUST_FACT"),override_field,override_values)
- # bds returns NULL if there is no data.
- #Adjustment Factor Operator Type
- # 1 = div
- # 2 = mul
- # 3 = add
- # 4 = sub
- #Adjustment Factor Flag
- # 1 = prices only
- # 2 = volumes only
- # 3 = prices and volume
+ spl <- bds(conn,paste(ticker,"Equity"),c("EQY_DVD_ADJUST_FACT"))
+ # bds returns NULL if there is no data.
+ #Adjustment Factor Operator Type
+ # 1 = div
+ # 2 = mul
+ # 3 = add
+ # 4 = sub
+ #Adjustment Factor Flag
+ # 1 = prices only
+ # 2 = volumes only
+ # 3 = prices and volume
- # can't handle 3 or 4 yet
+ # can't handle 3 or 4 yet
if(NROW(spl)!=0){
if (NROW(spl[spl[,"Adjustment Factor Operator Type"]%in% c(3,4),])>0){
stop("case not handled")
@@ -33,16 +32,21 @@ getBloombergData <- function(conn,ticker,start,date){
}
}
#div information
- div <- bds(conn,paste(ticker,"Equity"),c("DVD_HIST"),override_fields,override <- values)
+ #we need to override the end date as well cause the Ex-Date might be in the
+ #future
+ override_fields <- c("DVD_START_DT", "DVD_END_DT")
+ override_values <- c(format(start.date,"%Y%m%d"),format(Sys.Date(),"%Y%m%d"))
+ div <- bds(conn,paste(ticker,"Equity"),c("DVD_HIST"),override_fields,override_values)
if(NROW(div)!=0){
div <- xts(div$"Dividend Amount",as.Date(div$"Ex-Date"))
}
if(is.null(div)&&is.null(spl)){
divspl <- NULL
}else if(is.null(div)){
- divspl <- merge(NA,spl,all=T)
+ #need to use merge.xts, otherwise spl is cast to a numeric
+ divspl <- merge.xts(NA,spl,all=T)
}else if(is.null(spl)){
- divspl <- merge(div,NA,all=T)
+ divspl <- merge.xts(div,NA,all=T)
}else{
divspl <- merge(div,spl,all=T)
}