feat(strategies): add canonical regime-aware mean reversion
This commit is contained in:
parent
75abae2cfc
commit
6a67ae8683
24 changed files with 1910 additions and 88 deletions
|
|
@ -6,9 +6,9 @@ Scheduling source of truth: [manifest entry S05](../manifest.json). No task is a
|
|||
|
||||
## 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).
|
||||
- **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).
|
||||
- **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).
|
||||
- **STR-01 — Reverified:** S01/S02 already provide an isolated owner context and trusted SMA program. `strategies/canonical-sma.ts` still contains the single-strategy factory/binding boundary; extract only that dispatch seam for a second program.
|
||||
- **FIN-04 — Addressed by F02/F04/F05:** Owner basis, cash, fees and target reconciliation are already canonical Rust behavior. Verify independent MR/SMA owners against it; do not recreate those calculations in TypeScript.
|
||||
- **RES-01 — Still relevant:** Experimental Python full-sample preprocessing is not research evidence. S05 uses explicit fixed per-observation thresholds and no fitting; R08 still gates validation/alpha claims.
|
||||
|
||||
## Intended behavior and implementation scope
|
||||
|
||||
|
|
@ -20,11 +20,13 @@ No unrelated refactor, new service or broker activation.
|
|||
|
||||
## Likely files and ownership
|
||||
|
||||
- apps/stock/orchestrator/src/strategies/builtin/
|
||||
- apps/stock/orchestrator/src/strategies/StrategyRegistry.ts
|
||||
- libs/calculations/
|
||||
- apps/stock/orchestrator/src/contracts/builtin-strategy.ts
|
||||
- apps/stock/orchestrator/src/strategies/canonical-{builtins,sizing,sma,mean-reversion}.ts
|
||||
- apps/stock/orchestrator/src/{container,backtest/native-worker}.ts
|
||||
- test/{integration,fixtures,postgres}/canonical-regime*.ts
|
||||
- Existing SMA/worker/paper test import sites and one runnable research example
|
||||
|
||||
Write locks: example-strategy. One agent owns this change. Lock names do not override actual overlapping files.
|
||||
Write locks: example-strategy. One program owner; root owns shared contracts/dispatch, and an independent verifier owns disjoint native fixtures/tests. Lock names do not override actual overlapping files.
|
||||
|
||||
## Dependencies and blockers
|
||||
|
||||
|
|
@ -56,3 +58,25 @@ Keep migrations additive and previous results readable. Do not add a switch that
|
|||
## 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.
|
||||
|
||||
|
||||
## Execution contract — 2026-10-23
|
||||
|
||||
Base `75abae2` contains accepted S04. This wave adds `mean-reversion-regime-long-only/v1` as a distinct trusted canonical strategy; it does not reinterpret legacy mean-reversion or SMA versions. The existing native worker and opt-in paper composition use one small exhaustive built-in dispatcher. Preserve all existing financial, observation-clock and recovery contracts. No Rust, legacy strategy, generic feature framework, cache, optimizer, UI/default cutover or trading activation changes.
|
||||
|
||||
- Explicit parameters: price lookback >=2; longer trend period; momentum lag >=1; return-volatility window >=2; positive entry z threshold; nonnegative smaller exit z threshold; fractional trend/momentum floors >-1; nonnegative volatility ceiling; nonnegative decimal notional-volume minimum; `regimeFilter: volatility|none`. Owner budget remains an explicit decimal amount.
|
||||
- Pure signals reuse reviewed trailing mean/population deviation/simple returns: z=(latest-mean)/deviation (flat=0); trend=mean/longerMean-1; momentum=latest/laggedClose-1; volatility=population deviation of adjacent simple returns. Periods count observations, not elapsed time; gaps are not filled or time-normalized. Warmup is max(lookback,trend,momentum+1,volatility+1) in both ablation modes.
|
||||
- Entry is the conjunction z<=-entry, trend/momentum>=floors, close*volume>=minimum and volatility<=ceiling. `none` disables only the volatility gate. These are illustrative fixed parameters, not fitted evidence. No RSI or universal score type is needed.
|
||||
- Initial desired quantity is exact floor(ownerBudget/latestClose), without a forced minimum. Rust owns admission, available cash, fees, ownership, fills and all P&L. Retain a stable target while entry gates pass. If a gate fails, permanently cap the target to min(desired, actual owned quantity), abandoning unfilled buys; held fractional fills are preserved exactly. A flat owner may start a new eligible episode.
|
||||
- Exit z>=-exit is evaluated before entry gates. Target zero persists until the owner is flat, even during low volume/high volatility and partial exits. Never cancel an outstanding exit by replacing zero with held quantity. Empty target lists preserve prior commitments; explicit zero/owned targets invoke native reconciliation.
|
||||
- State is bounded detached JSON with exact selection/version binding, original observation identity, history and desired target. Future data rejects; duplicate/older delayed bars cannot rewrite evaluated history. Stale/missing/mismatched barriers may warm state but cannot emit a new target. Fresh decisions require the newest consumed observation to match the barrier.
|
||||
- Verification covers hand calculations and threshold equality, zero variance/warmup, every-prefix state continuation, suffix causality, native partial-fill/owner/risk oracles, mixed SMA/MR worker parity, one durable restart, repeated ablation inputs and explicit fee/slippage sensitivity. No claims of profitable alpha or out-of-sample validation before R08.
|
||||
|
||||
|
||||
## Validated handoff — 2026-10-23
|
||||
|
||||
Implementation and independent G1/G2 review accepted; manifest remains `review` until acceptance/commit. See [wave18 validation](../manifest.json) for exact source hashes, commands, economic oracles and limitations. Existing SMA version/selection serialization remains stable. The MR schema rejects legacy settings, unsupported versions and untrusted code fields.
|
||||
|
||||
Use `createBuiltinStrategy` from `strategies/canonical-builtins.ts` for either trusted canonical version. The new selection is `strategyId: mean_reversion`, `strategyVersion: mean-reversion-regime-long-only/v1`, with all parameters explicit. Both the existing native worker and opt-in canonical paper composition use that dispatcher; legacy/default APIs remain separate.
|
||||
|
||||
[The research example](../../../../apps/stock/orchestrator/examples/canonical-regime-research.ts) takes an existing `StrategyReplayRequest`, an existing `NativeBacktestWorker`, explicit alternative `{feeRate, slippageRate}` and an abort signal. `createRegimeComparisons` returns four detached requests for review; `runRegimeComparisons` executes them serially and returns exact requests/native reports. The caller owns worker lifecycle and artifact/result retention. This is a reproducible diagnostic recipe, not a validation/optimization or saved-experiment framework. No model or code artifact provenance guarantee replaces pending R01/R05/R06.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue