bt
bt copied to clipboard
Correct usage of bt.algos.RunIfOutOfBounds(tolerance)
Hello - I'm curious if there's a simple example of how to properly implement bt.algos.RunIfOutOfBounds. I've put it in the algo stack after WeighTarget as well as giving it the args for tolerance and from what I can tell from looking at the code this should be it - but it consistently returns nothing. Curious if anyone has had success with it.
Trying to develop an algo that rebalances when current day weights exit a buffer percentage back to the target weight which it seems that this is... open to any other solutions!
I'm having the same issue. When I use the get_transactions method it shows that it is rebalancing every single day regardless of what I set as the threshold.
I've done this.
tolerance = 0.3
s = bt.Strategy("s1",[bt.algos.SelectAll(),
bt.algos.WeighTarget(weights),
# bt.algos.WeighEqually(),
bt.algos.Or([bt.algos.RunOnce(), bt.algos.RunIfOutOfBounds(tolerance)]),
bt.algos.Rebalance()])
test = bt.Backtest(s, price_df)
res=bt.run(test)
The weight had to be allocated first.
Good luck!