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 date2num

    General Discussion
    2
    3
    550
    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 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

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

        Can you show how you use the timezones? Thanks

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

          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.

          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(); }); }