bt icon indicating copy to clipboard operation
bt copied to clipboard

Correct usage of bt.algos.RunIfOutOfBounds(tolerance)

Open jawnkc opened this issue 3 years ago • 2 comments

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!

jawnkc avatar Aug 12 '21 19:08 jawnkc

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.

painting1234 avatar Nov 04 '21 17:11 painting1234

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!

hermian avatar Nov 16 '21 23:11 hermian