QTPy-Lib, a new algorithmic trading Python library

Discussion in 'App Development' started by ranpo, Aug 19, 2016.

  1. ranpo


    I wouldn't worry at all about minute level data as you're maxed at only 1380 records per day for futures and 390 records for stocks - so no issues there.

    As for ticks... Each tick record in the database takes up 54 bytes of data. An average Futures contract can get 250-300 ticks/day from IB. This checks out to ~300MB of storage requirements per futures contract per month (~80MB for stocks).

    By that calculation, you'll need about 10GB per month to store one month's worth of both minute and tick data for 30 symbols. Multiply that by the number of months you want to keep and that's the storage you'll need for market data storage. Multiply that again by ~2 and that's your server requirements :)
    #11     Nov 5, 2016
  2. joederp


    Straightforward reasoning there, thanks! However, in the case of tick data from a provider other than IB, seems the tick count will be much higher, esp in the case of a market like NYMEX Crude Oil futures.

    On a separate note, while researching the db side, a blog post concerning IB's API in a Docker image came up - have a look, might be of use to you in that area: http://ryankennedy.io/interactive-brokers-api-docker/
    Last edited: Nov 6, 2016
    #12     Nov 6, 2016
  3. ranpo


    If you're using a tick-by-tick data feed then you're going to need more disk space... IB sends aggregated ticks 3-5 times/second.

    Most people, however, don't really use/need tick data and should be find with second-level data. It may be a good idea to add an option to QTPyLib that tells it to store second-level instead of tick-level data in order to save space. What do you think?

    I haven't played with the Docker image you mentioned, but it looks like it should do the trick (though I'm not a huge fan of Docker myself)
    #13     Nov 6, 2016
  4. joederp


    Hmm, yeah for sake of space reduction the 1-sec bars could prove useful.

    Personally I haven't used Docker, just read about its benefits (and the opinions of those in the programming arena who see it as over-applied nowadays). Figured it's good to have options, so that package adds one to the periphery if the need arises.
    #14     Nov 6, 2016
    ranpo likes this.
  5. joederp


    Hey ranpo, looks like you're keeping a regular pace to the updates & improvements to QtPyLib - inspiring to see!

    Regarding SMS, have you messed with pygooglevoice at all? I tried a sample script as-modded from some code posted to stackexchange & a blog, but couldn't get it to fire. Would be cool if a free option like this could be integrated with a platform as powerful as yours.
    #15     Dec 16, 2016
  6. ranpo


    I'm not based in US and don't have Google voice here - so there's no way for me to develop and test such integration at this time... I've opted for Nexmo/Twilio due to their international coverage and very reasonable rates (I'm using Nexmo for almost a year now and I'm still living off of my initial $20 deposit :))
    #16     Dec 20, 2016
  7. joederp


    Ran, does the backtesting feature in QTPyLib work off of its own logic/code for opening & closing positions from the historical data array chosen for testing? I'm not aware of any backtesting features built into TWS, let alone anything accessible through their API. Do you make provision for use of limit orders within this module?
    #17     Feb 3, 2017
  8. ranpo


    Yes to all :)

    QTPyLib has it's own backtesting logic. If you use market orders in backtesting, it considers the next tick/bar open as the trade price. If you're using limit orders, it considers the limit price as the trade price only if the next bar range touches your limit price.

    For obvious reasons (and this isn't limited to QTPyLib), both methods not 100% representative to real-world trading, as I'm not aware of the order queue and other market structure variances that may affect the actual trade.
    #18     Feb 5, 2017
  9. joederp


    Hello Ran, I watched your recent webinar, thanks for making time to do those! Got two questions which I posted to the input box, but moderator didn't pick them up:

    1) If you were looking at on_tick subscriptions for 35 instruments at a time, would QTPyLib be capable of handling the bandwidth and, if so, would a different data storage choice be more appropriate (e.g PostgreSQL), instead of HDF5?

    2) Have you considered (not necessarily planning) adding another market data connector (e.g. IQ Feed) or broker via another platform like Rithmic, CQG, etc?
    #19     Feb 25, 2017
  10. ranpo


    Thanks for attending the webinar :) I had a great time doing it.

    To answer your questions:

    1. Starting with version 1.5.56, QTPyLib is fully multi-threaded. It was tested with the entire S&P500 constituants and it worked without problems on a 8-core machine, although the total number of threads it can handle is machine-dependent.

    When running your strategy, use:
    $ python strategy.py --max_threads [NUMBER]
    ...and play with the [NUMBER] part to find the best settings for your machine.

    That being said, I don't foresee a problem handling 35 instruments on a decent machine.

    2. I am toying with the idea of adding more market data sources, but it'll require me to do some serious thought about possible issues that may arise (for example: I'll need to find an elegant way of mapping the symbols of each data source to IB's format to keep the simple syntax). But the short answer is YES - this is something I'm planing on having added to QTPyLib someday sooner than later.

    #20     Feb 26, 2017