Simulated orders with IB market data

Discussion in 'Data Sets and Feeds' started by mikesmithv, Aug 8, 2007.

  1. IB's market data stream contains ask, bid and last price plus volume info so there should enough data to make backtesting a good approximations of real trading but there are some pitfalls. Rather than go over my mistakes I'll jump right to my proposed new system. I've lost count of the rewrites!

    Market buy orders watch the price of the last trade and trigger when a trade occurs at the ask price, then uses that price for the simulated buy price. The idea here is that trades that occur at the ask are market buys which is what I want to mimic. Any lower price might be the result of a market sell which would result in over optimistic backtesting results. I would rather error on the side of "pessimistic" during system development.

    Market sell orders do the same as above but watch for a trade that occurs at the bid and uses that price.

    Limit buys orders are like market orders except they trigger when a trade occurs at the ask price AND that price is at the limit price or greater.

    Limit sell orders are the same but use the bid instead of ask and watch for a trade that is equal or lower than the limit price.

    The final thing (and the hardest) is to come up with a slippage factor that depends on the strategy, liquidity, position sizes and more. A trend-following strategy that jumps in with entries during a bullish frenzy with market orders would have a very different slippage factor than a strategy that waits for a pull-back using limit orders, for example.

    I think I'll wrap it here and see if anyone has any interest in this or if I am blabbering to no one. In a nutshell, I believe that improvements could include "smart" slippage factor that takes into account trades on either side of market orders to determine the likelihood of a fill, and for limit orders estimate where my order would be in the queue and let that number of trades pass by. And most important (for days like today) to notice when things are screwy and just step aside!

  2. GTG


    That sounds like a good idea. In the past, I haven't bothered to even try to simulate limit orders. I'll definately be adding this to my toolkit for a quick-and-dirty limit order simulation.
  3. With limit orders the question is would you really have been filled at that price. That depends on how many were before you in the queue when you placed your order. As I described it the simulator would always give you a fill even if there was only one trade at that price. A better approach would be to see if the market traded through that price. If so, you got your fill for sure. If not then there is some percent chance you would not have been filled. Calculating that percent chance is the trick.

  4. maxpi


    maybe if only the bid or ask went through your price would be best.
  5. Are you saying I only look at bid/ask crossing my limit price without taking into account the price and size of actual trades? That might work OK for ES during RTH but I'm looking for a more general set of rules (trading multiple markets & timeframes). For example while ES trades at ask and bid 99% of the time GOOG only trades there slightly over 50% of the time, the rest of the time the price is somewhere between ask and bid.

    I'm getting these statistics from a summary I did of Friday's day session and pasted into Excel. It show the columns in the following order: symbol, date, the percentage of actual trades that occurred above the current ask price, at the current ask price, between the ask and bid, at the current bid price, below the current bid, the average spread in ticks, crossed trades (CT) percent (the percent of total trades that occurred when bid/ask were crossed) and the same number but the actual trade count instead of % of trades.


    The IWM numbers were the most surprising so I verified the figures manually looking at time & sales. Around 12:07 EST Friday (8/10/2007) was the largest reverse spread of 105 ticks. The ask was at $78.21 and the bid was at $79.26, and there were so many of these Friday that it cause the average spread to be a negative number!

    The futures looked great with no crossed ask/bid but that was from one exchange, so I think my problem is using IB's SMART designation for the exchange (for equities). SMART is great for trading but not so great for quotes I think. It appears that SMART mixes together the ask/bid from several sources so it might be better to pick the largest exchange and go with that. If I want to buy 500 shares of IBM at ask on NYSE at $112.50 do I really care that there are 2 shares not moving on the Billy Bob exchange at $112.39 in Arkansas? :)

    Monday I will try specifying AMEX instead of SMART for IWM and I suspect I will get better results. If these way-off bid/asks from these other sources are tradeable maybe there is a strategy there!
  6. Here are some more results since my last post focusing on IWM. Rather than using SMART for the exchange I monitored each exchange individually. Here are the results for Thursday of last week which was a particularly bad day for crossed ask/bid:


    So it appears that ISLAND is the best market data source for IWM on IB. The ask/bid was never crossed and it had the best average spread. When another exchange had a better bid/ask most often it was not tradeable. For example, from 10:56:11 EST to 11:10:15 EST ISLAND had a worse ask price then CHX, but for that entire 14 minutes that was the ONLY ask price on CHX.

    So the moral of the story seems to be to use the most active exchange for quotes on IB instead of SMART. Given the complaints about IB's crossed ask/bid lately this might be good advise for non-ATS traders as well.
  7. maxpi


    Stocks are just too complicated. The simple answer is to trade the futures. In Frosty's thread it came to light that you can game the IB simulated account. I wouldn't use that for much.
  8. I agree. I am moving to futures. It might be nice to test what effect the underlying index or stock price movement has in relation to a future. Uncrossed asks and bids might come in handy for that but for simulating trades I think I'll tune it for just futures, at least for now.
  9. Tums


    The IB stream has all the data, but most charting software only collect the trade price.
    i.e. only the Last price is available from the local database for backtesting.
  10. Unlike most systems I am downloading ALL the data including ask/bid. This is for an ATS I am writing from the ground up, I probably should have been more clear in my first post - sorry. This makes it possible to develop strategies that are more "tape reading" oriented, not based on watching bars go by and making decisions at the end of bars based on RSI, MACD or whatever.

    My trading systems based on bar data have had 3 main disadvantages. (1) If a significant high and a significant low happened within the same bar there was no way for my ATS to know which came first. Backtesting was impossible, was my stop loss hit first or my profit target? (2) I had to wait for the end of the bar to make my decision, quite often that was too late. And finally (3) my strategies were limited. I am testing a variety of strategies now not possible before, volume bars (ala ProfLogic), momentum strategies with variable sized bars, etc - all constructed from market data.

    So that's why I'm sitting here watching ticks go by. I have not found any holy grail strategies yet but I've just begun. FYI, it was much MUCH harder than I imagined making this transition.
    #10     Aug 25, 2007