Simulated Order



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


  • administrators

    @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

    @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.



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



  • @backtrader - Waiting for your reply. Please help.



  • You need to introduce slippage.


  • administrators

    @Praveen-Baratam said in Simulated Order:

    help me realize the above objective on Backtrader!

    Please see: Community - EoDevelopment 1.x



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


  • administrators


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.