API Automated trading with IB's TWS : ASK/BID freeze - Negative Spread

Discussion in 'Automated Trading' started by tommaso, Mar 3, 2008.

  1. tommaso

    tommaso

    Hi, hello I just registered here. First of all, greetings to anyone.

    I have been spending the last few months programming and refining a windows application for automated trading, via API, using the Interactive Brokers TWS. [So far only tested by using the Demo and "Paper Account".]

    Now that the program seems to begin yield consistent positive results I noticed that using the "Paper Account" (simulated trading with live data), very often it happens that either the BID or the ASK freeze. Similarly, often the spread become negative and remains negative for very long time, or until TWS is restarted.

    Did anybody ever experience that, or has information about this behaviour?

    Thanks a lot,

    Tommaso
     
  2. MR.NBBO

    MR.NBBO

    It's a papertrader error.

    It's a pain, but just re-launch TWS--and it'll work ok for 20-30 minutes. I think much depends on the security your testing.

    It's good for debugging, but not true result testing.
     
  3. tommaso

    tommaso

    Thank you mikesmithv and MR.NBBO, it's good to hear that I should not expect this behaviour in "real" trading.

    Anyway, I have been playing with these waves for quite a while now examining every move after each order, and somehow I got the "impression" this is not really a bug of the platform.

    My hypothesis (I do not know if it's foolish), is that it is due to the fact that in paper trading we more directly face against a market making program.

    In the very short time, there seem to be nothing of really random in the behaviour of the program and it seems to me that it "precisely" react to each order. Clearly there is some randomness added, but also I can see there are neat regularities.

    For instance, I can assure, and I do not think I have ever seen a counterexample in thousand trials, that for instance after a buy, there is always an immediate price decrease and viceversa (I am talking about seconds).

    Also another peculiarity I noticed that this defensive mechanism does not work on rapid order inversion when a "trend" suddenly invertes. And actually relaying on that seems more accurate than many signals. I have never seen a loss playing on such inversion.

    If one think about it, there may be a technical reason. Of one would enforce the defensive behaviour in quick inversion, then the program could in theory begin oscillate wildly if a trading program keeps inverting orders. And that kind of behaviour could not be easily justified to the market.

    So am not sure of what I say, I am only making hipothesis based on long observations and based that I am getting some good results by understanding these behaviors.

    Another point is that these phenomen of BID or ASK freeze and spread invert seems to appear much more frequently when one has good gains. So it seems to me it's part of an attempt of "defense" on the part of the market making program.

    My idea, and tell me if its paranoic, is that on the paper trading we can see this "extreme" behavior because we are playing directly against the program and there is not a "market" that somehow moderates the reaction of the program to our bets.

    I would like to hear you opinions about these ideas. I am just trying to explain observation or facts without preconceived ideas. (But I may be wrong as well :- )

    Another point is, who provides the market making program? And is it conceivable to assume that the basic "reaction" strategy of these programs are similar? In the very short period, understanding how the program behaves and reacts, can make a difference.

    Tommaso
     
  4. bespoke

    bespoke

    Sell that bid and hit that ask with as many shares as possible! It's an arb! Ok.. maybe not..

    My API feed shows negative spreads (crosses) sometimes. At first I thought they were errors, but investigating them further I found that they seemed to happen at R/S levels and it seemed to be someone marketing a lot of shares up or down, probably with a stop order. So I tried auto-executing the trades with 100 shares on both sides to see if I could sell the bid and hit the ask and take the spread. I'd say the executions were fast enough 1/5th of the time to take the spread (usually 1-5 cents, sometimes up to 500 shares), but most of the time you would only get one of side of the trade and you'd have to market out. So either my execution was too slow, the display of the cross was a delayed, or there weren't any shares available. So in the end I just ended up paying a lot of fees.... it was a fun experiment though

    edit: when you say negative spread, do you mean a cross in the bid/ask prices?
     
  5. tommaso

    tommaso

    Hello

    >when you say negative spread, do you mean a cross in the bid/ask prices?

    Yes but not only that. The BID remains stationary over the ask or viceversa. For long time.

    From my experience (so far) there is no way to take advantage from that situation. And the reason is that, I believe (but I am not sure), it's a defensive device.

    In fact I have observed that, if you have an open position, it's often an attempt to make you believe you are going to lose a lot of money. But I observed also that if you wait long enough and do not panic it always returns to a profit.

    But never open a position in that condition.

    I have to do more research on that but that's my prescription so far.

    Anyway if that cannot happen in real trading, there is not much to be concernerd about. However it can give some useful insight on the deceiving behaviour of the market making programs.

    It seems to me that those programs are highly optimized to beat any naive opponent and if you play directly against them you have to be prepared to fight hard and very smart.

    In several week I have passed from enormous losses to nice gains per process [TWS seems to allow max 8 process on an account] just through continuous improvement of the logic. But the program is slowly becoming a monster. [And I still fell I am at the beginning of the story.]

    From my experience (so far) various ingredients are fundamental:

    - very smart entering in a position, when some conditions are met
    - never *ever* bound the profit (never use take profit) but use a very adaptive logic
    - do have a disclipline in limiting the drawdown, but not mechanically, in a very flexible way
    - Accurate study of the waves to avoid all the traps and the games played by the market making program.

    My current opinion, based on hundreds of simulations, is that no strategy with *fixed* take profit will ever compete in the long run with the drawdown. Ruin will always occur in the long run.

    Let me know if anyone has advice or more opinion for constructive discussion.


    Tommaso
     
  6. bespoke

    bespoke

    Well, I believe the cross is due to a very short momentary lag from one of the ECNs. These crosses only appear for a fraction of a second when you're trading live. Generally they happen a few times a day per highly active stock. I don't believe it's because of any market making. I don't know enough about how the systems work so that I can give you a good answer.

    I only observed this on NYSE stocks. Anyways, I don't think it's something you can take advantage of, nor does it really have any meaning or value. Sometimes you can take both sides using Fill or Kill and Immediate or Cancel orders, but from my live testing with real money it certainly wasn't worth it.

    BTW, my API feed isn't IB. I just wanted to talk about hitting those crosses.

    As for your system design endeavors, I wish you the best of luck.
     
  7. Tommaso,

    Are you using SMART for downloading market data? If so try using ISLAND or some other high volume ECN instead. That might also cure the freeze you are seeing. I was having problems with "negative spreads" as well and found that SMART was reporting bid and ask prices as the "best" price which were actually old & stale prices from low volume ECN's. The real ask/bid had long since moved away from that price but since the volume is so low on those dead ECN's no other ask or bid comes along to move that price and the SMART logic continues to report it. I am not having those freezes and maybe it's because I'm not using SMART.

    The bad news is that great strategy you have may not work so well since it is based on bogus prices. That's what happened to me anyway.
     
  8. tommaso

    tommaso

    Hello mikesmithv

    thanks a lot for the suggestion I will try that.

    Actually, I think I did several test by using ISLAND, but to be frank I do not remember if the problem also appeared in that case, because I was more concerned about other implementation aspects. I am afraid it also appeared in that case . I will try again and let you know.


    >The bad news is that great strategy you have may not work so well since it is based on bogus prices. That's what happened to me anyway.

    Yes it is possible. Actually this process of implementing a trader robot, I must admit, is quite painful and complicate even for me (who have written tons of code on other areas). And even when we get some result, as you rightly note, one is not even sure it will perform the same way on the "real" data.

    Another thing I am wondering, is about the Market Making program. I guess that when playing with the paper account we are actually using the one provided by IB, and its behavior could be different from what we find when playing with real market.

    Is this right ? Or I am saying something meaningless ?

    I am experiencing and feeling a very hostile behaviour from the program which handles the orders issued by my robot. I think that If instead the response where "neutral" and not a smartly programmed reaction to my moves, one could get much better results.

    Anyway, I guess I have to be wondering until I will be ready to try with the real account, and see what is like the real "reaction" of the "market" to the orders issued by the robot.

    What is your feeling about the "real" market reaction? Do you feel it's completely "neutral" respect to your orders?


    Tommaso

    [PS. sorry if I say some nonsense I do not know the inner workings of the markets. I am more a technologist and I am approaching the problem with statistical concepts and hard programming and observation]
     
  9. I happen to be working on this area right now so I will confirm this later, but it appears IB is watching the live data and when it sees a trade that matches your simulated trade it fills your order accordingly. So if you have a limit buy order for 1000 shares of AAPL at $123.00 it waits until an actual trade occurs at $123.00 and fills your order as if that was you. If large size trades are occurring then it is more likely your 1000 lot order will fill quickly, I'm not sure of the exact details yet. But I'm pretty sure the brutal market maker you see is the actual market because the trades correspond to real trades that are occurring.
     
    #10     Mar 5, 2008