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/

    Extending Pandas Dataframe with string/datetime column values.

    General Code/Help
    3
    5
    136
    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.
    • D
      Dastaan Sharma last edited by

      Hi BT community,
      I need help regarding extending Pandas Datafeed:

      My dataframe looks like this :

       	open 	high 	low 	close 	volume 	expiry
      time_stamp 						
      2015-04-01 09:15:00 	18250.00 	18315.00 	18226.15 	18295.00 	222650 	2015-04-30
      2015-04-01 09:30:00 	18295.00 	18299.50 	18261.55 	18278.00 	66875 	2015-04-30
      2015-04-01 09:45:00 	18275.20 	18358.95 	18266.95 	18345.05 	162800 	2015-04-30
      2015-04-01 10:00:00 	18345.05 	18390.00 	18332.60 	18374.95 	146525 	2015-04-30
      2015-04-01 10:15:00 	18375.00 	18411.65 	18361.35 	18383.20 	119875 	2015-04-30
      

      I have tried to figure this out by myself but would love help .

      class custom(bt.feeds.PandasData):
          
          lines = ('open', 'high', 'low', 'close', 'volume',
                   'expiry',
                  )
          
          params = (
              ('open', -1),
              ('high', -1),
              ('low', -1),
              ('close', -1),
              ('volume', -1),
              ('expiry', -1),
          )
      

      How can I use string/datetime as lines ?

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

        @Dastaan-Sharma said in Extending Pandas Dataframe with string/datetime column values.:

        How can I use string/datetime as lines ?

        You cannot. It it's a timestamp, encode it to be a float (for a date the integral part of the number should be enough for most practical uses)

        1 Reply Last reply Reply Quote 0
        • D
          Dastaan Sharma last edited by

          Ah Alright.
          It is better to apply

          date2num
          

          Solved my problem though.

          tianjixuetu 1 Reply Last reply Reply Quote 0
          • tianjixuetu
            tianjixuetu @Dastaan Sharma last edited by

            @Dastaan-Sharma maybe using PandasDirectData is a better way.

            1 Reply Last reply Reply Quote 0
            • D
              Dastaan Sharma last edited by

              @tianjixuetu
              Thanks. Your analysis is really helpful for me.

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