Allocate a Custody Fee Across Accounts Without Losing a Cent
Last updated: November 29, 2026
Quick Overview
A quarterly custody fee must be split across a client's accounts in proportion to their holdings, in whole centimes, so the parts sum exactly to the fee. Explain why binary floating point is wrong for this and implement the allocation.
UBS
November 29, 20260
0
0 solved
A quarterly custody fee must be split across a client's accounts in proportion to their holdings, in whole centimes, so the parts sum exactly to the fee. Explain why binary floating point is wrong for this and implement the allocation.
Fee and interest calculations run across millions of wealth management accounts, and a rounding error repeated at that scale becomes a reconciliation break and a client complaint. A UBS phone screen in this style checks that you know how money is represented in code and can design an allocation that is exact, deterministic and auditable.
What the Interviewer Expects
- Explain why 0.1 + 0.2 is not 0.3 in IEEE 754 doubles
- Use integer minor units or a decimal type, never float
- Use the largest remainder method so parts sum exactly to the total
- Make tie-breaking deterministic so reruns give identical results
- Handle zero total holdings explicitly
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How does this change for a currency with no minor unit, such as JPY, or three, such as KWD?
- When would you use banker's rounding (ROUND_HALF_EVEN) instead?
- How would you allocate a negative amount, such as a fee rebate?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Input: a total fee in CHF and a map of account id to holding value. Output: an amount per account in CHF with two decimals. Invariants: every part is within one centime of its exact pro rata share, th...
High-Level Design
Floats store binary fractions, so 0.1 has no exact representation and 0.1 + 0.2 == 0.3 is False. Summed over millions of postings those errors show up as reconciliation breaks. I work in integer cen...