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/

    Transaction Analyzer: price <backtrader.linebuffer.LineBuffer object [...]>

    General Code/Help
    1
    4
    74
    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.
    • Kjiessar
      Kjiessar last edited by

      Hi,
      the output of the analyser gives object str instead of the actual price.
      Any idea what I'm doing wrong here?

          cerebro.addanalyzer(bt.analyzers.Transactions, _name='transactions')
          d =strat.analyzers.getbyname("transactions").get_analysis()
          print(d)
      

      One correct and one outputted wrong

      OrderedDict(
      [(datetime.datetime(1970, 1, 1, 19, 9, 27),
      [[23.10281162, 2.05e-05, 0, '', -0.00047360763821]]),
      [...]
      [[-23.10281162, <backtrader.linebuffer.LineBuffer object at 0x000001847D964400>, 0, '', 0.0005489228040912]]),
      [...]])

      Kjiessar 1 Reply Last reply Reply Quote 0
      • Kjiessar
        Kjiessar @Kjiessar last edited by

        @kjiessar
        In the above code sample a run is performed, just tried to put in the relevant information

        Some more info not sure if it can help but thought couldn't hurt

        Trade:

        1970-01-01 19:45:46,-5.0,2.224e-05,0,,0.0001112

        1970-01-01 19:45:54,-5.0,<backtrader.linebuffer.LineBuffer object at 0x0000029F82F3DF70>,0,,0.00011485

        OHLC

        1970-01-01 19:45:53+00:00,1629356760,2.271e-05,2.271e-05,2.271e-05,2.271e-05,0.0,0

        1970-01-01 19:45:54+00:00,1629356820,2.279e-05,2.297e-05,2.279e-05,2.297e-05,0.0,0

        1970-01-01 19:45:55+00:00,1629356880,2.275e-05,2.275e-05,2.275e-05,2.275e-05,0.0,0

        Kjiessar 1 Reply Last reply Reply Quote 0
        • Kjiessar
          Kjiessar @Kjiessar last edited by

          @kjiessar

          And more Information:
          GitHub: BT Transaction Analyzer

              def next(self):
                  # super(Transactions, self).next()  # let dtkey update
                  entries = []
                  for i, dname in self._idnames:
                      pos = self._positions.get(dname, None)
                      if pos is not None:
                          size, price = pos.size, pos.price
                          if size:
                              entries.append([size, price, i, dname, -size * price])
          
                  if entries:
                      self.rets[self.strategy.datetime.datetime()] = entries
          
                  self._positions.clear()
          
          Kjiessar 1 Reply Last reply Reply Quote 0
          • Kjiessar
            Kjiessar @Kjiessar last edited by

            @kjiessar
            Aaand again. After long debugging session I found the culprit and it wasn't even in the code I had shown.

            Errorness:

            self.sell(data=self.data0, exectype=bt.Order.Limit, price=self.datas[0].close, size=entry["size"], valid=datetime.timedelta(minutes=self.p.tis))
            

            correct one:

            self.sell(data=self.data0, exectype=bt.Order.Limit, price=self.datas[0].close[0], size=entry["size"], valid=datetime.timedelta(minutes=self.p.tis))
            

            Note the proce parameter and the last [0]

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