62 lines
4.5 KiB
Markdown
62 lines
4.5 KiB
Markdown
# D04 — Provide prefix-safe shared feature calculation
|
|
|
|
Parent epic: E3. Priority/severity: P1 / High. Relative complexity: M. Recommended specialization: Quantitative feature engineering.
|
|
|
|
Scheduling source of truth: [manifest entry D04](../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
|
|
|
|
- **STR-01 — Verified:** Registry is a useful small boundary, but its factories receive mode/execution services; BaseStrategy mixes author decisions, order submission and hidden signal filtering. [apps/stock/orchestrator/src/strategies/StrategyRegistry.ts:7](../../../../apps/stock/orchestrator/src/strategies/StrategyRegistry.ts#L7); [apps/stock/orchestrator/src/strategies/BaseStrategy.ts:315](../../../../apps/stock/orchestrator/src/strategies/BaseStrategy.ts#L315).
|
|
- **RES-01 — Verified:** Experimental Python feature preprocessing uses full-sample medians/quantiles; shuffled returns preserve ordinary Sharpe. These routines must not silently become validation evidence. [apps/stock/analytics/src/ml/feature_engineering.py:386](../../../../apps/stock/analytics/src/ml/feature_engineering.py#L386); [apps/stock/analytics/src/analysis/statistical_validation.py:168](../../../../apps/stock/analytics/src/analysis/statistical_validation.py#L168).
|
|
- **KEEP-02 — Verified:** Preserve frozen/hash-verified historical snapshots and fenced durable runner attempts; extend them instead of creating a second job engine. [apps/stock/orchestrator/src/data/historical-dataset.ts:98](../../../../apps/stock/orchestrator/src/data/historical-dataset.ts#L98); [apps/stock/orchestrator/src/backtest/BacktestRunner.ts:190](../../../../apps/stock/orchestrator/src/backtest/BacktestRunner.ts#L190).
|
|
|
|
## Intended behavior and implementation scope
|
|
|
|
Add a small feature request/result contract keyed by dataset hash, instrument, timeframe, parameters and implementation version. Reuse reviewed calculations; one experiment-local calculation per identical feature request. Prefix-gate precomputed outputs; no distributed feature service or persistent cache framework. Fitted/model features also key by artifact hash, fit-window identity and availability policy; they must not reuse a transform fitted on another partition.
|
|
|
|
Measurable benefit: Avoids duplicate work and feature leakage without a framework.
|
|
|
|
## Exclusions
|
|
|
|
No unrelated refactor, new service or broker activation.
|
|
|
|
## Likely files and ownership
|
|
|
|
- libs/calculations/
|
|
- apps/stock/engine/src/indicators/
|
|
- apps/stock/orchestrator/src/data/
|
|
- test/integration/strategy-contracts.test.ts
|
|
|
|
Write locks: feature-contract. One agent owns this change. Lock names do not override actual overlapping files.
|
|
|
|
## Dependencies and blockers
|
|
|
|
Implementation requires [S01](S01.md), [P01](P01.md) integrated.
|
|
|
|
No additional economic-policy approval is needed for this narrowly scoped task.
|
|
|
|
Deferred: Only after profiling demonstrates repeated identical feature work; use reviewed incremental calculations directly first.
|
|
|
|
Parallel eligibility: only with disjoint actual files and reserved write locks; read FIRST-WAVE.md for the initial exact ownership boundaries.
|
|
|
|
## Acceptance criteria
|
|
|
|
- Regime and strategy consumers requesting the same SMA/volatility share results within a run.
|
|
- Batch and incremental values match reviewed warmup/NaN semantics; a future data mutation cannot affect earlier features.
|
|
- Float feature outputs never become authoritative monetary calculations.
|
|
|
|
## Mandatory tests
|
|
|
|
- batch_incremental_parity, prefix_equivalence, shared_request_counter, warmup_alignment.
|
|
- Run calculations migration-preservation and numerical suites.
|
|
|
|
Apply the relevant [quality gates](../../QUALITY-GATES.md); submit exact commands, outcomes and skipped checks. Named cases above are required regression scenarios, not claims that those tests already exist.
|
|
|
|
## Regression risks and rollback
|
|
|
|
Compatibility or lifecycle regression; preserve frozen inputs, old results and existing failure tests.
|
|
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.
|