Welcome to the risk team. The service nets signed trades per counterparty and symbol: buys are positive, sells are negative, and the net position is their signed sum, isolated per (counterparty, symbol).
Welcome to the risk team. The service nets signed trades per counterparty and symbol: buys are positive, sells are negative, and the net position is their signed sum, isolated per (counterparty, symbol).
This repository has three reported problems, listed below as tickets. Fix as many tickets as you can in 45 minutes. Each ticket is checked separately, and you are not expected to finish every one.
You may use the AI assistant and normal repository tools. Treat the assistant like a junior developer: establish a plan, inspect its work, run the tests, and retain ownership of the result.
risk/
models.py domain types (Trade, with signed qty)
errors.py LimitBreach
positions.py PositionBook: net per (counterparty, symbol)
netting.py NettingService: add_trade (idempotent), net_position
service.py RiskService: the public entry point
tests/visible/ shipped regression tests
conftest.py puts the repository root on the import path for pytest
trade_id.(counterparty, symbol) and never share across counterparties.Risk numbers are wrong: a sell adds to the net position instead of reducing it. Positions are being accumulated with the magnitude of each trade, ignoring its sign.
Do not change counterparty isolation as part of this ticket.
The same trade sometimes arrives twice from the upstream feed, and the position counts it twice. Trades must be idempotent on trade_id.
trade_id twice counts the trade once.trade_id with the same fields still counts.trade_id twice and asserts a single application.Do not change the sign handling as part of this ticket.
Two counterparties trading the same symbol are being netted together, so one counterparty's exposure bleeds into another's. Positions are keyed only by symbol.
(counterparty, symbol).Do not change the sign handling or idempotency as part of this ticket.
pytest tests/visible. Every shipped test fails on the starter code and passes once the bugs it covers are fixed.risk/ are submitted; the shipped tests in tests/visible run as they are.Adapted from treasure567/bloomberg-practice (round-2/basalt @ 8de07d5), used with the author's permission.
Visible test command
pytest tests/visibleThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
risk-netting-signs-replays-and-counterparty-mix
Changes under src/ are evaluated.