portfolio-rebalance
Compute exact buy and sell amounts to rebalance your portfolio to target allocations, with drift threshold support for partial rebalancing.
Instructions
Pure-math portfolio rebalancing calculator. Given current holdings (asset names and their current USD values) and target allocations (percentages summing to 100), returns the exact buy/sell dollar amounts needed to reach target weights. Handles partial rebalancing with a drift threshold. No external API — deterministic and instant. Useful for DeFi agents, robo-advisory flows, and automated rebalancing triggers.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| holdings | No | Current portfolio positions. | |
| targets | No | Target allocation percentages. Must sum to 100. | |
| drift_threshold_pct | No | Minimum drift percentage before an asset is flagged as needing rebalance (default 1.0). Positions within threshold are marked 'in_range'. | |
| cash_injection | No | Optional additional cash (USD) to deploy during rebalancing (positive = buying, negative = withdrawing). |