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/

    Difference in number of trades executed and actual order issued during backtesting

    General Code/Help
    2
    3
    30
    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.
    • Z
      zuj last edited by

      I have a simple pairs trading code in which I buy one symbol and sell another symbol when a condition is met and vice versa when another condition is met. I haven't put any restrictions in backtrader. After analyzing the results using notify_order and notify_trade, I am getting total trades ([('total', 369), ('open', 2), ('closed', 367)]) while for sym1 trades are 241 and sym2 trades are 126. I also added a global variable in next() to record how many times self.close() is called for each symbol and it's 409 for both. Why are there discrepancies in the results?

      run-out 1 Reply Last reply Reply Quote 0
      • run-out
        run-out @zuj last edited by

        @zuj It's really hard to help you when we can't see your code.

        Z 1 Reply Last reply Reply Quote 0
        • Z
          zuj @run-out last edited by

          @run-out I can't share my whole strategy but I will show the part in which I issue trades because that's what matters for the notify_trade() to the best of my knowledge.

          if self.currentPosition is None:
                  if condition1:
                    self.log("Long Entry")
                    self.sell(self.data)
                    self.buy(self.data1)
                    self.currentPosition="long"
                  elif condition2:
                    self.log("Short Entry")
                    self.buy(self.data)
                    self.sell(self.data1)
                    self.currentPosition="short"
                else:
                  if self.currentPosition=="long" and condition3:
                    self.log("Long Exit")
                    self.close(self.data)
                    self.close(self.data1)
                    self.trade_count_sym1+=1
                    self.trade_count_sym2+=1
                    self.currentPosition=None
                  elif self.currentPosition=="short" and condition4:
                    self.log("Short Exit")
                    self.close(self.data)
                    self.close(self.data1)
                    self.currentPosition=None
                    self.trade_count_sym1+=1
                    self.trade_count_sym2+=1
          

          trade_count_sym1 and trade_count_sym2 both turn out to be 409 while the trade count from analyzers are mentioned in the original post

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