Tasks · 003-position-engine
Real-time position engine
Ordered, parallelizable work. Tests precede implementation. Drive through with
/spectastic.implement — one task per invocation.
003-position-engine
Created
Read time
11 tasks across five phases. Setup → Foundational → User stories (US1·US2·US3) → Polish. Tasks marked [P] can run in parallel — different files, no dependency. Tests for a story MUST be written and failing before its implementation tasks start.
1 · Execution strategy
Implement US1 end-to-end. Ship. Iterate to US2 and US3 only after US1 is verified.
Setup → Foundational → US1 → US2 → US3 → Polish. Each story closes its conformance before the next opens.
One team on each user story after Foundational. Coordinate at shared seams (data model, API contracts) via the spec, not Slack.
2 · Phase 1 — Setup
3 · Phase 2 — Foundational
Shared infrastructure no story can ship without. Sequential where order matters.
TradeEvent and PriceTick from the umbrella model owned by 001; add no duplicate types src/main/java/io/spectastic/portfolio/model/netQty, costBasisTotal, mtmValue, unrealizedPnl, asOfSeq src/main/java/io/spectastic/portfolio/position/Position.javaPositionEngine as an @ApplicationScoped bean, gated by the umbrella portfolio.analytics.enabled flag src/main/java/io/spectastic/portfolio/AnalyticsPlatform.java4 · Phase 3a — US1 · Net quantity and basis from fills
Tests (write & fail first)
Implementation
costBasisTotal update; proportional removal costBasisTotal*|f|/|net| and crossing-zero reset to newNet*price by exact integer arithmetic src/main/java/io/spectastic/portfolio/position/PositionEngine.java5 · Phase 3b — US2 · Mark-to-market on a tick
Tests (write & fail first)
mtmValue/unrealizedPnl; a tick for an un-held instrument is a verified no-op; quantity unchanged src/test/java/io/spectastic/portfolio/PositionEngineTest.javaImplementation
netQty src/main/java/io/spectastic/portfolio/position/PositionEngine.java6 · Phase 3c — US3 · Consistent cross-instrument snapshot
N, no torn pre-/post-event mix across instruments src/test/java/io/spectastic/portfolio/PositionEngineTest.javaN src/main/java/io/spectastic/portfolio/position/PositionEngine.javaCloses FR-004.
7 · Phase 4 — Polish
/q/metrics src/main/java/io/spectastic/portfolio/position/PositionEngine.java8 · Dependencies
Setup → Foundational
Foundational → US1, US2, US3 (independent after this point)
US1, US2, US3 → Polish
9 · Change log
- Initial task breakdown. TDD per story: US1 net qty + VWAP basis with sign-flip (T-100/T-110), US2 MTM on tick (T-200/T-210), US3 consistent snapshot (T-300/T-310); Polish adds a reconcile-to-replay test, Micrometer timers, and the jacoco gate.