[R-SIG-Finance] Pulling minute bar data with bar() function in Rbbg(RBloomberg) package in R

David Reiner David.Reiner at xrtrading.com
Mon Aug 19 15:27:36 CEST 2013


Sorry for the late reply - I was out for a few days.
(It's generally better to go to the list so you have more chances of getting a reply.)

I follow the last example under ?merge.xts to align my incomplete series:
just generate a sequence of date-times you want and merge the zero-width xts object with your other xts object.
You'll get NA's where there's no data, and you can leave them or use locf from zoo.
HTH,
-- David


-----Original Message-----
From: Alex Bennett [mailto:ppminers11 at yahoo.com] 
Sent: Wednesday, August 14, 2013 4:04 PM
To: David Reiner
Subject: Re: [SPAM] - [R-SIG-Finance] Pulling minute bar data with bar() function in Rbbg(RBloomberg) package in R - Email found in subject

Hi David,

Thank you so much for the help - this worked perfectly! 

Using the "isBizday()" function at the start of the for loop circumvents the 4th and stops the error I was getting. 

One more quick question regarding this: Right now the code only returns lines from minutes there was volume moved, and I am wondering if it is possible to add something (either code or a parameter) that will cause the bar() function to return a line for every minute instead of just minutes in which there were trades. For example, for a liquid name, like SPY, there will be 390 lines (one for every minute since there is volume moving every minute); however, for more illiquid names there could only be 100 lines returned because there are several minutes with no volume.  What I would like is for there to always be 390 lines returned, and, in the event there was no volume moved, have a zero on the line corresponding to those minutes. This would cause the "use" data frame to have 390*n rows. 

Ultimately I would like a column with a number, 1-390, corresponding to each minute bar for a given day, and I cannot think of a way to efficiently add this column without having 390 rows per day from the start. 

Does this make sense? Do you have any insights as to how to achieve this goal? 

Thanks for your help!

Best, 
Alex Bennett




On Aug 14, 2013, at 10:38 AM, David Reiner <David.Reiner at xrtrading.com> wrote:

> Alex,
> Sending your message in text instead of html will help you get an answer - see below for what we received.
> But, no, you can go back further, but you must omit holidays the way you are doing it, since the empty
> return from July 4 messes up your logic. The timeSequence function does take a FinCenter argument,
> which may help you.
> 
>> start.date <- localToUTC('2013-04-01 08:30') # I'm in Chicago
>> end.date <- localToUTC('2013-04-01 15:00')
>> raw=bar(conn,"GOOG US Equity","TRADE",start.date,end.date,"60")
>> head(raw)
>                                           time    open    high     low   close numEvents volume
> 2013-04-01T13:30:00.000 2013-04-01T13:30:00.000 795.010 801.800 793.250 801.380      3650 512342
> 2013-04-01T14:30:00.000 2013-04-01T14:30:00.000 801.380 801.380 796.600 798.850      2323 320520
> 2013-04-01T15:30:00.000 2013-04-01T15:30:00.000 798.940 800.980 798.063 798.414      1063 152294
> 2013-04-01T16:30:00.000 2013-04-01T16:30:00.000 798.450 801.350 798.070 800.777       815 119642
> 2013-04-01T17:30:00.000 2013-04-01T17:30:00.000 800.860 802.209 800.500 801.280      1061 145566
> 2013-04-01T18:30:00.000 2013-04-01T18:30:00.000 801.155 801.330 799.550 799.750      1299 185598
> 
> HTH,
> -- David Reiner
> PS:
> localToUTC <- function(x) {
>  if (class(x)[1] == "character") {
>    x <- as.POSIXct(x) # Assume strings are in the correct format
>  }
>  format(x, "%Y-%m-%d %H:%M:%OS3",tz="UTC")
> }
> 
> -----Original Message-----
> From: r-sig-finance-bounces at r-project.org [mailto:r-sig-finance-bounces at r-project.org] On Behalf Of Alex Bennett
> Sent: Tuesday, August 13, 2013 8:18 PM
> To: r-sig-finance at r-project.org
> Subject: [SPAM] - [R-SIG-Finance] Pulling minute bar data with bar() function in Rbbg(RBloomberg) package in R - Email found in subject
> 
> I am fairly new to the Rbbg package, so please excuse any ignorance on my part, however I am wondering if it is possible to pull more than ~25 days of minute bar data using the bar() function. I've found I can't pull more than 25 or 26 days worth of data and am wondering if I am doing something wrong, or if it is just not possible.
> Here is the code I am using:
> #install.packages("rJava")#install.packages("Rbbg", repos="http://r.findata.org")#install.packages("timeDate")library(rJava)library(Rbbg)library(timeDate)conn <-blpConnect()weekdays =timeSequence(from=(Sys.Date()-38),to =(Sys.Date()-1),by="day")[isWeekday(timeSequence(from=(Sys.Date()-38),to =(Sys.Date()-1),by="day"))]date_time=numeric()volume=numeric()for(i in1:length(weekdays)){start.date <-paste(weekdays[i],"13:30:00.000")end.date <-paste(weekdays[i],"20:00:00.000")raw=bar(conn,"GOOG US Equity","TRADE",start.date,end.date,"1")date_time=append(date_time,raw$time)volume=append(volume,raw$volume)}date.time <-data.frame(do.call('rbind',strsplit(as.character(date_time),'T',fixed=TRUE)))use=data.frame("date"=format(as.Date(date.time$X1),"%m/%d/%Y"),"time"=date.time$X2,"volume"=raw$volume)blpDisconnect(conn)
> This works fine and pulls data from the trading days in the past 3.5 weeks. Now, if I try to change the 38 to a greater number in the line weekdays = timeSequence(from = (Sys.Date()-38), to = (Sys.Date()-1), by = "day")[isWeekday(timeSequence(from = (Sys.Date()-38), to = (Sys.Date()-1), by = "day"))], I get the following error: Error in matrix.data[, 1] : subscript out of bounds when I try running the above script.
> Is it the case that the API can only pull about 3.5 weeks of minute bar data? Or am I doing something incorrect? Ideally, I would like to have at least 100 trading days worth of data.
> Thank you all for your help.
>        [[alternative HTML version deleted]]
> 
> 
> 
> This e-mail and any materials attached hereto, including, without limitation, all content hereof and thereof (collectively, "XR Content") are confidential and proprietary to XR Trading, LLC ("XR") and/or its affiliates, and are protected by intellectual property laws.  Without the prior written consent of XR, the XR Content may not (i) be disclosed to any third party or (ii) be reproduced or otherwise used by anyone other than current employees of XR or its affiliates, on behalf of XR or its affiliates.
> 
> THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.



More information about the R-SIG-Finance mailing list