Accurate Summation of Many Small Position P&L Values
Last updated: November 29, 2026
Quick Overview
A nightly job sums millions of per-position P&L values of mixed magnitude in double precision, and the total drifts from a reference system. Explain why and implement a compensated summation that fixes it.
D. E. Shaw
November 29, 20260
0
0 solved
A nightly job sums millions of per-position P&L values of mixed magnitude in double precision, and the total drifts from a reference system. Explain why and implement a compensated summation that fixes it.
In the style of a D. E. Shaw technical screen for software developers on the risk and P&L side, where numerical correctness is treated as seriously as speed. The interviewer checks that you understand IEEE 754 rounding, can explain why order of addition matters, and know a standard fix rather than reaching for decimals everywhere.
What the Interviewer Expects
- Explains that each floating point add rounds to 53 bits of mantissa and small addends lose low-order bits
- Shows that addition is not associative, so ordering and parallel reduction change results
- Implements Kahan or Neumaier summation correctly
- Mentions math.fsum or exact accumulation for reference checks
- Discusses when fixed-point integers (for example cents or basis points) are the better representation
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 do you make a parallel reduction across 64 threads give identical results run to run?
- When would you store P&L as integers instead of doubles?
- What breaks plain Kahan summation and how does Neumaier repair it?
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
Sum a large array of doubles where a few values are huge (a large book's P&L) and many are tiny (rounding residues, small positions). The result should be as close as possible to the exact sum and sho...
High-Level Design
A double has about 15 to 16 significant digits. When the running total is and you add , the addend's low bits fall off the end of the mantissa. Over millions of adds the losses accumu...