Skip to content

fix(universe_returns): use NYSE trading-day arithmetic for forward windows#96

Merged
cipher813 merged 2 commits into
mainfrom
fix/universe-returns-trading-day
Apr 25, 2026
Merged

fix(universe_returns): use NYSE trading-day arithmetic for forward windows#96
cipher813 merged 2 commits into
mainfrom
fix/universe-returns-trading-day

Conversation

@cipher813
Copy link
Copy Markdown
Owner

@cipher813 cipher813 commented Apr 25, 2026

Summary

  • collectors/universe_returns.py now imports add_trading_days from alpha_engine_lib.trading_calendar (lib v0.2.1, PR fix: holiday check false positives on trading days #8) — single source of truth across data + executor + future consumers
  • Replaces the prior _add_business_days (calendar Mon-Fri, no holiday awareness) which silently mis-labeled forward returns crossing NYSE holidays (e.g. eval_date=2026-04-02 + 5 BD returned 4/9, but the actual 5th trading day is 4/10 — Good Friday was wrongly counted)

Sequencing

Requires alpha-engine-lib PR #8 merged first (adds add_trading_days etc.). alpha-engine-data is pinned @main for lib, so this picks up the new symbol on the next ae-trading boot-pull or local pip install -U after the lib merge.

Changes

  • collectors/universe_returns.py: drop local _add_business_days, import lib's add_trading_days (aliased as _add_trading_days to keep the 4 call sites unchanged)
  • tests/test_universe_returns_trading_day.py: 6 tests covering data-specific eligibility filter (_trading_days_to_process). Arithmetic tests (Good Friday, Thanksgiving, etc.) live in lib's test_trading_calendar.py — no duplication.

Test plan

  • 6 new tests cover: weekend/holiday exclusion, fwd_5d strictly-past gate, existing-set filter, sorted output, holiday-spanning eval_date (4/2 → fwd_5d=4/10) is included
  • Full suite: 215/215 pass
  • Live validation: today's manual Sat SF DataPhase1 step processes eval_date=2026-04-17 cleanly

🤖 Generated with Claude Code

cipher813 and others added 2 commits April 25, 2026 06:05
…ndows

Replace _add_business_days (Mon-Fri, no holiday awareness) with
_add_trading_days using alpha_engine_lib.trading_calendar.next_trading_day.
The pre-fix helper silently mis-labeled forward returns when the window
crossed a NYSE holiday — e.g. eval_date=2026-04-02 + 5 BD returned
2026-04-09 (counting Good Friday as a BD), so return_5d was actually a
4-trading-day return. Now lands on 2026-04-10 as intended.

Also enumerates trading days only via existing is_trading_day check, so
holidays never become eval_dates either.

14 new tests in test_universe_returns_trading_day.py covering the helper
+ _trading_days_to_process eligibility filter. 223/223 full suite pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace local helper with lib import — same logic, single source of truth
across the three repos that need trading-day arithmetic. Trim duplicate
arithmetic tests (those are locked in alpha-engine-lib's test_trading_calendar.py
now); keep data-specific eligibility-filter tests.

Requires alpha-engine-lib >= 0.2.1 (alpha-engine-data is pinned @main, so
auto-picks up after lib PR #8 merges).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cipher813 cipher813 merged commit 2f8fb86 into main Apr 25, 2026
1 of 2 checks passed
@cipher813 cipher813 deleted the fix/universe-returns-trading-day branch April 25, 2026 13:27
cipher813 added a commit that referenced this pull request May 3, 2026
PR 4c's setup_eval_quality_alarm.sh used a SEARCH expression to
reduce across (judged_agent_id, criterion, judge_model) combos at
alarm-evaluation time. Caught at deploy:

  ValidationError: SEARCH is not supported on Metric Alarms.

CloudWatch dashboards support SEARCH; alarms don't. Switched to a
simple metric alarm against the new agent_quality_score_4w_mean_min
floor metric that the rolling-mean Lambda emits (alpha-engine-research
PR #96).

  --namespace AlphaEngine/Eval
  --metric-name agent_quality_score_4w_mean_min
  --statistic Minimum --period 86400 --evaluation-periods 1
  --threshold 3.0 --comparison-operator LessThanThreshold

Operator workflow unchanged: alarm fires → operator clicks dashboard
quality-trend page to identify which combo triggered. The SEARCH
design wouldn't have surfaced per-combo identity in the alarm body
either.

bash -n syntax-clean. Tests 433 still pass (no test logic affected).

Deploy after merge: ./infrastructure/setup_eval_quality_alarm.sh
(idempotent — overwrites the alarm in place).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant