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/

    Print Date column from the date is in Float (737069.9999999999 ). How to get the correct date format while print

    General Code/Help
    3
    3
    480
    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.
    • S
      suresh_trader last edited by

       def __init__(self):
      
          self.datadate = self.datas[0].datetime
      

      def next(self):
      print(self.datadate[0])

      if name == 'main':

      data = btfeeds.GenericCSVData(
      dataname=datapath,
      fromdate=datetime.datetime(2013,1,1),
      #dtformat=('%Y-%m-%d %H:%M:%S'),
      dtformat=('%m/%d/%Y'),
      timestamp=0,
      time=1,
      high=3,
      low=4,
      open=2,
      close=5,
      volume=6,
      timeframe= bt.TimeFrame.Days,
      compression= 1
      )

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

        self.data.datetime.date(x) where x stand for how many periods back you want to go.

        1 Reply Last reply Reply Quote 0
        • A
          ab_trader last edited by

          Docs - Quickstart - Our First Strategy:

              def log(self, txt, dt=None):
                  ''' Logging function for this strategy'''
                  dt = dt or self.datas[0].datetime.date(0)
                  print('%s, %s' % (dt.isoformat(), txt))
          

          Also bt has two functions to convert date to/from numbers: date2num and num2date.

          • If my answer helped, hit reputation up arrow at lower right corner of the post.
          • Python Debugging With Pdb
          • New to python and bt - check this out
          1 Reply Last reply Reply Quote 1
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors