Sub topic 10
Using contributions and withdrawals to rebalance
This chapter assumes you can compute portfolio weights and drift against a target allocation. It also assumes you know how calendar and threshold rules decide when to rebalance. The Python examples need only the standard library.
Earlier chapters rebalanced by selling the asset class that has grown and buying the one that has shrunk. That works, but it is not the only way to move weights. If money is already entering or leaving the portfolio, you can direct those flows so the weights move toward target without selling anything you want to keep.
The idea: let the cash flow do the trading
A contribution is new money. A withdrawal is money you must take out anyway. Both force trades. A rebalancing-by-cash-flow rule chooses those trades on purpose:
- Contributions are spent on the asset classes that are below target.
- Withdrawals are taken from the asset classes that are above target.
The benefits are practical:
- You avoid the extra sales that a normal rebalance would need, so you save transaction costs.
- In a taxable account, you realize fewer gains. Buying an underweight asset triggers no tax. Selling an overweight asset only triggers tax on the amount you must raise anyway.
- You change the weights without a separate rebalancing event.
The limit is size. Cash flows are usually small next to the portfolio, so they correct small drifts well and large drifts slowly or not at all.
Working out the right amounts
The cleanest way to allocate a flow is to ask what the portfolio should look like after the flow, then compare that with what you hold.
- Add the flow to the current total. A contribution of 5,000 raises the total. A withdrawal of 8,000 lowers it.
- Multiply each target weight by the new total to get the desired value of each asset class.
- Subtract the current value from the desired value. This gap is positive for an underweight class and negative for an overweight one.
- For a contribution, use only the positive gaps. For a withdrawal, use only the negative gaps.
- If the usable gaps add up to more than the flow, scale them down in proportion so the trades add up to exactly the flow.
Take a 60/40 portfolio with 72,000 in stocks and 38,000 in bonds, so the total is 110,000. Stocks are 65.5% of the portfolio, which is 5.5 points over target. You contribute 5,000.
- The new total is 115,000.
- Desired values are 69,000 in stocks and 46,000 in bonds.
- The gaps are −3,000 for stocks and +8,000 for bonds.
- Only the bond gap is positive. It is larger than the contribution, so all 5,000 goes to bonds.
The result is 72,000 in stocks and 43,000 in bonds. Weights are 62.6% and 37.4%, so drift shrank from 5.5 to 2.6 points with no sale.
For a withdrawal of 8,000 from the same portfolio:
- The new total is 102,000.
- Desired values are 61,200 in stocks and 40,800 in bonds.
- The gaps are −10,800 for stocks and +2,800 for bonds.
- Only the stock gap is negative, and its size exceeds the withdrawal, so all 8,000 comes from stocks.
The result is 64,000 in stocks and 38,000 in bonds. Weights are 62.7% and 37.3%.
The same procedure in code
This function handles both cases. Pass a positive flow for a contribution and a negative one for a withdrawal. It returns buys as positive numbers and sells as negative numbers, and the trades always sum to flow.
def flow_trades(values, targets, flow):
"""Allocate a contribution (flow > 0) or withdrawal (flow < 0).
Returns {asset: amount}; positive means buy, negative means sell.
The amounts sum to flow.
"""
total = sum(values.values())
gap = {a: targets[a] * (total + flow) - values[a] for a in targets}
if flow >= 0:
usable = {a: max(g, 0.0) for a, g in gap.items()}
else:
usable = {a: max(-g, 0.0) for a, g in gap.items()}
usable_total = sum(usable.values())
if usable_total == 0:
return {a: 0.0 for a in targets}
sign = 1 if flow >= 0 else -1
return {a: sign * abs(flow) * usable[a] / usable_total for a in targets}
targets = {"stocks": 0.60, "bonds": 0.40}
values = {"stocks": 72000.0, "bonds": 38000.0}
for flow in (5000.0, -8000.0):
trades = flow_trades(values, targets, flow)
new_values = {a: values[a] + trades[a] for a in values}
new_total = sum(new_values.values())
print(f"flow {flow:+,.0f}: trades {trades}")
for a in targets:
print(f" {a}: {new_values[a] / new_total:.1%}")Running it prints bond buys of 5,000 for the contribution and stock sells of 8,000 for the withdrawal, with the weights computed above.
Two properties are worth knowing:
- Positive gaps always add up to at least the contribution. The gaps across all classes sum to the flow, and any negative gaps only subtract from that sum. So the scaling step only ever scales down or leaves the gaps unchanged.
- If no class is overweight, every gap is positive and the contribution lands exactly on target. This is the full rebalance.
How big must the flow be to fully rebalance?
Sometimes you want to know whether your regular flows are large enough to do the job. You can solve for this directly.
For a contribution with no sales, the portfolio reaches target when the most overweight class sits at exactly its target weight in the new total. For each asset, the new total must be at least value / target. So:
contribution needed = max over assets of (value / target) - totalFor the example, stocks give 72,000 / 0.60 = 120,000. Bonds give 38,000 / 0.40 = 95,000. The larger is 120,000, so the needed contribution is 120,000 − 110,000 = 10,000. After that, stocks are 72,000 of 120,000 (60%) and bonds are 48,000 (40%).
For a withdrawal with no purchases, the new total is the smallest value / target. The bonds give 95,000, so the withdrawal is 110,000 − 95,000 = 15,000, all from stocks. Stocks end at 57,000 of 95,000 (60%).
def full_fix_flow(values, targets):
"""Contribution (>0) or withdrawal (<0) that reaches target with no opposite-side trades."""
total = sum(values.values())
implied = [values[a] / targets[a] for a in targets]
if max(implied) - total > 1e-9:
return max(implied) - total # contribute this much
return min(implied) - total # negative: withdraw this much
print(full_fix_flow({"stocks": 72000.0, "bonds": 38000.0},
{"stocks": 0.60, "bonds": 0.40}))This prints 10000.0. The function returns the contribution when the portfolio is overweight in something and a negative withdrawal otherwise. When the portfolio is exactly on target, both values are equal and it returns 0.
Where cash-flow rebalancing fits in a rule
Cash flows do not replace calendar or threshold rules. They sit in front of them.
Do the flow step first, then measure. Many drifts that would have breached a band at review time are already gone, so the band check often finds nothing to do.
Keep the check itself unchanged. A threshold rule still looks only at weights and bands. A calendar rule still looks only at dates. The cash flow only changes the weights that those rules see.
Edge cases and common errors
- Flows that are too small. A monthly 500 contribution into a 500,000 portfolio moves weights by about 0.1 point. It will not stop a 10-point drift after a market crash. Keep a threshold or calendar backstop.
- Overshooting. A very large contribution to a single underweight class can push it above target. The "use only positive gaps and scale" procedure avoids this because it never buys a class past its desired value. Do not simply put the whole contribution into whichever class is most underweight.
- Withdrawals that drain one class. Repeatedly selling the overweight class can leave it close to zero in extreme cases. The procedure caps each sale at that class's gap, but check that the remaining holdings still make sense.
- Using the wrong total. Compute gaps against the total after the flow, not before. Using the old total misstates every desired value by the flow times its target weight.
- Ignoring account structure. If your assets sit in several accounts, a contribution to one account may not be able to buy the class you want. Treat the accounts as one portfolio for weights, then place trades where they cost least. Putting sales in a tax-advantaged account avoids tax, and buying in a taxable account avoids realizing gains.
- Minimum trades and fractional shares. Round the computed amounts to whole units your broker allows. Small rounding errors are fine, and the next flow corrects them.
- Treating a flow as a market view. Directing money to the underweight class is a mechanical consequence of the target. It is not a prediction that the class will do better.
Exercises
Exercise
A portfolio targets 60% stocks and 40% bonds. It holds 66,000 in stocks and 34,000 in bonds. You withdraw 5,000. (a) How much do you sell from each class using the gap method, and what are the resulting weights? (b) What withdrawal would bring the portfolio exactly to target without buying anything?
Show answer
(a) The total after the withdrawal is 95,000. Desired values are 57,000 for stocks and 38,000 for bonds. The gaps are −9,000 for stocks and +4,000 for bonds. Only the negative gap is usable, and it exceeds the withdrawal, so sell 5,000 of stocks and nothing from bonds. Holdings become 61,000 and 34,000, giving weights of 64.2% and 35.8%. (b) The new total must equal the smallest value divided by target. Bonds give 34,000 / 0.40 = 85,000, and stocks give 66,000 / 0.60 = 110,000. The smallest is 85,000, so withdraw 100,000 − 85,000 = 15,000, all from stocks. Stocks end at 51,000 of 85,000, which is 60%.
Exercise
A threshold rule uses a 5-percentage-point absolute band around a 60% stock target. Stocks are at 66% of a 200,000 portfolio. You make a 12,000 contribution. Using the gap method, does a band breach remain, and what does the rule do?
Show answer
The new total is 212,000. Desired stocks are 127,200 and desired bonds are 84,800. Current stocks are 132,000, so the stock gap is −4,800 and the bond gap is +4,800 (bonds are 68,000). Only the bond gap is positive, and 4,800 is less than 12,000, so the contribution is scaled to the usable gap: all 12,000 goes to bonds because bonds are the only class with a positive gap. Bonds become 80,000 and stocks stay at 132,000 of 212,000, which is 62.3%. That is 2.3 points from target, inside the 5-point band, so no further trades are needed.