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/

    Issue with RollOver and live data

    General Discussion
    2
    4
    679
    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
      BobDenar last edited by

      Hi,

      I had an issue with live data and RollOver data feed, and I think I found where is the problem.
      Can you please review it and maybe submit a patch if relevant.

      The live feed is my own class (Reuters). It returns None when no data is available yet and False when this is the end of the feed (I believe this is a convention here). I am trying to trade futures with my live feed and RollOver, but a problem arises on line 155 of feeds/rollover.py:

      def _load(self):
          while self._d is not None:
              if not self._d.next():  # no values from current data source
                  if self._ds:
                      self._d = self._ds.pop(0)
                      self._dts.pop(0)
                  else:
                      self._d = None
                  continue
      

      The test on if not self._d.next(): is ambigous as it makes no difference between None and False.
      As a result if in a resampling, on say 5 seconds, no ticks came, then RollOver thinks the contract is over and get to the next one, which is wrong.

      The solution I propose is to test False on this line:

      def _load(self):
          while self._d is not None:
              if self._d.next() is False:  # no values from current data source
                  if self._ds:
                      self._d = self._ds.pop(0)
                      self._dts.pop(0)
                  else:
                      self._d = None
                  continue
      

      It works great on both live data feed and backtest data feeds.
      Thanks

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

        Indeed. I guess at that time ... such a feat was not even considered.

        1 Reply Last reply Reply Quote 0
        • B
          BobDenar last edited by

          Hi,

          I'm glad you've fixed this issue in the latest release.
          Unfortunately, there is a typo in the check for values in the data source:

          def _load(self):
              while self._d is not None:
                  if self._d.next() is not False:  # no values from current data src
                      if self._ds:
                          self._d = self._ds.pop(0)
                          self._dts.pop(0)
                      else:
                          self._d = None
                      continue
                      ...
          

          It should have been:

          def _load(self):
                  while self._d is not None:
                      if self._d.next() is False:  # no values from current data src
                      ... 
          

          not was falsely added.

          Regards

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

            Corrected. It will go into 1.9.67.122

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