Backtrader Community

    • 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/

    How to add new column that is string type to datafeed?

    General Code/Help
    1
    1
    34
    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.
    • C
      crackerlee last edited by

      I wanted to add an additional column to datafeed, the column provide corresponding
      future contract code of one line, the data just like this:
      b0052522-4bf9-4626-897a-39f593556554-image.png

      I subclass bt.feeds.PandasData:
      class PandasData_return(bt.feeds.PandasData):
      lines = (''code',)
      params = (('code', -1),)
      datafields = bt.feeds.PandasData.datafields + (['code'])

      but when I run strategy, I got an error below:
      --> 222 self.array[self.idx + ago] = value
      223 for binding in self.bindings:
      224 binding[ago] = value

      TypeError: must be real number, not str

      Anyone has good idea? thanks.

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