Adds three new synthetic-Candidate emitter engines parallel to the
existing leader_follower scheduler hook, plus look-ahead defenses
(LookaheadViolationError + per-engine assertions). Each engine is
covered by a standalone PoC config (no PEAD/parking/idle alpha) for
isolation backtests against the midlarge or broad snapshot.
Engines:
EarningsRunup (libs/backtest/earnings_runup.py)
- Trigger: days_to_earnings ∈ [3,7] AND attention_zscore_20d ≥ 1.5
AND dollar_volume_20d_zscore ≥ 1.0 (all evaluated at T-1 close)
- Entry: T+1 next_open. Exit: -4% / +8% / max_holding_days =
days_to_earnings - buffer (forced flat by close before announcement)
- PIT calendar: PointInTimeEarningsCalendar adapter for backtest;
oracle_surprise_prefetch fallback when parquet calendar absent
- PoC verdict (configs/experiments/earnings_runup_poc_v1.json):
119 trades over 1051 days, +37.27% total return, 44.46% MDD,
SQS 45.2 (profitability=55.5, risk=23.5, robustness=50.1).
VIABLE BUT NEEDS WORK — signal exists; standalone risk profile
too aggressive for v7.356 baseline (8.8% MDD on v7.364). Path
forward: per_trade_risk reduction, VIX gate, position cap, or
integrate as PEAD sleeve adjunct (not as standalone replacement).
PeerSympathy (libs/backtest/peer_sympathy.py)
- Trigger: leader passes PEAD filter (earnings_release / guidance_update
/ material_contract) AND leader reaction_close ≥ +5% AND peer 60d
correlation ≥ 0.55 over [T-65, T-5]. Top-2 peers by correlation
from leader_follower_extra_peer_symbols_by_sector + sector ETF
holdings.
- Entry: T+1 next_open on peer. Exit: -3.5% / +6% / max_holding=3 /
peer-earnings blackout
- PoC verdict (configs/experiments/peer_sympathy_poc_v1.json):
256 trades over 1051 days, -52.92% total return, 54.47% MDD,
SQS 19.6 (profitability=0.0, risk=5.4, robustness=100.0).
DEAD. The leader's catalyst is already absorbed by T+1 next_open
— peers gap up overnight before entry. robustness=100 confirms
the negative result is not noise. Salvage paths (not implemented):
reaction_close entry, raised-guidance-only restriction.
- Note: initial run_id was 0 trades due to a select_candidates
filter mismatch (engine.event_types=['peer_sympathy'] dropping
real event_type='earnings_release' rows). The runner adapter
was patched to bypass strategy_engine filtering for leader
selection; the manual peer_sympathy_leader_event_types filter
does the gating.
VolBreakout52w (libs/backtest/vol_breakout_52w.py)
- Trigger: close_T-1 > max(high[T-252:T-2]) AND volume_T-1 ≥
2 × median_volume_20d_T-2 AND ATR_14_T-1/close ∈ [0.015, 0.06].
Entry T next_open, exit -3% / +5% / max_holding=2 / MOC.
- Honest, look-ahead-safe descendant of the retired topgainer v1-v54
family. Five layers of strict-before assertions guard the bar
provider, candidate construction, trigger evaluation, and feature
timestamps. A leaky-provider proof-by-contradiction test
demonstrates the categorical catch.
- PoC verdict (configs/experiments/vol_breakout_52w_poc_v1.json,
broad-liquid universe): 1,332 trades, -87.28% total return,
88.74% MDD, SQS 24.4 (profitability=0.0, robustness=100.0).
DEAD AND HONEST. This is the most important finding of the three
PoCs: the topgainer v1-v54 lineage's headline returns (+267%
Sharpe 13.73 in best variants) were 100% lookahead bug. With
the bug removed, the 52w-high + volume + ATR signal has no real
alpha — the lookahead-corrected -4.3% from prior memory is
confirmed and amplified to -87% on a fuller universe and longer
horizon. Future "revive topgainer" proposals can cite this run
(bt_return_max_long_v1_broad-liquid_20260509042903892342_3bb473d9)
as definitive falsification.
- Pre-open gap guard inactive (no premarket data in broad snapshot).
skip_if_no_gap_data=true; the +4% gap-fade guard would not move
the result given the magnitude.
Shared infrastructure additions:
- libs/backtest/domain.py: LookaheadViolationError class +
StrategyEngineConfig fields (11 EarningsRunup + 11 PeerSympathy
+ 13 VolBreakout52w = 35 new fields)
- apps/backtester/run.py: _BacktestAttentionZscoreAdapter,
_RunnerPeerResolver, _schedule_earnings_runup_candidates,
_schedule_peer_sympathy_candidates,
_schedule_vol_breakout_52w_candidates wired into the daily
scheduler block. PeerSympathy adapter bypasses strategy_engine
filtering on leader selection (manual filter handles gating).
Tests: 21 (EarningsRunup) + 27 (PeerSympathy) + 38 (VolBreakout52w)
= 86 new unit tests, all passing. Broader unit suite: 1392 passed,
2 pre-existing failures unrelated.
Net engine state: EarningsRunup is the only viable new engine class.
PeerSympathy and VolBreakout52w are kept in-tree as falsification
evidence, not as production engines.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The _classify_event_type mapping (2.02 → earnings_release, 7.01 →
guidance_update, 1.01 → material_contract, 1.03 → other_material_event,
8.01 → other_material_event, 5.02 → management_change) was already in
place but used naive 'in items' string matching. Upstream extractors
sometimes deliver items as 'Item 2.02' or '2.02 - Results of Operations'
(full-description form), which silently slipped through to event_type
'unknown' and were rejected by all 12 v7.356 PEAD engines.
A reparse using the patched classifier touched 9,779 historical 'unknown'
rows; only 16 actually flipped (the rest are genuinely off-vocab 8-Ks
like 9.01-only, 3.01, 5.07). The fix is therefore small in retroactive
impact, but defends against future ingestion drift.
Changes:
- libs/parser/rule_parser.py: rewrote _classify_event_type with
_normalize_item_codes (regex \\b(\\d+\\.\\d+)\\b token extractor) and
tuple-of-pairs _ITEM_TO_EVENT_TYPE mapping. Earnings_release wins
priority over management_change when 2.02 + 5.02 co-occur, consistent
with the strategy's vocabulary intent.
- tests/unit/test_rule_parser.py: 7 new regression tests covering
AMD/MNST-style 2.02+9.01, dirty 'Item 2.02' / '2.02 - Results...'
forms, and negative cases (9.01-only, 2.03, 3.01 remain unknown).
Note: a follow-up vocabulary normalizer is still needed for the
Oracle-fallback path in apps/pipeline/event_parser/main.py:140, which
writes raw oracle_event.event_type values like 'earnings_result',
'shareholder_vote', 'regulation_fd' that don't match the strategy
vocabulary. Flagged for separate ticket.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Pre-market label_generator runs request future-dated price windows from
Stock Oracle, which correctly returns 404 because the data does not yet
exist. The labeler was swallowing this as label_status='unavailable' with
entry_date=None. Snapshot export then filtered these rows out, so live
PEAD trading silently lost candidates whose entry_dates fell on
later trading days (e.g., post-market 8-K filings late Friday → Monday
open entry). This explains today's missed RKLB/SNDK/AKAM/MNST/AMD/MRNA
even though their 8-Ks parsed correctly.
Changes:
- libs/labeler/label_generator.py: in 404/empty-bars path, when
entry_date >= today, preserve entry_date and mark label_status='pending'.
New log event label_price_pending_future_window distinguishes from real
data-unavailable failures (past dates still log label_price_unavailable).
- libs/export/snapshot_export.py: include 'pending' in the
label_status filter so today's not-yet-labeled events flow into the
live snapshot.
- apps/pipeline/label_generator/main.py: regeneration logic also
retries existing 'unavailable' rows whose entry_date is null or future
to recover events already mis-labeled in the DB.
- tests/unit/test_labeler.py: regression test reproducing the
RKLB/SNDK/AKAM failure mode and asserting label_status='pending' with
entry_date preserved.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- v7.356 config: swap dataset_snapshot_id from manual_only ftb_fix_v2 to
auto_full_rebuild base canonical so paper trader can refresh snapshot
(root cause of processed_events=0 for 30 days)
- Multi-session order isolation (1.A.2/1.A.3): tag client_order_id with
pt-{session_id[:8]}-{uuid} prefix on all entry orders; _cancel_stale_orders
filters by own session prefix so one session no longer ghost-cancels another's
orders on shared Alpaca account
- Pipeline halt on failure (1.B.1): _run_pipeline returns bool and stops on
first subprocess failure instead of silently progressing with stale data
- Daemon restart window skip (2.2): run_open/run_close only marked completed
if processed_phases DB confirms prior execution — no more trading-less days
after mid-day restart
- event_parser: periodic batch commits every 500 docs (hypothesis fix for
3h hangs; unverified — may just be slow serial Oracle calls)
- Tests updated for _verify_order_fill tuple return + new cross-session
isolation test; all 23 paper_trader unit tests green
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Paper trader: Alpaca broker fixes, catchup-thread state improvements
- Web GUI: intraday backtest duplicate run button, paper trading fixes
- Experiment registry: cleanup old v15/v16 experiments, update index
- Tests: Oracle client test additions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
12 tests covering all screener filters: min_price, min_atr_14,
min_avg_dollar_volume, date selection (latest-before, future excluded),
and the V23 quality filters min_atr_pct / max_atr_pct added last session
but previously untested.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests the stop evaluation loop that mirrors orb_simulator.py:477-580:
- Long/short stop_loss hit
- Breakeven promotion (stop moves to entry at 1R)
- trailing_tighten_at_r: verifies tight ATR multiplier fires at 2R vs
normal multiplier, exercising the tighten logic added in V23 port
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Bug: pending candidate DB records were only swept inside the "has open
positions" branch of run_eod_exit, so a server restart mid-day (ORB
detection ran, no breakouts, no positions) left candidates as "pending"
forever.
Fix: move the in-memory and DB pending sweep to run unconditionally before
the positions check.
Test: TestEodDbSweep verifies both code paths (no-position + in-memory).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests the three structural guards that were previously untested:
- Rolling loss filter: skip logic, boundary, window slicing, date exclusion
- Circuit breaker: 25% drawdown halts session
- max_simultaneous_entries: blocks new entries when at cap
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Delete v7.360-v7.363 experiment configs (rotation/momentum tests)
- Remove _schedule_momentum_breakout_candidates() from backtester run.py
- Remove MomentumBreakoutConfig from domain.py
- Delete momentum_calendar.py, momentum_screener.py, build_momentum_calendar.py
- Delete data/momentum_calendar/ parquet data
Valid period performance was -31.36% vs +152.4% baseline — sleeve is not viable
without walk-forward validation. Abandoning for now.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Backtester (run.py):
- cash_available = (self._cash + parking_value) * multiplier caused trades to be
approved even when self._cash ≈ 0 (all money in SGOV/QQQ). Trades executed
by deducting from self._cash → negative cash (phantom money).
- Fix: after simulate_entry, if self._cash < actual trade cost and parking exists,
call _liquidate_parking_for_cash(shortfall) before deducting from cash.
- Verified: 2022-2026 backtest with qqqm_low_dd shows 0 cash_negative events.
Live engine (engine.py):
- Add _parking_liquidate_for_event(): frees parking cash to fund event entries.
SGOV (virtual) reduces entry_value in DB; QQQM/QQQ sells real shares via broker.
- Both entry loops (engines mode + flat/reaction_close mode) now attempt parking
liquidation when plan.skip_reason == "insufficient_cash" before giving up.
Also includes prior session work (accumulated since last commit):
- 6 novel parking gate signals: VRP, Market Temperature, Hurst exponent, Rolling
Kurtosis, Return Autocorrelation, SPY-QQQ Correlation (composite risk score v2)
- QQQM parking symbol support (lower expense ratio vs QQQ)
- Snapshot auto-refresh + bar extension cache (pickle) to avoid 10-min re-fetches
- Bar extension clamps to last market-closed date (ET 4PM check)
- fithia2 refresh command; --no-refresh flag for paper backtest
- Paper backtest macro extension beyond last event date (parking-only periods)
- parking_state DB schema: 7 new columns (peak_price, gate_in_sgov,
committed_target, pending_target, pending_days, sgov_entry_value, sold_today)
- Live engine: target confirmation (2-day), top-up drawdown gate, trailing stop,
SGOV interest accrual, full 6-signal gate evaluation
- New PARKING_PRESETS: qqqm_low_dd, composite_v2, vv_24_vrp8, vt_24_t13, etc.
- Web GUI / CLI result parity fix (Oracle URL via get_settings().stock_oracle_url)
- Force-close uses last_exec_date (has bar data); parking liquidates at last_date
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Builds a full synthetic market data pipeline to test strategies against
12 diverse market regimes (bull/bear/crash/chop/rotation/liquidity drought)
that may not exist in historical data. Computes Regime Robustness Score (RRS)
to detect overfitting and environment-specific fragility.
- libs/backtest/scenarios/: price_gen, macro_gen, event_gen, coupling,
store_builder, scenarios (12 pre-built), robustness (RRS)
- apps/scenario/cli.py: `fithia2 scenario-test` with Rich output
- apps/tracker/cli.py: scenario-test command routing
- tests/: 83 unit tests across 3 new test files
- docs/scenario_test.md: usage guide and result interpretation
- docs/research_workflow_and_handoff.md: Step 5.5 scenario test added
Fix: no_signal scenario uses drift=0% (was +10%) for fair signal integrity scoring.
Fix: synthetic candidates now carry macro_vix/macro_hy_spread from macro_by_date
to pass selector engine filters.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- ReconciliationReport dataclass tracking orphaned/ghost positions and stale orders
- _cancel_stale_orders(): cancel leftover open orders at daily run start
- _reconcile_positions(): detect Alpaca vs local state mismatches; auto-close ghost positions with RECONCILED exit reason
- _verify_order_fill(): poll broker up to 2s to confirm market order fill before saving state
- _check_kill_switch(): activate and persist kill switch at 25% drawdown; blocks new entries
- run_daily() and _process_entries() wired with all safety checks
- 18 unit tests covering all reconciliation scenarios
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Track experiment cycles with SQS scoring (0-100), JSONL journal, and
auto-generated leaderboard to prevent duplicate experiments and enable
data-driven strategy decisions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove 5 non-alpha features (earnings surprise, risk penalty, parse confidence,
direction clarity, LM sentiment) from composite score to eliminate double-counting
with hard gates and noise sources. Redistribute weights to 5 alpha features.
Add default-deny for unknown event types, no-follow-through early exit (D+1),
kill switch log-only mode, macro regime size scaler. Remove SUE gate (Gate 8).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Flip scoring weights so event/document quality is primary signal (55%)
and market confirmation is secondary (35%). Add research mode with
kill-switch cooldown/reset, veto gates for bad events, reduced portfolio
risk, and 4 diagnostic analysis scripts.
Phase A: Research mode kill-switch reset, risk reduction (0.5%/trade,
max 4 positions), bullish-only direction for all event types.
Phase B: 2 new sub-scorers (parse_confidence, direction_clarity),
4 veto gates (oneoff risk, parse confidence, unknown/bearish direction).
Phase C: signal_quality, event_type_decomposition, kill_switch_impact,
concurrent_position analysis scripts.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace naive abs(reaction_day_return) fallback with a composite score
from 4 market microstructure features available at entry time:
1. Reaction quality (35%) — moderate positive return (PEAD zone) is
ideal; extreme positives penalized as "priced in"
2. Close strength (30%) — close near session high = buyers won
3. Volume conviction (20%) — 1.2-2x is healthy; >3x is exhaustion
4. Gap quality (15%) — small positive gap = orderly strength
Real data results (14 events, b1868603 snapshot):
- Score filters out 6 of 10 losers (DDOG -11.7%, META -9.1%, etc.)
- With threshold 0.5: return -2.63% → +0.27%, drawdown 4.24% → 0.86%
- Profit factor 0.44 → 1.16 (turns profitable)
- MSFT loss (-8.7%) is macro-driven, not predictable from stock features
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add `think: False` and `num_ctx: 8192` to Ollama payload:
Qwen3.5 extended thinking mode generated 1300+ internal reasoning
tokens before each response, adding 30-60s latency per LLM call.
Disabling it reduces parse time from 600s timeout to ~13s.
- Rewrite OllamaClient to use sync httpx.Client inside asyncio.to_thread():
Async httpx inside an active asyncpg SQLAlchemy session context on
Python 3.13 hung indefinitely. Synchronous httpx in a thread pool
completely isolates Ollama I/O from the asyncio event loop.
- Fix filing_poller to set issuer_id/symbol_id on Document records:
Missing FK caused feature_builder to reject all events with
event_no_symbol warning. Now looks up IssuerMaster/SymbolMaster
by ticker before creating Document rows.
- Update test_llm_client to mock _sync_call instead of _client attr.
- Raise ollama_timeout default to 600s for large document processing.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Oracle 서비스 어댑터 5개를 실제 API 포맷에 맞게 수정
- 모든 경로에 /api/v1/ prefix 추가
- price: data[] → bars 매핑, volume float→int
- filings: accession_number→accession_no, total_count→total
- financial: financial_data[] → periods, period_date 파싱
- finra: entries[] → data 매핑
- fred: data.observations 언패킹, value string→float (버그 수정 포함)
- fixtures 6개를 실제 Oracle 응답 포맷으로 전면 교체
- 통합 테스트에서 httpx_mock 완전 제거 → 실제 Oracle 직접 호출
- 신규 단위 테스트 3개 파일 추가 (logging, fred_service, llm_parser_stub)
- test_retries.py에 exhaustion 테스트 추가
- test_oracle_client.py에 connection/timeout/no-ctx 테스트 추가
- Phase 1/2 testing_checklist.md 실제 구현 기준으로 전면 재작성
- 전체 114 tests pass (unit 100 + replay 5 + integration 9)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- filing_poller: add --start-date/--end-date CLI args for historical backfill
(defaults to 7 days ago when omitted)
- OracleClient.get/post: apply with_retry(max_attempts=3) so transient
connection errors, timeouts, and 5xx responses are automatically retried
with exponential backoff (0.1s→0.2s→fail)
- financial_features: new compute_financial_features() extracting latest_eps,
latest_gross_margin, latest_operating_margin, eps_growth_qoq,
revenue_growth_qoq from FinancialDataResponse
- feature_builder: wire FinancialService into build_features_for_event(),
persisting financial_v1 FeatureSnapshot (non-fatal if unavailable)
- tests: 94 pass (81→89 unit + 5 replay); +8 new tests covering financial
features and retry success path
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>