Coverage for performance/rank_ic_monitor.py: 100%
7 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
1"""Phase 6 of the 5/10 -> 9/10 roadmap: production rank-IC decay
2monitoring - closes a real gap. `rank_20d` is the one signal in this
3codebase with a statistically significant backtest result (see
4risk/position_sizing.py::rank_sizing_multiplier()'s docstring: sequence
5model mean IC 0.073, t-stat 4.40 on the full series), but rank-IC was
6never monitored in production at all before this - only computed offline
7into `*_training_metrics.json` by train.py::compute_rank_ic().
9The outcome-resolution shape here is genuinely different from every
10existing trigger in performance/triggers.py: those all operate on
11already-resolved experience events (the outcome - drawdown, win/loss,
12confidence - is known at the moment the event was recorded). Rank-IC
13can't be scored until the prediction's realized 20-trading-day forward
14return is known - a "wait for the future, then join back" shape. This
15module is that outcome-resolution job: given a stream of experience
16events (each optionally carrying `resolved_predicted_rank_20d`/
17`close_price`, see experience/redis_queue.py::build_experience_event()),
18it self-joins each prediction against the SAME ticker's close ~20 TRADING
19days later (not 20 calendar days - positional, within that ticker's own
20event sequence, matching train.py::engineer_features()'s target_return_20d
21convention of a row-indexed shift, not a calendar-day one - this
22correctly respects each ticker's own trading calendar, e.g. crypto
23trading every day vs. equities/bonds only on business days), computes the
24realized forward return, then cross-sectionally ranks all tickers'
25realized returns per origin date - reusing evaluation/rank_ic_core.py's
26exact tested ranking/correlation core (no torch dependency needed here,
27this module never imports torch).
29V5.3.5 (development/Problems.md #102): the actual resolution/aggregation
30logic now lives in evaluation/rank_ic_core.py (moved, not duplicated) so
31main.py's live decision path can reuse it directly without pulling in
32this module (which `performance/__init__.py` imports transitively via
33`.trigger_worker`, which in turn imports `train.py`'s full torch/sklearn
34stack - a real Lean-isolator-timeout risk, see development/Problems.md
35#16). The two functions below are thin re-exports, kept for every
36existing caller (performance/trigger_worker.py, tests/test_rank_ic_monitor.py).
37"""
39from __future__ import annotations
41from typing import Any
43from evaluation.rank_ic_core import (
44 aggregate_rank_ic_observations,
45 resolve_realized_rank_ic_observations,
46)
49def compute_realized_rank_ic_observations(events: list[dict], horizon_days: int = 20) -> list[dict]:
50 """Thin re-export of evaluation.rank_ic_core.resolve_realized_rank_ic_observations()
51 - see that function's docstring for the actual algorithm."""
52 return resolve_realized_rank_ic_observations(events, horizon_days)
55def compute_production_rank_ic(observations: list[dict], non_overlapping_stride: int = 1) -> dict[str, Any]:
56 """Thin re-export of evaluation.rank_ic_core.aggregate_rank_ic_observations()
57 - see that function's docstring for the actual algorithm."""
58 return aggregate_rank_ic_observations(observations, non_overlapping_stride=non_overlapping_stride)