[R-SIG-Finance] Bloomberg historical data requests via rcom
Alex Bird
sunduck at gmail.com
Wed Oct 27 17:40:09 CEST 2010
Hello there,
I have encountered a problem trying to retrieve some historical
piece of data from bloomberg using rcom. Namely if I am trying to do
any requests without specifying start/end datetimes into the bloomberg
functions like this one
conn<-comCreateObject("Bloomberg.Data.1")
comGetProperty(conn,"BLPSubscribe",Security="SPX Index",Fields=c("TODAY_DT"))
I get "10/27/2010" as a result. But if I want to get a timeseries as
of some date like the following one
comGetProperty(conn,"BLPGetHistoricalData",Security="SPX
Index",Fields=c("TODAY_DT"),StartDate=startdate)
I get NULL as a result. I tried to specify dates and datetimes in
different formats (chron,POSIXct,YYYYMMDD,etc.), including the one
used to convert datetime from chron to COM format in the
RBloomberg_0.1-11 (i.e. the current date 2010-10-27 for example
becomes 40452, function for doing that can be found below). Details of
my R are
> sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United
States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] chron_2.3-38 rcom_2.2-3.1 rscproxy_1.3-1
>
and I use the latest statconnDCOM3.1-2B6.
I tried to do the same request via RDCOMClient package. Details of
that request are
> require(RDCOMClient)
> require(chron)
>
> as.COMDate.chron <- function(x, date1904 = FALSE){
+ orig0 <- attr(x, "origin")
+ orig1 <- as.Date(ISOdate(orig0[3], orig0[1], orig0[2]))
+ if (date1904){
+ dif <- orig1 - as.Date("1903-12-31") + 1
+ }else{
+ dif <- orig1 - as.Date("1900-01-01") + 2
+ }
+ y <- as.numeric(x) + as.numeric(dif)
+ class(y) <- "COMDate"
+ y
+ }
>
> conn<-COMCreate("Bloomberg.Data.1")
> startdate=as.COMDate.chron(as.chron('2010-10-27'))
> startdate
[1] 40478
attr(,"class")
[1] "COMDate"
> conn$BLPSubscribe(Security="SPX Index",Fields="TODAY_DT")
[[1]]
[[1]][[1]]
[1] "10/27/2010"
> conn$BLPGetHistoricalData(Security="SPX Index",Fields="PX_OPEN",StartDate=startdate)
[[1]]
[[1]][[1]]
[[1]][[1]][[1]]
An object of class "COMDate"
[1] 40478
[[2]]
[[2]][[1]]
[[2]][[1]][[1]]
[1] 1183.84
>
> sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United
States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] chron_2.3-38 RDCOMClient_0.92-0.1
>
And the question is what can be wrong with the datetime format or my R?
Thanks in advance!
Kind regards,
Alex
More information about the R-SIG-Finance
mailing list