I have run a self-rebalancing buy and holding strategy in the past using timers and order_target_percent, like so:
def __init__(self, **kwargs): self.add_timer( when=bt.timer.SESSION_START, monthdays=, timername='buytimer', # in case the day is a non-trading day the timer should kick in on the next trading day )
def notify_timer(self, timer, when, *args, **kwargs): current_month = self.datas.datetime.date(0).month if current_month not in [2, 5, 8, 11]: # not time to buy return if self.order: return self.order = self.order_target_percent(data=self.A, target=0.5, exectype=bt.Order.Market) self.order = self.order_target_percent(data=self.B, target=0.5, exectype=bt.Order.Market)
I provide this as a starting point, since I'm not sure where to go from here. I have a list of a couple hundred dates, with 15 tickers per date (using a non-traditional data source), and would like to run a backtest by inputting these tickers manually. How would I start to go about this? I figure doing it through the above timer method would be horribly inefficient runtime + hardcoding-wise. Any advice?