IB Backtesting for newbie.

Discussion in 'Automated Trading' started by hlwlkkax, Oct 10, 2016.

  1. hlwlkkax

    hlwlkkax

    Background:
    1. I have years of programming and machine learning under my belt. I prefer coding in python but can make the change to C if necessary.

    2. I have years of historical data(down to millisecond) via my school's subscription to WRDS.

    3. I wrote an "trading algorithms" using python and sql data. The algorithm had a positive return consistently for 2 yrs. of backtesting. I created a control environment. Essentially, I wrote a program that would call my SQL database, look for patterns, and execute based on them. To mimic reality I had a half a minute execution time delay.

    What I want to do:

    I want to execute my algorithm using the IB API. I wrote my algorithm, this time "executing" using the IB API. For example when a pattern is detected I would place a "stop order" with the IB API. all was going good, until I decided to test my code with historical data.

    From my understanding I cannot upload my own data into TWS and run my code right? If so can someone direct me to links to do so?

    If not, how can I backtest my code. To make sure it is doing what its suppose to do? and in future to improve it? Do I have to used a 3rd party trade platform? if so which one(i want to trade stocks)? Assuming I have to use 3rd party, when I go live should I use my own code to connect to IB API or continue using 3rd party?

    Is it possible for me to do "live" testing using Ib API? In other words go live and make fake orders. for example, when I execute a "buy" order the IB API would let me know what my order price would had been if I were to execute the order without doing it?

    Any help would be much appreciate it.
     
  2. Here are a couple of links to help:

    a) use someone elses system. If you're trading equities the best is probably https://www.quantopian.com/ It's python.

    b) build your own

    This is my blog. I suggest you have a read through that. Everything I write is in python.

    Also yes you can use a paper trading account to test IB trading.

    GAT
     
  3. From my understanding I cannot upload my own data into TWS and run my code right? If so can someone direct me to links to do so?

    - Ib does not give you back testing software. You may use R, Python, quantopian, metatrader or any other software.

    Interactive brokers traders use two connections to test their algos: one it connects to the real account to receive market data and with the other you connect to a demo account. This way you can test your algorithm in real time.

    I have uploaded some videos in Youtube. In this one you can see how you can connect to two TWS (demo and real account) at the same time to test it.
     
  4. southall

    southall

    IB provide a sim account for testing. API works exactly the same as real account except fill prices are simulated.
     
  5. hlwlkkax

    hlwlkkax

    All of this are great answers, i will look into them and I'm sure I will post more questions.

    From experience is it better to trade directly with IB's API or should I go through a trade platform (e.g. ninjatrader, metatrader, etc...?)
     
  6. With your previous experience and skills I think direct API access makes more sense. Having said that I've never used a platform so I can't compare them directly.

    GAT
     
  7. I agree with GAT.

    It is faster.
     
  8. hlwlkkax

    hlwlkkax

    I agree with GAT, but I obviously want to run my code, test it and debug it. My understanding is that if I use IB I have to do it live right? The problem is this will be a side project(until I start making serious cash), so I'm not sure how I can test it other than taking days off work.
     
  9. As southall said IB provide a paper trading account... You still need to fund your real account (I think USD 10k) but then you can program your software to trade the paper account, not the real one. You'd still be liable for exchange fees (10-50$ a month) to get live data. Also, I haven't experienced it but I've heard people complain that the fills on the paper trading account are sometimes not accurate (e.g. slightly different to where a real fill would be). I'd suggest the Yahoo TWS API group for help getting started with the API.
     
  10. TD877

    TD877

    Unless I'm mistaken, doesn't IB allow you to follow 100 instruments in real time without data fees?
     
    #10     Nov 13, 2016