Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Interactive Brokers historical data error when resampling into daily bars.

    General Code/Help
    2
    3
    276
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sullyai
      sullyai last edited by

      I have been working with backtrader for a while now and I love the platform but I have just recently started working with Interactive brokers and backtrader. I have found that the data feed seems to get stuck whenever I resample into daily bars. I have 5, 15, and 60 minute data and I am trying to add daily resampling. However, when I add the resample line, my script seems to get through a few bars, then just stops working and I have to close my terminal altogether. When the daily resample is removed, it works like a dream. I have also tried making separate requests for intraday and daily bars but when I do that, I get the data notification then the error in the dt0 = min(dt0 for dt0 in enumerate(dts)), min() is an empty argument.

      My code for resmapling:

      datakwargs = dict(dataname = epic, 
                                    historical = historical, 
                                    latethrough = False, 
                                    fromdate = dt.datetime.strptime(fromdate, '%Y-%m-%d'),
                                    qcheck = 0.5)
                  
      data = IBDatafactory(**datakwargs)
                                        
      cerebro.resampledata(data,  timeframe = bt.TimeFrame.Minutes, compression = interval)
      cerebro.resampledata(data,  timeframe = bt.TimeFrame.Minutes, compression = 15)
      cerebro.resampledata(data,  timeframe = bt.TimeFrame.Minutes, compression = 60)
      cerebro.resampledata(data,  timeframe = bt.TimeFrame.Days, compression = 1) 
      

      Please let me know if I am an idiot or if there is something wrong in the system. Also, the code is inside of a function, but I have attached what is pertinent.

      Thank you so much!

      B 1 Reply Last reply Reply Quote 0
      • B
        bigdavediode @sullyai last edited by

        @sullyai Couple of points that may or may not be useful: resampledata is done in-place so you are resampling four times in-place above. Ie. if your "day" has a half an hour bar during the real time hours, then you may get stuck resampling from 60 minutes to 1 day. Resample from 1 minute to daily instead.

        Another thought is that your source data may be missing some bars due to it not being traded. For example, at the 4:00pm bar there may not be a "tick" yet so it may be missing and thus cannot be resampled. Especially with ibdata which isn't real tick data.

        1 Reply Last reply Reply Quote 0
        • sullyai
          sullyai last edited by

          Thank you so much! I changed the datakwargs from:

          datakwargs = dict(dataname = epic, 
                                        historical = historical, 
                                        latethrough = False, 
                                        fromdate = dt.datetime.strptime(fromdate, '%Y-%m-%d'),
                                        qcheck = 0.5)
          

          to this:

          datakwargs = dict(dataname = epic, 
                                        timeframe = bt.TimeFrame.Minutes,
                                        historical = historical, 
                                        latethrough = False, 
                                        fromdate = dt.datetime.strptime(fromdate, '%Y-%m-%d'),
                                        qcheck = 0.5)
          

          with the obvious import of

          import backtrader as bt
          

          Thank you again!

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors