Rebalancing means periodically resetting the portfolio weights to their targets. Without it, the asset that rises most ends up dominating and the actual risk drifts away from the chosen risk.
In Backtrader, you schedule a timer in __init__: self.add_timer(when=bt.Timer.SESSION_START, monthdays=[1], monthcarry=True). At the start of each month, Backtrader calls notify_timer(self, timer, when, *args, **kwargs), where you put the order_target_percent calls.
monthcarry=True moves the trigger to the next trading day if the 1st falls on a weekend or a holiday. For a weekly rhythm, use weekdays=[1] (Monday).
The trade-off is about frequency: rebalancing every day sticks to the targets but piles up fees; once a quarter or a year costs little but lets the weights drift. Another option: only rebalance when a weight strays from its target by more than a few points.
Examples
NU-X (fictional market) : Each rectangle stands for a one-month period. At the start of each one, the timer fires and the strategy resets the weights to their targets; in between, it lets the portfolio move.
2022: stocks and bonds fall together : In 2022, the S&P 500 lost about 19% and the US investment-grade bond index about 13%: a rare year in which both fell at the same time. A rebalanced 60/40 portfolio fell too. Rebalancing keeps the chosen risk, it does not protect against a general decline.
Key terms
Rebalancing
Periodically resetting portfolio weights to their targets
add_timer
Method that schedules a recurring trigger
notify_timer
Method called when a timer fires
Drift threshold
Maximum gap tolerated between an actual weight and its target