57 lines
3.9 KiB
Markdown
57 lines
3.9 KiB
Markdown
# F04 — Enforce cash reservations and portfolio risk centrally
|
|
|
|
Parent epic: E2. Priority/severity: P0 / Critical. Relative complexity: L. Recommended specialization: Rust financial risk.
|
|
|
|
Scheduling source of truth: [manifest entry F04](../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-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-06 — Verified:** Native simulation fills complete requested quantities at the latest price without bar-volume participation; current risk must be enforced at acceptance and fill, including pending exposure. [apps/stock/engine/src/backtest/engine.rs:374](../../../../apps/stock/engine/src/backtest/engine.rs#L374); [apps/stock/engine/src/backtest/engine.rs:414](../../../../apps/stock/engine/src/backtest/engine.rs#L414).
|
|
|
|
## Intended behavior and implementation scope
|
|
|
|
Implement canonical cash-long-only funding, pending fee-inclusive reservations, fill-time affordability and existing per-order/symbol/gross limits. Accept explicit account RiskSessionBoundary commands from the F01 contract; do not infer a day from UTC or independently roll for every venue. Marked daily-loss and drawdown checks use canonical marks. Session rollover resets only daily baseline; peak equity and drawdown halt persist until authorized reset.
|
|
|
|
## Exclusions
|
|
|
|
No unrelated refactor, new service, broker enablement, or silent reinterpretation of historical results.
|
|
|
|
## Likely files and ownership
|
|
|
|
- apps/stock/engine/src/risk/mod.rs
|
|
- apps/stock/engine/src/financial/risk.rs (new)
|
|
- apps/stock/engine/src/financial/ledger.rs
|
|
|
|
Write locks: rust-ledger, risk-policy. One agent owns this change. Lock names do not override actual overlapping files.
|
|
|
|
## Dependencies and blockers
|
|
|
|
Implementation requires [F02](F02.md) integrated.
|
|
|
|
Architecture decisions: ADR-002, ADR-003. 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
|
|
|
|
- No accepted order/fill creates negative available cash or an unsupported short.
|
|
- Pending/partial orders reserve resources once and release on cancellation/rejection/expiry.
|
|
- Stale marks block risk increases; marked losses halt increases even without realized trades; reductions remain possible.
|
|
|
|
## Mandatory tests
|
|
|
|
- competing_reservations, adverse_gap_reject_remainder, stale_other_symbol, marked_loss_halt, explicit_risk_session_boundary.
|
|
- drawdown_halt_survives_rollover_restore, unauthorized_reset_denied, alternate_venue_does_not_reset_account_day.
|
|
- Property test raw order and target paths cannot bypass the same policy.
|
|
|
|
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.
|