feat(phase6): per-feature signal attribution in log-odds space
CI/CD / build-and-push (push) Successful in 1m56s

Adds feat_fg_lo / feat_mom_lo / feat_news_lo / feat_mfld_lo / feat_btc_dom_lo
to every trade, all normalized to log-odds contribution for direct comparability.

- fg / mom / btc_dom: raw probability-delta × 2 → log-odds
- news / mfld: already log-odds (LOGODDS_WEIGHT already applied), no scaling
- btc_dom tracked separately in bayesian.py instead of bundled in total_adj
- reasoning string updated to fg_lo= / mom_lo= notation for self-documentation

Schema: 5 new DOUBLE PRECISION columns + 2 partial indexes
Stack: TradingSignal → Order → Trade → save_trade all carry feat fields
Startup: backfill_feature_columns() recovers fg/mom/news/mfld from old
  reasoning strings (×2 applied to fg/mom); btc_dom_lo stays NULL for legacy
API: /api/metrics/features — triggered/material split per feature with
  two-level thresholds (0.05 for fg/mom/btc_dom, 0.10 for news/mfld)
API: /api/trades/legacy — exposes pre-Phase-1 trades (edge_net IS NULL)
API: _enrich_trade backward-compat: reads DB columns first, falls back to
  reasoning regex with unit conversion for pre-Phase-6 trades

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
chemavx
2026-04-22 07:04:53 +00:00
parent 9a5be27532
commit 8479a63174
7 changed files with 343 additions and 20 deletions
+47
View File
@@ -121,6 +121,53 @@ CREATE INDEX IF NOT EXISTS idx_trades_closed ON trades(closed_at) WHERE closed_a
ALTER TABLE trades ADD COLUMN IF NOT EXISTS close_pnl DOUBLE PRECISION;
ALTER TABLE trades ADD COLUMN IF NOT EXISTS resolution DOUBLE PRECISION;
-- ─────────────────────────────────────────────────────────────────────────────
-- Phase 6: per-feature signal attribution — all values in log-odds space
--
-- All four primary features share a common unit (log-odds contribution to
-- the posterior estimate) so they can be compared directly:
--
-- feat_fg_lo = _fg_contribution × 2
-- Fear & Greed direction-adjusted delta, ×2 to log-odds.
-- Non-zero for every trade. Range ≈ ±0.12.
-- Materiality threshold: |lo| ≥ 0.05.
--
-- feat_mom_lo = _momentum_contribution × 2
-- Momentum delta (direction-adjusted), ×2 to log-odds.
-- Zero when |btc_change_24h| ≤ 2 %. Range ≈ ±0.15.
-- Materiality threshold: |lo| ≥ 0.05.
--
-- feat_news_lo = news_log_adj (already in log-odds, no scaling)
-- GNews sentiment × NEWS_LOGODDS_WEIGHT (1.5).
-- Zero for non-politics or when GNews budget exhausted.
-- Range ≈ ±1.5. Materiality threshold: |lo| ≥ 0.10.
--
-- feat_mfld_lo = manifold_log_adj (already in log-odds, no scaling)
-- Manifold divergence × MANIFOLD_LOGODDS_WEIGHT (0.6).
-- Zero when Manifold returned no result.
-- Range ≈ ±0.6. Materiality threshold: |lo| ≥ 0.10.
--
-- feat_btc_dom_lo = _btc_dom_contribution × 2
-- BTC-dominance alt-pressure delta, ×2 to log-odds.
-- Only fires for ETH / altcoin / general-crypto markets
-- when btc_dominance > 55 % or < 45 %.
-- Values: { 0.06, 0.0, +0.06 }.
-- Materiality threshold: |lo| ≥ 0.05.
--
-- NULL for pre-Phase-6 trades. Backfilled at startup via
-- Database.backfill_feature_columns() using reasoning-string regex
-- (fg_lo/mom_lo multiplied by 2 from raw; news_lo/mfld_lo taken directly;
-- btc_dom_lo cannot be backfilled and remains NULL for legacy trades).
-- ─────────────────────────────────────────────────────────────────────────────
ALTER TABLE trades ADD COLUMN IF NOT EXISTS feat_fg_lo DOUBLE PRECISION;
ALTER TABLE trades ADD COLUMN IF NOT EXISTS feat_mom_lo DOUBLE PRECISION;
ALTER TABLE trades ADD COLUMN IF NOT EXISTS feat_news_lo DOUBLE PRECISION;
ALTER TABLE trades ADD COLUMN IF NOT EXISTS feat_mfld_lo DOUBLE PRECISION;
ALTER TABLE trades ADD COLUMN IF NOT EXISTS feat_btc_dom_lo DOUBLE PRECISION;
CREATE INDEX IF NOT EXISTS idx_trades_feat_fg ON trades(feat_fg_lo) WHERE feat_fg_lo IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_trades_feat_mfld ON trades(feat_mfld_lo) WHERE feat_mfld_lo IS NOT NULL;
-- ─────────────────────────────────────────────────────────────────────────────
-- Fix 3: extended metrics_daily columns for DB-computed metrics
--