FAILURE MAP
← Case archive

FA-62035 / Currency rounding and FX conversion / Member archive

A partial close re-weights the average rate · case 05

After selling part of a long position the remaining lot shows a new average and wrong unrealized P&L.

Member previewVariant 5 · 3 implementations · 6 checks per implementation

Case contract

solve(trades, spot): trades are [qty, rate] in foreign units (buy positive, sell negative) at home-per-foreign decimal rates. Adding in the position's direction updates the weighted average rate; reducing realizes closed_qty * (rate - avg) * sign(position) without changing avg; a flip realizes the closed part and opens the remainder at the trade rate; a flat position has no average. Zero-quantity trades are ignored. Unrealized = position * (spot - avg). Return [position, avg to 6 dp or None, realized to 2 dp, unrealized to 2 dp], rounded half-even only at output with unsigned zeros.

Why this case matters

Currency amounts must be rounded at the right stage and in the right unit, or ledgers, quotes and settlements drift by minor units.

One recorded failure

Sample boundary fixture

This sample comes from the broken implementation of a controlled reproducer.

Boundary fixtureActualExpectedOutcome
regression reduction-average 1[1190, "1.110424", "4.12", "-39.18"][1190, "1.113885", "4.12", "-43.30"]Failed

MEMBER ARCHIVE

The complete case is available to members.

This record includes three runnable implementations, regression fixtures, execution results, and source hashes.

Member access is invitation-based. Sign in with your invited account to inspect the sources.

Sign in to the archive ↗