@backtrader
In terms of use order targer to rebalance, how does backtesting broker execute the orders? Do I set_coc to True and set_checksubmit to False? I loaded 10 different monthly return series and try to trade top 5 equal weight based on last 3 month returns. But my below strategy gave me some really extreme large final portfolio value. I think probably something wrong with the way I execute my orders?
Anything is about how I use ranking in bt, do you reckon it is the correct approach or should I implement everything under 'next'?
class TestStrategy(bt.Strategy):
def __init__(self):
# calculate last 3 month return
for i in range(0, 10):
self.datas[i].rtn = (self.datas[i].close(0) / self.datas[i].close(-3)) - 1
def next(self):
rtn_ls = np.array([self.datas[i].rtn[0] for i in range(0, 10)])
rtn_target = np.percentile(rtn_ls, 50)
for i in range(0, 10):
if self.datas[i].rtn[0] > rtn_target:
self.order_target_percent(target=0.2)
else:
self.order_target_percent(target=0.0)
Thank you