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/

    Simulated Order

    General Code/Help
    3
    8
    1768
    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.
    • P
      Praveen Baratam last edited by

      As per my understanding there are only Market, Limit, Stop and StopLimit order types supported by BT.

      But many frameworks also support a Simulated order type that just executes an order at a supplied price irrespective of the market data in that Bar.

      It might sound dumb but this type of simulated orders are needed for weeding out outliers during optimization.

      How can we implement such an order on Backtrader?

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

        @Praveen-Baratam said in Simulated Order:

        As per my understanding there are only Market, Limit, Stop and StopLimit order types supported by BT.

        Wrong. StopTrail, StopTrailLimit, OCO, Bracket and Market on Close (named Close) and Spot-Future compensation orders.

        See

        • Docs - Order
        • Docs - OCO Orders
        • Docs - StopTrail(Limit)
        • Docs - Bracket Orders
        • Docs - Futures and Spot Compensation

        @Praveen-Baratam said in Simulated Order:

        But many frameworks also support a Simulated order type that just executes an order at a supplied price irrespective of the market data in that Bar.

        Let's see what the other frameworks support:

        • The price range is between 99 and 100 and a buy order wants to be matched at 50 and it gets matched.
        • The next bar has a price range between 100 and 100 (no movement) and the trade has an instant profit of 100%.

        It might sound dumb

        Indeed it does seeing the quickly crafted example from above.

        How can we implement such an order on Backtrader?

        backtrader doesn't support that functionality. If the price isn't there, there will be no matching.

        1 Reply Last reply Reply Quote 0
        • P
          Praveen Baratam last edited by

          Let me explain the use case for this.

          While optimizing our strategies, it is prudent that one off profit drivers do not influence our optimization metrics.

          Lets say we are optimizing a strategy and we have the following backtest results for 2 sets of parameters Set A and Set B

          Strategy Parameter Set A

          Trade 1: -10%
          Trade 2: -15%
          Trade 3:-5%
          Trade 4: 1%
          Trade 5: 6%
          Trade 6: -20%
          Trade 7: 201% (Outlier)

          Total Return : 25.1%

          Strategy Parameter Set B

          Trade 1: -10%
          Trade 2: 15%
          Trade 3:17%
          Trade 4: -9%
          Trade 5: 8%
          Trade 6: 20%
          Trade 7: -15%

          Total Return: 21.3%

          If our strategy is being optimized for say Total Return it will choose Set A as the ideal parameter set for the Strategy which is not truly the ideal set.

          We can approach this problem by defining complex optimization targets or simply limiting the profits any given trade can produce during optimization.

          Lets say we limit the profit to 20% by forcing an order to that hypothetical price point, Set A would only have a Total Return of -25.3% and our optimization run will yield better results.

          For this, we need to know the next bar's open price so that we can calculate the actual return on this trade and then limit the return to a predefined level by forcing an exit at a hypothetical target price.

          I hope I made my case clear. Please help me realize the above objective on Backtrader!

          1 Reply Last reply Reply Quote 0
          • P
            Praveen Baratam last edited by

            @backtrader - Waiting for your reply. Please help.

            1 Reply Last reply Reply Quote 0
            • fbleaux
              fbleaux last edited by

              You need to introduce slippage.

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

                @Praveen-Baratam said in Simulated Order:

                help me realize the above objective on Backtrader!

                Please see: Community - EoDevelopment 1.x

                1 Reply Last reply Reply Quote 0
                • P
                  Praveen Baratam last edited by

                  After diving into order.py and bbroker.py I found that there is an internal order type called Historical which does exactly the same thing as I have asked for i.e. execute an order at a given price irrespective of the bar's OHLC data.

                  Is there anything I need to consider before using Historical order type for the above purpose?

                  Thank you @backtrader and @fbleaux - I understand your time is precious and I sincerely owe you for that.

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

                    See Blog - Evaluating external historical performance

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