5
$\begingroup$

I am attempting to access 1 minute trade data for 50 securities using Bloomberg API (rblpapi). Following is the code I got from the CRAN:

con <- blpConnect() 
security<- "NIFTY Index" 
field<- "INDX_MEMBERS"sec<- bds( security, field) 
getBars("XYZ IS EQUITY", eventType = "TRADE", barInterval = 01, 
        startTime = Sys.time() - 1360 * 60 * 6, endTime = Sys.time(),
        options = NULL, verbose = FALSE, returnAs = getOption("blpType","matrix"), 
tz= Sys.getenv("TZ", unset = "UTC"))

I want to access all 50 securities without repeating my code. Is there a way to directly call a list of member securities of an index from Bloomberg and use it to access intraday data in one go. Also, when I input specific dates such as:

getBars("XYZ IS EQUITY", eventType = "TRADE", barInterval = 01,
    startTime = as.Date("2014-01-01 03:30:00"), endTime = as.Date(" 2014-02-04 09:30:00"),
    options = NULL, verbose = FALSE, returnAs = getOption("blpType",
                                                          "matrix"), tz = Sys.getenv("TZ", unset = "UTC"))

it shows:

Error: startTime and endTime must be Datetime objects

Thanks in advance.

$\endgroup$
  • $\begingroup$ From the As.date documentation (stat.ethz.ch/R-manual/R-devel/library/base/html/as.Date.html): "Arguments: x An object to be converted. format A character string. If not specified, it will try "%Y-%m-%d" then "%Y/%m/%d" on the first non-NA element, and give an error if neither works. Otherwise, the processing is via strptime" $\endgroup$ – lcrmorin Apr 18 '16 at 7:54
1
$\begingroup$

Briefly:

  1. Some functions simply are not vectorised. If you want to loop getBars() over a vector of symbols, write another wrapper doing the looping.

  2. As our documentation says: startTime: A Datetime object with the start time, defaults to one hour before current time (and ditto for endTime) you need to supply a DateTime object, and as.POSIXct() is one way of doing it. Sticking date and time into as.Date() is not.

$\endgroup$
  • $\begingroup$ I Will try to write the wrapper. $\endgroup$ – Polar Bear Apr 19 '16 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.