Backtesting with Interactive Brokers

Discussion in 'Automated Trading' started by kramer65, Jul 14, 2011.

  1. kramer65



    I've started trading with Interactive Brokers a while ago and I've recently had my algo being developed into a Java program which can now work with the TWS Java API.

    Since I would like to be on the safe side though, I want to backtest my algo. To my surprise however, there doesn't seem to be a way to backtest my strategy with the TWS.

    Does anybody know of a way that I can backtest my algo written for the IB Java API?

    Any tips or hints are welcome!
  2. You have to write your own code to backtest, or use some third party tool.
  3. LeeD


    Proper backtesting requires substantial amount of historical data and the history you can get from IB is very limited. So, it would be misleading to provide a backtesting tool in TWS when there is not enough price history for any backtest to be conclusive.

    kramer65, on what instruments is your strategy aimed to work?
  4. It seems very odd that you claim to have an algo without any backtests. Seems like that may not be true, unless you have done backtests, you won't get any data that will be large enough to run your algo from IB.
  5. One program that works well with TWS is AmiBroker. It has huge programming capabilities. The shortest time intervals you can get with AB/TWS is 15s. To have enough data for backtesting, you can login before 4:00 pm EST for several days and you will have the data stored in AB. You can set up AB to download session data only or round the clock data. Then you can test your system in AB or send the data to a spreadsheet using "AddColumn".
  6. Bob111

    Bob111 write the algo, you trade with IB, but you just realize that IB is not a TradeStation? :p
    then write another application to download historical data from IB (you are going to get what you paying for it) and then another application to backtest. meanwhile you can test whatever on IB's paper account(not demo). but depends on strategy,time frame,frequency- the difference can be huge between paper and real trading.
  7. LeeD


    You make a good point.

    However, I would hesitate to start a flame war against kramer65.

    First, there are a few accomplished discretionary traders who believe they can communicate their experience to a developer so that the trading strategy comes our ready without a need for backtest.

    Second, a few institutional market-makers think no backtesting is necessary as long as they can manually increase bid-offer spread whenever the strategy trading solely aginst clients stops making money.

    On the bottom line, kramer65 is more likely gullible than dishonest.

    No offence but this is bullshit. Interative Brokers don't give you any "tick" data and you can download "1-minute" data for only a month or two back. Note that IB don't provide timestamp on their market data. So, minute bars you see based on real-time data from IB will be different from historical minute bars downloaded from IB for the same time period.

    AmiBroker is a great backtesting tool on its own. In fact, the last time I checked it provided the fastest backtest I had seen by an order of magnitude.

    However, it is totally misleading to claim that AmiBroker can get better (or more) data from Interactive Brokers than other charting tools.
    I guess the point of this rant is IB doesn't provide tick price history and the prices IB provides in real time are not suitable for reconstruction of 1-minute bars.

    If you trade on, say, 5-minute time frame, all of this will have hardly any impact.
  8. Eight


    I would sidestep IB's data, they throttle it if you try to get too much, it's only available down to 30 second bars if it's historical and it's sent in snapshot packets in realtime... excellent data is not expensive at all and available from several sources.

    To backtest very thoroughly I'd use OpenQuant, it's designed from the ground up to be a backtesting environment. When you finish testing it will trade your strategy via IB's API.
  9. Bob111


    LD-we can only guess,cause OP did not provide any details. time frame,frequency,type of security..dunno how to put in in English right(cause it's not my native language) but..when you come up with such vague question w\o any details-most likely you would receive similar responds
  10. IB's data is available a year back and is available in 1 second, 5 second and 15 second bars (ohlc). It's obviously also available in longer timeframes.

    It is correct that they throttle the throughput and it'll take quite a while to build a representative backtesting database.

    PM me what type of stocks you trade. I've been building my database for several years, I have about 300 highly liquid symbols in 15 second bars in a database.
    #10     Jul 15, 2011