For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Broker cash adjust delay

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

  • 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
    def __init__(self, **kwargs):  
        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.log("BUY EXECUTED " + self.data0._name)
                        self.fondo ="In"
                        self.signal_buy[0] = False
            elif self.fondo == "Order Sell":
                        #self.log("SELL EXECUTED" + self.data0._name)
                        self.fondo ="Out"
                        self.signal_sell[0] = False
        if self.fondo == "Out":
                if self.signal_buy[0] == True :
                        self.log("BUY  " + self.data0._name)
                        self.fondo ="Order Buy"
                        self.diacambio = 0
        elif self.fondo == "In":
                if self.signal_sell[0] == True :
                        self.log("SELL " + self.data0._name)
                        self.fondo ="Order Sell"
                        self.diacambio = 0

Log in to reply