59 lines
4.9 KiB
Markdown
59 lines
4.9 KiB
Markdown
# F01 — Define the minimal financial contract and economic fixtures
|
|
|
|
Parent epic: E2. Priority/severity: P0 / Critical. Relative complexity: M. Recommended specialization: Rust financial contract owner.
|
|
|
|
Scheduling source of truth: [manifest entry F01](../manifest.json). No task is authorized until the plan is approved. Dependencies and decision references below describe the design; the manifest controls current readiness.
|
|
|
|
## Evidence and root cause
|
|
|
|
- **FIN-05 — Verified:** Rust and TypeScript separately implement fill/accounting behavior; the exposed native TypeScript callback method explicitly rejects callbacks. [apps/stock/engine/src/api/backtest.rs:63](../../../../apps/stock/engine/src/api/backtest.rs#L63); [apps/stock/orchestrator/src/execution/SimulationExecution.ts:114](../../../../apps/stock/orchestrator/src/execution/SimulationExecution.ts#L114).
|
|
- **FIN-03 — Verified:** Native order risk lacks a cash/fee reservation check. TypeScript compares gross exposure with pre-fee equity, so a fully funded buy can leave negative cash. [apps/stock/engine/src/risk/mod.rs:89](../../../../apps/stock/engine/src/risk/mod.rs#L89); [apps/stock/orchestrator/src/execution/model.ts:234](../../../../apps/stock/orchestrator/src/execution/model.ts#L234).
|
|
- **FIN-04 — Verified:** Native fills notify every strategy. TypeScript realized P&L uses aggregate symbol cost basis, not per-strategy cost basis. [apps/stock/engine/src/backtest/engine.rs:489](../../../../apps/stock/engine/src/backtest/engine.rs#L489); [apps/stock/orchestrator/src/execution/model.ts:108](../../../../apps/stock/orchestrator/src/execution/model.ts#L108).
|
|
|
|
## Intended behavior and implementation scope
|
|
|
|
Define only the contracts consumed by the first financial vertical slice: scalar posting rules, owner IDs, account risk-session boundary, commands/effects, snapshot version and stable decision identity. Use a maintained checked decimal implementation, not bespoke arithmetic. Absorb C05: add small hand-derived JSON/table fixtures beside their consumers, without a reference simulator or an expected-failure test campaign. Freeze the TS/Rust command/context shape before consumers implement it.
|
|
|
|
## Exclusions
|
|
|
|
No unrelated refactor, new service, broker enablement, or silent reinterpretation of historical results.
|
|
|
|
## Likely files and ownership
|
|
|
|
- apps/stock/engine/src/financial/ (new small modules)
|
|
- apps/stock/engine/src/api/
|
|
- libs/core/types/src/financial-engine.ts (new)
|
|
- test/fixtures/economics/ (small new fixture set)
|
|
|
|
Write locks: financial-contract. Review concrete file overlap; first-wave writable paths are further restricted by FIRST-WAVE.md.
|
|
|
|
## Dependencies and blockers
|
|
|
|
No code prerequisite. Global execution approval and write-lock acquisition still required.
|
|
|
|
Architecture decisions: ADR-002, ADR-003, ADR-004. Agents may not independently amend their policies.
|
|
|
|
Parallel eligibility: only with disjoint actual files and reserved write locks; read FIRST-WAVE.md for the initial exact ownership boundaries.
|
|
|
|
## Acceptance criteria
|
|
|
|
- Financial postings use8 decimal places with explicit round-half-away-from-zero at ties (matching current TS half-up behavior); reject overflow/non-finite/excess-precision external commands. Float observations/features are not converted into money strings on every native crossing.
|
|
- Authoritative basis is remaining cost amount, not rounded average price. Fixture buys3 shares for total5; partial/final disposals release exactly5 basis in total.
|
|
- Stable protocol snapshot/command serialization and unknown-version rejection pass small Rust/TS contract fixtures; scope is one supported version, not a compatibility-negotiation framework.
|
|
- Each regression fixture lists economic assumptions, hand calculation and owning task. Each implementation task adds its own passing regression coverage; do not merge a blanket failing suite.
|
|
|
|
## Mandatory tests
|
|
|
|
- Rust/TS fixture parse parity, rounding_ties_positive_negative, overflow_rejected, basis_residual_spec, command_id_conflict_spec.
|
|
- Use existing binding smoke tests to confirm Bun/addon compatibility; no temporary simulator or new FFI framework.
|
|
|
|
Apply relevant [quality gates](../../QUALITY-GATES.md). Report exact commands/results and unavailable checks; named new cases are requirements, not claims of existing passing tests.
|
|
|
|
## Regression risks and rollback
|
|
|
|
Financial or compatibility regression; preserve existing fixtures and version changed semantics.
|
|
Keep migrations additive and previous results readable. Do not add a switch that restores a correctness defect. Versioned cutover/migration is required only when persisted contracts or active engines change; never silently fall back to old economics.
|
|
|
|
## Handoff
|
|
|
|
Report scope changes (if any), fixture expectations, API/schema changes, measurements, remaining limitations and commit/PR references once authorized. Request independent review; only the integration/planning owner may mark the manifest done.
|