Lesson 10 of 15
Portfolio Rebalancing
Portfolio Rebalancing
Portfolio rebalancing is the process of realigning the weights of a portfolio to match a target allocation. Over time, winning assets grow and losing assets shrink, causing the portfolio to drift from the desired allocation.
Rebalance Trades
To rebalance, we compute how many shares (or units) of each asset to buy or sell:
trade[i] = (target_weights[i] - current_weights[i]) * portfolio_value / prices[i]
- A positive trade means buying more of that asset.
- A negative trade means selling some of that asset.
- A zero trade means no change needed.
Task
Implement rebalance(current_weights, target_weights, prices, portfolio_value) that returns a list of trade sizes for each asset.
Python runtime loading...
Loading...
Click "Run" to execute your code.