[Feature] v3.0.0-beta.5 | Allocation Targets & Rebalancing Advisor | Before PR.
feat: Allocation Targets & Rebalancing Advisor
Hello @afadil, here is the feature inline with the new beta.
Branch: [feature/allocation-targets](https://github.com/Jonjon-prog/wealthfolio/tree/feature/allocation-targets)'
Base: v3.0.0-beta.5
[!IMPORTANT] By submitting a PR for this feature, I confirm I have read and agree to the CLA.
Summary
Adds a full allocation targeting and rebalancing workflow to Wealthfolio. Users can set target percentages per asset class category, visualize drift from their targets, drill down into per-holding targets within each category, and get cash-first buy suggestions to rebalance toward their targets.
Motivation
Before this feature, users could view their current allocation breakdown in the Insights page (read-only). There was no way to set personal targets, track drift, or get structured buy suggestions based on those targets.
This is a core workflow for passive investors who want to maintain a specific asset allocation strategy (e.g. 70% equities / 30% bonds) over time.
This feature builds on the taxonomy system introduced in beta (hierarchical asset class categories with weighted assignments), rather than the old hardcoded asset_class / asset_sub_class fields.
What's Included
Database
Three new SQLite tables (already migrated):
portfolio_targets— one target profile per account (or global "All Portfolio")portfolio_target_allocations— category-level target percentages (basis points)holding_targets— per-holding target percentages within a category
Backend (Rust)
- Full CRUD service for targets, category allocations, and holding targets
batch_save_target_allocations— atomic DB transaction for category savesbatch_save_holding_targets— atomic DB transaction for holding saves- Deviation report engine — compares target vs. current allocation per category
- Two-phase buy-only rebalancing algorithm:
- Phase 1: Greedy share purchases that reduce deviation from target
- Phase 2: Remaining cash deployed up to category ceiling (no overshoot)
- 15 Tauri IPC commands + matching Axum REST routes for web mode
- Unit tests for rebalancing service (5 scenarios: basic buys, budget scaling, no-holding-target categories, zero cash, Phase 2 ceiling enforcement)
Frontend
New /allocations page with two tabs:
Overview tab
- Account selector (single account or "All Portfolio")
- Single donut chart showing current allocation with hover details (category name, %, value, drift status)
- Target list with inline editing, side-by-side actual vs. target bars, drift indicators (Underweight / Overweight / Aligned)
- Auto-distribution: unlocked categories get proportional remainder when user sets one value
- Lock mechanism per category to pin a value during auto-distribution
- "Save All Targets" (atomic batch), "Clear All" button
- Category side panel (slide-in sheet) for per-holding targets within a category: same auto-distribution and lock logic, cascading % display(holding % × category % = portfolio %), grouped by instrument type
Rebalancing tab
- Cash input → "Calculate Suggestions" → buy recommendations
- Overview mode: category cards with target %, current %, suggested buy, projected new %
- Detailed mode (default): accordion per category with per-holding rows showing shares × price, amount, current → target % of category
- Zero-share toggle (show/hide holdings at or above target)
- Category residual display (unspent budget due to whole-share constraint)
- Summary: total allocated, remaining cash, additional cash needed
- Export: "Copy as Text" (clipboard) + "Export CSV" (date-prefixed filename)
- State persisted in
sessionStorageper account (survives navigation)
How to Use
Step 1 — Set your category targets
Navigate to Allocations in the sidebar. You'll see your current portfolio allocation as a donut chart, and a list of asset class categories on the right.
Click the target percentage field next to any category and type your desired allocation (e.g. 70 for 70%). As you fill in values, unset categories automatically receive the proportional remainder — shown in italic.
Once you're happy with the distribution, click Save All Targets.
[!TIP] Click the lock icon next to a category to pin its value. Locked categories are excluded from auto-distribution when you adjust others.
Step 2 — Track drift
Once targets are saved, each category row shows your actual % alongside your target %, with a drift badge:
- Underweight — you hold less than your target
- Overweight — you hold more than your target
- Aligned — within threshold
Hover over the donut chart to see the drift status for each slice.
Step 3 — Set per-holding targets (optional)
For more granular control, click the Holdings button on any category row (not available for Cash). A side panel opens showing all holdings in that category.
Set a target percentage for each holding within the category — these are percentages of that category, not of your total portfolio. The cascading percentage (e.g. "50% of Equity = 35% of portfolio") is shown below each row.
Auto-distribution and lock work the same way as at the category level. Click Save All Targets when done.
Step 4 — Get rebalancing suggestions
Switch to the Rebalancing tab. Enter the amount of cash you want to invest and click Calculate Suggestions.
The tool shows:
- Overview mode: a card per category with your target %, current %, how much to buy, and the projected new % after purchases
- Detailed mode (default): a breakdown by category with specific holdings, share counts, prices, and amounts to invest
[!NOTE] Categories with no holding targets configured show a budget allocation but no specific buy suggestions — set holding targets in Step 3 to get granular recommendations. Use the eye icon to show or hide holdings that are already at or above target (0 shares recommended).
Step 5 — Export
Use Copy as Text to copy the plan to your clipboard (e.g. to paste into our broker's order form), or Export CSV to download a spreadsheet.
Switching accounts
Use the account selector at the top to switch between individual accounts and "All Portfolio". Each account has its own independent set of targets.
Screenshots
Light Theme
Dark Theme
Architecture Decisions
- Asset classes only: Scoped to the
asset_classestaxonomy. Other taxonomies (regions, sectors) deferred — they have multi-assignment complexity that requires separate design. - Preview mode only: No strict 100% enforcement. Auto-distribution fills unset values proportionally. Users can save partial targets.
- Buy-only: The rebalancing advisor never suggests sells. Designed for passive investors making periodic contributions.
- Whole shares only: No fractional shares. Remaining cash after whole-share purchases is shown as residual per category.
- Per-account targets: Each account (or "All Portfolio") has its own target profile. Multi-account portfolio grouping (named groups of 2+ accounts) is a separate planned feature — see
docs/features/portfolios/portfolio-grouping-spec.md.
Known Limitations
[!WARNING] Physical and alternative assets (property, vehicles, collectibles, etc.) do not appear in the allocation view or rebalancing suggestions. This is inherited behavior from the existing allocation engine — these assets have no taxonomy assignments and fall into an
__UNKNOWN__bucket. The same behavior exists in the Insights page today. Physical/custom assets not included: Supporting them would require a design decision on how to map asset kinds (e.g.PRECIOUS_METAL,PROPERTY) to asset class categories — out of scope for this PR. Cash holdings: Cash (EUR, USD, etc.) uses synthetic asset IDs without real asset records. Holding-level targets are blocked for Cash categories — only category-level allocation (e.g. "5% Cash") is supported. The rebalancing advisor shows a budget allocation for Cash but no specific buy recommendations. No sell suggestions: The algorithm is buy-only. Users with overweight categories will not receive rebalancing suggestions for those categories until new cash is available.
[!NOTE] The rebalancing advisor only suggests buys. Overweight categories are shown for reference but receive no sell suggestions. Whole shares: Depending on share prices, a small amount of cash (typically <10%) may remain undeployed after rebalancing suggestions.
asset_classestaxonomy only: Targets cannot be set against regions, sectors, or other taxonomies in this version.
Future Work (Out of Scope for This PR)
- Portfolio grouping: Named groups of 2+ accounts for unified allocation tracking. Planned in
feature/portfolio-grouping. The allocations page currently supports single accounts and the "All Portfolio" aggregate. - Once portfolio grouping is built, the
AccountSelectoron this page will be replaced by anAccountPortfolioSelector. - Sell suggestions / full rebalancing: Suggest sells for overweight categories, not just buys for underweight ones.
- Drift alerts: Notify users when a category drifts beyond a threshold without requiring them to visit the page.
- Alternative rebalancing algorithms: More aggressive cash utilization options (e.g. allowing small overshoots) or time-based rebalancing.
Testing Notes
Rust unit tests (run with cargo test -p wealthfolio-core -- rebalancing):
test_basic_buy_recommendations— buys shares when cash availabletest_budget_scaling_when_cash_insufficient— proportional scaling across categoriestest_category_without_holding_targets_gets_budget_recommendation— Cash-like categoriestest_zero_cash_produces_no_allocations— zero cash edge casetest_phase2_deploys_remaining_cash_without_overshoot— ceiling enforcement
Manual testing checklist:
- [ ] Set category targets for "All Portfolio", save, verify drift indicators
- [ ] Switch to a single account, verify separate target profile
- [ ] Open category side panel, set per-holding targets, verify cascading %
- [ ] Rebalancing tab: enter cash, calculate, verify overview + detailed modes
- [ ] Export: copy to clipboard + download CSV
- [ ] Navigate to a holding from rebalancing tab and back — state preserved
- [ ] Account with no targets shows empty state, not an error
- [ ] Category at/above target shows 0 shares in rebalancing (verify with toggle)
Open Questions
- PR strategy: Given the tight coupling between backend and frontend, a single PR seems appropriate. Happy to split into backend-first + frontend if preferred.
- Physical/custom assets: Should the rebalancing advisor explicitly exclude non-standard asset types, or is a "no price available" silent skip acceptable? Currently the algorithm skips holdings with
price = 0silently. asset_classestaxonomy assumption: The target profile hardcodestaxonomy_id = "asset_classes". Is this acceptable for the initial version, or should it be user-selectable at profile creation?- Portfolio grouping integration: The
account_idfield onportfolio_targetsaccepts any string (account UUID or"PORTFOLIO"). When the portfolio grouping feature lands, named portfolios could map to this field naturally — does this design align with your plans? - Alternative assets in allocation tracking: Physical and alternative assets (
PRECIOUS_METAL,PROPERTY,VEHICLE, etc.) currently have no taxonomy assignments and don't appear in the allocation view — consistent with the existing Insights page behavior. Would you want these included in future allocation tracking? If so, should the app auto-map asset kinds to asset class categories (e.g.PRECIOUS_METAL→ Commodities), or should users assign them manually via the taxonomy system?
Thanks @Jonjon-prog, I'm trying to stabilize and release v3; I will review this PR later.
Thanks @Jonjon-prog, I'm trying to stabilize and release v3; I will review this PR later.
Thanks @afadil Just to let you aware I have rebased onto v3.0.0 and the branch is up to date. So we could just talk about the feature by itsel and the vision about it.
hello @afadil ,
I hope you are doing well,
Did you had the time to have a little look into that ? I got some spare time so I could correct some stuff if needed.
I want to start also a next feature (that I was talking here also) : Portfolio grouping :
Here is little list of how it will work :
Overview
Portfolios are named groups of 2+ accounts that enable unified views and strategy management across the app. A user with accounts at Degiro, Interactive Brokers, and a bank savings account can create "Retirement" (Degiro + IB) and "Emergency Fund" (savings) portfolios and manage each independently.
This is a cross-cutting feature: once built, any page that uses AccountSelector can support portfolio selection. The allocations page is the primary consumer but holdings, insights, and dashboard benefit equally.
Design Principles
- Lightweight: Portfolios are just named references to account IDs. No data duplication. All data stays in accounts/holdings tables.
- Independent strategies: Each portfolio gets its own allocation targets, performance tracking, etc.
- Flexible UX: Quick multi-select for ad-hoc exploration + named portfolios for persistent use.
- "All Portfolio" remains the default aggregate of all accounts.
If you have any idea on that or wanted to stick with the accounts let me know.
Hi @Jonjon-prog, sorry I completely forgot about this. I will check it out soon.
Hi @Jonjon-prog, sorry I completely forgot about this. I will check it out soon.
Don't worry, it's more to adjust things if you have some feedbacks. Aside from that I am trying to keep it up to date like this it will be ready fast.
@afadil Hello back :)
Did you have the time to check it little bit? Like this I can prepare the PR if this suit you.
I'm really interested by this. I think I will do an addon until subassets are supported :)
Step 3 — Set per-holding targets (optional) This would be really useful, and would be even greater to have the option to exclude some holding from the rebalancing.