Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. BobDenar
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    B
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 6
    • Best 0
    • Groups 0

    BobDenar

    @BobDenar

    0
    Reputation
    205
    Profile views
    6
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    BobDenar Unfollow Follow

    Latest posts made by BobDenar

    • RE: How do you buy and sell the roll with RollOver Feed

      @adamb032 self.data._rolls[0] refers to the first contract from the RollOver feed, and self.data._rolls[1] to the second.
      Therefore it is closing position on the first contract and opening on the second at the same bar.

      posted in General Code/Help
      B
      BobDenar
    • RE: How do you buy and sell the roll with RollOver Feed

      @adamb032 I have the same issue, here is the workaround I coded:

      if not self.position:
          ...
      else:
          if self._check_is_roll_date(self.data.datetime.date(), self._curr_future):
              self.sell(data=self.data._rolls[0])
              self.buy(data=self.data._rolls[1])
      

      The issue here is to get the right contract by its _rolls index. A solution would be to name each datafeed composing the RollOver, then find the wanted contract by its name.

      posted in General Code/Help
      B
      BobDenar
    • RE: Issue with RollOver and live data

      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

      posted in General Discussion
      B
      BobDenar
    • RE: Issue with date2num

      On timers with tzdata parameters to trigger timers on market place's timezone.
      Our historicals datas are stored into a MongoDB through Arctic library, since ticks and bars are stored UTC, when building a feed I add tz parameter to point to the proper timezone.

      I guess that those uses of timezones pinpointed me to this issue.

      posted in General Discussion
      B
      BobDenar
    • Issue with date2num

      Hi,

      I use timezones intensively, and I had an issue with date2num on line 209 of utils/dateintern.py.
      The code refers to an undefined variable dwhen:

      def date2num(dt, tz=None):
          """
          Convert :mod:`datetime` to the Gregorian date as UTC float days,
          preserving hours, minutes, seconds and microseconds.  Return value
          is a :func:`float`.
          """
          if tz is not None:
              dt = tz.localize(dwhen)
      
          if hasattr(dt, 'tzinfo') and dt.tzinfo is not None:
              delta = dt.tzinfo.utcoffset(dt)
              if delta is not None:
                  dt -= delta
      
          base = float(dt.toordinal())
          if hasattr(dt, 'hour'):
              # base += (dt.hour / HOURS_PER_DAY +
              #          dt.minute / MINUTES_PER_DAY +
              #          dt.second / SECONDS_PER_DAY +
              #          dt.microsecond / MUSECONDS_PER_DAY
              #         )
              base = math.fsum(
                  (base, dt.hour / HOURS_PER_DAY, dt.minute / MINUTES_PER_DAY,
                   dt.second / SECONDS_PER_DAY, dt.microsecond / MUSECONDS_PER_DAY))
      
          return base
      

      My guess is that dwhen must be substituted with dt.

      Thanks

      posted in General Discussion
      B
      BobDenar
    • Issue with RollOver and live data

      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

      posted in General Discussion
      B
      BobDenar