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/

    Order

    General Discussion
    6
    12
    4296
    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.
    • K
      KT last edited by

      Hi! I would like to clarify for the definition of order.executed.value and how the trade.pnl is calculated in backtrader.

      If I am using multiple datasets, is it possible if I calculate trade.pnl for each datasets? And if I am backtesting for FX, how do i obtain the net profit in terms of pips?

      Thankss :)

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

        A Trade is always a per-data thing. Several orders will be grouped to form a trade. Unless the questions is not understood, the Trade is already doing what you want.

        The order.value is the value of your position. For a long position of 100 shares at price 10, the value is 100 * 10 = 1000. It is always given as a positive value. You can multiply it by the sign of the sign if you want to distinguish between short and long positions.

        For futures, the value of an order is margin needed to cover that position.

        There is no automatic calculation to obtain the net profit in terms of pips. A custom CommissionInfo scheme would be needed. You are probably referring to calculations like the ones explained here:

        • https://www.oanda.com/forex-trading/learn/intro-to-currency-trading/conventions/pips
        1 Reply Last reply Reply Quote 0
        • K
          KT last edited by

          Thanks @backtrader ! For the case of multiple data feeds, is it possible to refer to the trade.pnl of each dataset? (Maybe sth like Trade.pnl(self.data1))

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

            @KT said in Order:

            Thanks @backtrader ! For the case of multiple data feeds, is it possible to refer to the trade.pnl of each dataset? (Maybe sth like Trade.pnl(self.data1))

            No. Each Trade you get notified over notify_trade is for a data and it has a data attribute.

            def notify_trade(self, trade):
                thedata = trade.data
            

            Although not foreseen as such, you can access the list of trades per data at self._trades in the strategy, which is a dictionary first with the data as the key and then the specific tradeid. If not tradeid has been specified (the usual case), the trades will be under the default tradeid=0

            tradesfordata = self._trades[data][0]  # list of trades for data
            
            1 Reply Last reply Reply Quote 0
            • K
              KT last edited by

              Thanks @backtrader !! Is it possible to access the opening price and closing price of an order?

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

                Orders have a request price and an execution price.

                For trades: Docs - Trade

                1 Reply Last reply Reply Quote 0
                • K
                  KT last edited by

                  Thanks @backtrader . For the order's opening price and closing price, how do i check the value of the opening and closing price?

                  Also, for the statistics that are provided by backtrader, can we check for the following info too ? The info includes
                  largest profit trade, largest loss trade, average profit trade, average loss trade, maximum number of consecutive wins, maximum number of consecutive loss, and number of trades.

                  Curtis Miller 1 Reply Last reply Reply Quote 0
                  • Curtis Miller
                    Curtis Miller @KT last edited by Curtis Miller

                    @KT If a built-in indicator is not defined (and maybe check PyFolio and read about PyFolio integration), you may need to define your own analyzers to do this: see documentation on analyzers, and an analyzers reference with list of provided analyzers.

                    Blog posts: Walk Forward Analysis Demonstration, Stock Trading Analytics and Optimization

                    Books/Video Courses: Unpacking NumPy and Pandas

                    K 1 Reply Last reply Reply Quote 0
                    • K
                      KT @Curtis Miller last edited by KT

                      @Curtis-Miller Thanks!! I will check the PyFolio

                      1 Reply Last reply Reply Quote 0
                      • Ahmed Malik
                        Ahmed Malik last edited by

                        A Trade is always a per-data https://gas-stationsnearme.com/arco/ thing. Several orders will be grouped to form a trade. Unless the questions is not understood, the Trade is already

                        1 Reply Last reply Reply Quote 0
                        • Sam Smith
                          Sam Smith last edited by

                          For example, a student with part-time work can find it difficult to get time to type up essays literature review writing services. Therefore, a “write my essay UK” agency would guarantee a scholar timely delivery of the work.

                          D 1 Reply Last reply Reply Quote 0
                          • D
                            DeclanForan @Sam Smith last edited by

                            My name is D.L. Jaworski, and I'm a writer for WordPress who focuses on the e-commerce industry. I prefer to check this https://aucklandconcretecontractors.co.nz/ and get more new things for cutters. I'm here to help you learn what it takes to create an effective e-commerce site and sell products via this platform. Order is an online marketplace. You can find many sellers and purchase anything you like at the lowest possible price.

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