Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getMultipleTicks(..., returnAs="xts") is broken #76

Closed
eddelbuettel opened this issue Sep 30, 2015 · 11 comments
Closed

getMultipleTicks(..., returnAs="xts") is broken #76

eddelbuettel opened this issue Sep 30, 2015 · 11 comments
Labels

Comments

@eddelbuettel
Copy link
Member

We rely on xts to merge the bid, ask, trade, ... vectors but the timestamps are not unique. So the merged xts is not valid.

@armstrtw
Copy link
Contributor

can we do this on the c++ side. I have some code around for this type of thing.

@eddelbuettel
Copy link
Member Author

Awesome sauce! Below is a recent snippet going straight to the c++ side. Also note the verbose switch I already had there :)

R> res <- Rblpapi:::getTicks_Impl(con,  "ES1 Index", c("TRADE", "BID", "ASK"), "2015-09-30 15:00:00", "2015-09-30 15:00:10", TRUE)
Sending Request: IntradayTickRequest = { security = "ES1 Index" eventTypes[] = { TRADE BID ASK } startDateTime = 2015-09-30 endDateTime = 2015-09-30 }
Processing Response
Response contains 46 items
Time        Type        Value       Size        Condition Code
9/30/2015 0:0       BID     1875.500000     30      
9/30/2015 0:0       BID     1875.500000     29      
9/30/2015 0:0       BID     1875.500000     30      
9/30/2015 0:0       BID     1875.500000     31      
9/30/2015 0:0       ASK     1875.750000     14      
9/30/2015 0:0       BID     1875.500000     32      
9/30/2015 0:0       BID     1875.500000     34      
9/30/2015 0:0       BID     1875.500000     32      

@armstrtw
Copy link
Contributor

huh?

@eddelbuettel
Copy link
Member Author

That is the data we get. I also split this into vectors which I then merge but that merge assumes unique timestamps.

Also in the example above timestamps miss the 'T' required: 2015-09-30T15:00:00, not '2015-09 30 15:00:00'.

@eddelbuettel
Copy link
Member Author

So what were you thinking of @armstrtw ?

@armstrtw
Copy link
Contributor

if you have something working, that's great. I haven't even looked at that function yet.

I don't know what you ended up doing on c++ side, but I historically have just used some stl stuff to merge and cbind.

@eddelbuettel
Copy link
Member Author

If you re-read the tread, and look at the two (short) files involved, things should become clearer. And I did not say or mean to imply that I have something working. I demonstrated what get from Bbg: a mix of rows.

@armstrtw
Copy link
Contributor

It's month end. I'll follow up on this tomorrow.

@joshuaulrich
Copy link

How about this:

# data for reproducible example
set.seed(21)
N <- 40
eventType <- c("BID","ASK","TRADE")
res <- data.frame(
  time=.POSIXct(rep(0:1,each=N/2), tz="UTC"),
  type=sample(eventType, N, TRUE, c(40,40,20)),
  value=runif(N, 21, 22), size=sample(N)*100)
# end

## Make timestamps unique
res$time <- make.index.unique(res$time, eps=1e-5)
## Subset into blocks for each event type, creating xts
rl <- lapply(eventType,
         function(s) {
             x <- subset(res, res$type==s)
             colnames(x)[3] <- tolower(s)
             colnames(x)[4] <- paste0(tolower(s), "sz")
             xts::xts(x[,3:4], order.by=x[,1])
         })
x <- do.call(merge, rl)
options(digits.secs=6)  # make unique index values visible

@eddelbuettel
Copy link
Member Author

I thought about uniquefying the timestamps too. But I am afraid that we may have more than 1e5 at the same time stamps. Also, maybe we should trunc() the timestamp after the merge to not supply false timestamps.

@eddelbuettel
Copy link
Member Author

The suggestion works -- I added two lines to make column unique as you suggested, and later trunc() the time back down. That should do it. More testing tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants