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/

    Broker cash adjust delay

    General Discussion
    2
    2
    106
    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.
    • exu
      exu last edited by

      Hi,
      How could I simulate the following behavior in BT:

      Once a position is closed (D+0) and there is profit, the broker will pay you only 3 days after, in D+3 (these are the rules in Brazil)

      I need to incorporate this in my backtest. I guess it has to do with checksubmit, but how could I delay the cash adjust?

      1 Reply Last reply Reply Quote 0
      • Mariano Volpedo
        Mariano Volpedo last edited by

        Hi,

        Did you solve that? Im trying to backtest mutual funds and need to simulate this behavior, typycally the mutual funds admin spend 3/4 days to make a change here in latin america.

        So I decided to implement this logic into any strategy code but open to recieve some feedback in order to have a better implementation. I´d rather to put this logic into cerebro/order management.

        def nextstart(self):
            self.order= None
            self.diacambio = 0
            self.fondo="In"
            self.buy(self.data0)   
              
        def __init__(self, **kwargs):  
            self.__dict__.update(kwargs)
            super().__init__()
            self.signal_buy = [False]
            self.signal_sell = [False]
            self.data0_emarapida = EMA(self.data0.close,period=self.p.emarapida,plotname="FastEMAPLOT", plot=False)
            self.data0_emalenta = EMA(self.data0.close,period=self.p.emalenta,plotname="SlowEMA", plot=False)
            self.crossoverEMA = CrossOver(self.data0_emalenta, self.data0_emarapida, plotname="CrossOver", plot=False)
        
        def next(self):       
            self.diacambio = self.diacambio + 1
            
            if self.crossoverEMA[0] > 0 and self.fondo == "Out":
                self.signal_buy[0] = True
            if self.crossoverEMA[0] < 0 and self.fondo == "In":
                self.signal_sell[0] = True
        
            if self.diacambio >= self.p.delayed:
                if self.fondo == "Order Buy":
                            self.order=self.buy(data=self.data0) 
                            #self.log("BUY EXECUTED " + self.data0._name)
                            self.fondo ="In"
                            self.signal_buy[0] = False
                            return
                elif self.fondo == "Order Sell":
                            self.order=self.sell(data=self.data0) 
                            #self.log("SELL EXECUTED" + self.data0._name)
                            self.fondo ="Out"
                            self.signal_sell[0] = False
                            return
        
            if self.fondo == "Out":
                    if self.signal_buy[0] == True :
                            self.log("BUY  " + self.data0._name)
                            self.fondo ="Order Buy"
                            self.diacambio = 0
                            return
            elif self.fondo == "In":
                    if self.signal_sell[0] == True :
                            self.log("SELL " + self.data0._name)
                            self.fondo ="Order Sell"
                            self.diacambio = 0
                            return
        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(); }); }