perf(research): add compact replay projections and representative profiling

This commit is contained in:
Boki 2026-10-23 10:42:31 -04:00
parent 19e9dad68b
commit e3bd722e31
21 changed files with 2830 additions and 130 deletions

View file

@ -13,19 +13,23 @@ Scheduling source of truth: [manifest entry F08](../manifest.json). No task is a
## Intended behavior and implementation scope
F09 now supplies the independently deliverable compact terminal/owned-fill projection. F08 consumes it and adds historical sampling/statistical reporting; do not duplicate its native transport work. F09 is not completion of this story.
Use canonical Rust ledger postings, owned fills, occupied intervals and session-ending marks as the sole financial inputs. Reuse reviewed TypeScript statistical functions in `libs/calculations/src/analytics/` for return ratios and reports; do not port them to Rust merely for language uniformity. Add a small adapter for the engine-declared session calendar rather than blindly regrouping every venue by UTC date.
Version economics and metrics independently. Define sampling, annualization, benchmark and risk-free conventions in the result policy. Missing benchmark/risk-free inputs must not silently become invented measurements. Undefined or unsupported metrics are null with reasons. Adapt existing result DTOs without rewriting old rows.
Measurable benefit: comparable, independently checked rankings without a second ledger or a needless analytics rewrite.
Before implementation, pin reporting-only conventions in the handoff: account boundaries currently execute before equal-time observations and are not automatically close-equity samples; partial final sessions must be explicit; exposure needs a declared elapsed/venue-time denominator; the reviewed statistics currently assume 252 periods and default to 2% risk-free, so the adapter must pass a supported explicit policy and diagnose omitted inputs. These choices must not alter financial event ordering or risk semantics. Fills are not round trips.
## Exclusions
No accounting/fill recomputation in TypeScript, statistical library rewrite, forced native port, new service, or silent reinterpretation of historical results. Native analytics remain an option only if measured as a bottleneck.
## Likely files and ownership
- apps/stock/engine/src/backtest/simple_results.rs (authoritative projections, not new statistical formulas)
- apps/stock/engine/src/financial/result.rs and replay reporting hooks (canonical outputs; legacy simple_results.rs remains separate)
- apps/stock/orchestrator/src/backtest/native-result.ts
- apps/stock/orchestrator/src/backtest/BacktestReport.ts
- libs/calculations/src/analytics/return-statistics.ts
@ -36,7 +40,7 @@ Write locks: result-contract. One agent owns this change. Lock names do not over
## Dependencies and blockers
Implementation requires [F06](F06.md) integrated.
Implementation requires [F06](F06.md) and [F09](F09.md) integrated.
Architecture decisions: ADR-002, ADR-003. Agents may not independently amend their policies.