feat: model validation, calibration, and signal quality layer
ci/woodpecker/push/test Pipeline failed
ci/woodpecker/push/build-1 unknown status
ci/woodpecker/push/build-3 unknown status
ci/woodpecker/push/build-2 unknown status
ci/woodpecker/push/finalize unknown status
Build and Push / lint-and-test (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.adapters.broker_adapter name:broker-adapter]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.aggregation.worker name:aggregation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.extractor.worker name:extractor]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.ingestion.worker name:ingestion]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.lake_publisher.worker name:lake-publisher]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.parser.worker name:parser]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.recommendation.worker name:recommendation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.scheduler.app name:scheduler]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.api.app:app --host 0.0.0.0 --port 8000 name:query-api]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.risk.app:app --host 0.0.0.0 --port 8000 name:risk]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.symbol_registry.app:app --host 0.0.0.0 --port 8000 name:symbol-registry]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.trading.app:app --host 0.0.0.0 --port 8000 name:trading-engine]) (push) Has been cancelled
Build and Push / build-dashboard (push) Has been cancelled
Build and Push / build-superset (push) Has been cancelled
Build and Push / integration-test (push) Has been cancelled
Build and Push / beta-gate (push) Has been cancelled

- Migration 035: prediction_snapshots, prediction_outcomes, signal_evidence_links, model_metric_snapshots tables + SQL views
- Prediction snapshot writer with canonical evidence keys, duplicate detection, contribution scores
- Outcome evaluator across 5 horizons (1h, 6h, 1d, 7d, 30d)
- Metrics engine: ECE, Brier score, IC, Rank IC, benchmark comparison
- Attribution engine: per-source, per-catalyst, per-layer performance
- Calibration engine: Bayesian shrinkage source reliability
- Quality gate for live trading eligibility with configurable thresholds
- 7 new /api/validation/* endpoints
- Upgraded OpsModel dashboard with validation tab
- Enhanced recommendation display with calibration context
- Backtest replay validation mode
- 86 Python tests (unit + property-based), 179 frontend tests passing
This commit is contained in:
Celes Renata
2026-05-01 03:04:58 +00:00
parent 5d2ffd9163
commit 7fcc8a6c07
23 changed files with 7554 additions and 9 deletions
+40 -1
View File
@@ -64,6 +64,7 @@ from services.shared.metrics import (
AGGREGATION_WINDOWS_COMPUTED,
)
from services.shared.schemas import TrendDirection, TrendSummary, TrendWindow
from services.trading.model_quality_gate import QualityGateResult, evaluate_quality_gate
logger = logging.getLogger(__name__)
@@ -1576,10 +1577,34 @@ async def aggregate_company(
# Mid-cycle changes take effect on the next cycle.
probabilistic = await fetch_probabilistic_scoring_enabled(pool)
pipeline_mode = "probabilistic" if probabilistic else "heuristic"
# --- Quality gate evaluation (Req 11.2, 11.3) ---
# Evaluate model quality gate at the start of each aggregation cycle.
# When the gate fails, all recommendations are forced to paper mode.
# Gate evaluation failure defaults to paper-only (fail-safe).
quality_gate_passed = False
try:
gate_result: QualityGateResult = await evaluate_quality_gate(pool)
quality_gate_passed = gate_result.passed
logger.info(
"Quality gate for %s cycle: %s%s",
ticker,
"PASS" if gate_result.passed else "FAIL",
gate_result.reason,
)
except Exception:
logger.exception(
"Quality gate evaluation failed for %s cycle — "
"defaulting to paper-only mode (fail-safe)",
ticker,
)
quality_gate_passed = False
logger.info(
"Aggregation cycle for %s: pipeline_mode=%s",
"Aggregation cycle for %s: pipeline_mode=%s quality_gate=%s",
ticker,
pipeline_mode,
"passed" if quality_gate_passed else "failed",
)
# --- Regime detection (Req 7.1, 7.2, 7.3, 7.8, 7.9) ---
@@ -1647,6 +1672,20 @@ async def aggregate_company(
ticker_returns=ticker_returns,
ticker_volumes=ticker_volumes,
)
# When quality gate fails, annotate the trend summary so the
# recommendation engine forces paper mode (Req 11.2, 11.3).
if not quality_gate_passed:
ctx = summary.market_context
if isinstance(ctx, dict):
ctx["quality_gate_passed"] = False
elif ctx is not None and hasattr(ctx, "model_dump"):
ctx_dict = ctx.model_dump()
ctx_dict["quality_gate_passed"] = False
summary.market_context = ctx_dict
else:
summary.market_context = {"quality_gate_passed": False}
summaries.append(summary)
return summaries