Implementing time-based rebalancing
The trigger for time-based rebalancing is just the calendar. Typical schemes might be annual – a specific date such as December 31, or quarterly, which might be set dates at the end of each quarter.
Before we get to the rebalancing algorithm, let’s do a little cleanup to ensure we are reusing our code in the Portfolio
class. Because we want to reuse those handy differences between the model and current allocations, let’s separate that from our current drift function:
def calculateDiffsToModel(self) -> list: allocations = [obj.percentage for obj in self.allocations] holdings = [obj.units for obj in self.allocations] if sum(holdings) == 0.0: return [] market_values = [] for allocation in self.allocations: price = float(yf.Ticker(...