Hi everyone,

I'm using the IBrokers package to get the implied volatility for options
from Interactive Brokers.

To seperate the implied volatility field from the data stream you get after
calling reqMktData(), I had to write a specific EventWrapper:

library(IBrokers)

implVWrapper <-
function(n=1) {
eW <- eWrapper(NULL)
#eW$assign.Data("data", vector(mode = "numeric", length = 2))

eW$tickOptionComputation <- function(curMsg, msg, timestamp, file, ...) {
        tickType = msg[3]
        msg <- as.numeric(msg)
         id <- as.numeric(msg[2])
value <- msg[4]
#file <- file[[id]]
         #data <- eW$get.Data("data")

if(tickType == 13 & value != -1) {     # 14 is MODEL_OPTION, -1 is ???
print(paste("id:", id, "implVol:", msg[4]))
v[id] <<- value
#cancelMktData(tws, id)
}

#eW$assign.Data("data", data)
        c(curMsg, msg)
}

return(eW)
}

Now I call the reqMktData() function with my special eventwrapper:

options = list(twsOption("AA    100320P00012000"), twsOption("AA
 100320C00014000")) # specify the options
v = vector(mode = "numeric", length = length(options))    # v will hold the
implied volatilities for the options
tws = twsConnect(clientId=1)
reqMktData(tws, options, eventWrapper=implVWrapper())

This all works as expected except that reqMktData() keeps on running until
it is stopped by the user (with the Esc key). What I would like is some way
to stop the function when both implied volatilities are "filled". How do I
do that?

Kind regards,

-Mark-

	[[alternative HTML version deleted]]

