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/

    IB - Interactive Historical Data Download Bug report

    General Discussion
    2
    4
    301
    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.
    • B
      barton05 last edited by barton05

      Tried to download data using IBStore, it can download historical minutes data start with 30 May 2019 but fail if start with 31 May 2019. @backtrader appreciate if you can take a look below, thanks!

      #use demo account, port=7497
      ibstore=bt.stores.IBStore(port=7497)
      cerebro = bt.Cerebro()
      stockName='SPY-STK-ISLAND-USD'
      data = ibstore.getdata(dataname=stockName,
                          historical=True,
                          timeframe=bt.TimeFrame.Minutes,
                          compression=60,
                          fromdate=datetime.datetime(2019, 5, 31),
                          todate=datetime.datetime(2019,6, 25))
      cerebro.adddata(data,name=stockName)
      cerebro.run()
      

      Below is the error message:

      ---------------------------------------------------------------------------
      ValueError                                Traceback (most recent call last)
      <ipython-input-11-00a260357ba9> in <module>()
           15                     todate=datetime.datetime(2019,6, 25))
           16 cerebro.adddata(data,name=stockName)
      ---> 17 cerebro.run()
           18 '''
           19     if len(data)>0:
      
      /usr/local/lib/python3.7/site-packages/backtrader/cerebro.py in run(self, **kwargs)
         1125             # let's skip process "spawning"
         1126             for iterstrat in iterstrats:
      -> 1127                 runstrat = self.runstrategies(iterstrat)
         1128                 self.runstrats.append(runstrat)
         1129                 if self._dooptimize:
      
      /usr/local/lib/python3.7/site-packages/backtrader/cerebro.py in runstrategies(self, iterstrat, predata)
         1208                 if self._exactbars < 1:  # datas can be full length
         1209                     data.extend(size=self.params.lookahead)
      -> 1210                 data._start()
         1211                 if self._dopreload:
         1212                     data.preload()
      
      /usr/local/lib/python3.7/site-packages/backtrader/feed.py in _start(self)
          201 
          202     def _start(self):
      --> 203         self.start()
          204 
          205         if not self._started:
      
      /usr/local/lib/python3.7/site-packages/backtrader/feeds/ibdata.py in start(self)
          400         if self._state == self._ST_START:
          401             self._start_finish()  # to finish initialization
      --> 402             self._st_start()
          403 
          404     def stop(self):
      
      /usr/local/lib/python3.7/site-packages/backtrader/feeds/ibdata.py in _st_start(self)
          627                 timeframe=self._timeframe, compression=self._compression,
          628                 what=self.p.what, useRTH=self.p.useRTH, tz=self._tz,
      --> 629                 sessionend=self.p.sessionend)
          630 
          631             self._state = self._ST_HISTORBACK
      
      /usr/local/lib/python3.7/site-packages/backtrader/stores/ibstore.py in reqHistoricalDataEx(self, contract, enddate, begindate, timeframe, compression, what, useRTH, tz, sessionend, tickerId)
          707         duration = None
          708         for dur in durations:
      --> 709             intdate = self.dt_plus_duration(begindate, dur)
          710             if intdate >= enddate:
          711                 intdate = enddate
      
      /usr/local/lib/python3.7/site-packages/backtrader/stores/ibstore.py in dt_plus_duration(self, dt, duration)
         1174             month = dt.month - 1 + size  # -1 to make it 0 based, readd below
         1175             years, month = divmod(month, 12)
      -> 1176             return dt.replace(year=dt.year + years, month=month + 1)
         1177 
         1178         if dim == 'Y':
      
      ValueError: day is out of range for month
      
      B B 2 Replies Last reply Reply Quote 0
      • B
        barton05 @barton05 last edited by

        One more interesting bug:
        When trying to download IB historical with fromdate older than the stock start date.
        I.e. RWGV first trading day start with 18 Jan 2019 and i tried to use following code:

        data = ibstore.getdata(dataname='RWGV',
                                currency='USD',
                               exchange='ARCA',
                                historical=True,
                                timeframe=bt.TimeFrame.Days,
                                fromdate=datetime.datetime(2016, 5, 1),
                                todate=datetime.datetime(2019,6, 1))
        

        This code will have no data downloaded instead download data from 18 Jan - 1 Jun 2019.

        B 1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators @barton05 last edited by

          @barton05 said in IB - Interactive Historical Data Download Bug report:

          ppreciate if you can take a look below, thanks!

          Actually the code there could fail in some other lines for those downloads. All dates should be checked against an actual calendar implementation. Too much for the current state.

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators @barton05 last edited by

            @barton05 said in IB - Interactive Historical Data Download Bug report:

            This code will have no data downloaded instead download data from 18 Jan - 1 Jun 2019.

            Don't download data before the start of the actual trading start.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
            $(document).ready(function () { app.coldLoad(); }); }