93 Commits (0928eb2428f0fac27a5ac88f8ee88befcc4ceb0a)
 

Author SHA1 Message Date
I Luk Kim 0928eb2428 Fix direct backtest mode UX: live log, inline results, trade table sort/filter
- Fix log endpoint to serve .direct.log for direct mode tasks
- Fix _parse_dates: 4-digit start with no end now defaults to today
- Fix frontend year mode to send start=YYYY-01-01 instead of year param
- Replace DirectModePanel with DirectModeTaskView: live terminal log while
  running, inline results (metric cards + equity chart + trade blotter) on
  completion, collapsible log
- Add trade table sort/filter: symbol, engine, exit reason filters, Win/Loss
  toggle, sortable columns (No., PnL, entry/exit price), stats bar
- Add No. column showing original trade order for sort restoration
- Add BacktestDirectResultsPage at /backtest/direct-results/:taskId
- Add Results button in task list for has_direct_result tasks

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
5 months ago
I Luk Kim c5dea9a9a8 Add Paper Trading web GUI with ANSI terminal log rendering
- Full paper trading page (sessions sidebar, 5-tab detail view)
- Auto daemon panel: status, schedule, start/stop, live log
- Auto daemon detection for terminal-started processes via psutil scan
- Log source detection: process stdout file → web GUI log file → TTY hint
- ANSI color rendering for paper task logs and auto daemon log
- Dark terminal theme (matching backtest log style) with macOS traffic lights
- Extracted ansiToHtml to shared lib/utils.ts (deduped from Backtest.tsx)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
5 months ago
I Luk Kim 7df99447ee Register named strategies on leaderboard
conviction_v6new.307 (SQS 74.4 #1), core_boost_v6new.288 (72.8 #3),
entropy_safe_v6new.196 (72.6 #6) — now visible by name on leaderboard.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 8dfebcf5fe Add v6new.311-322, named strategy configs, and tracker common_window fix
- v6new.311-322: latest experiment iterations
- Named configs: baseline, conviction, core_boost, docgate, entropy_safe, quick_cut
  (derived from best-performing v6new variants for production reference)
- Rename v6new.29_mom2 → baseline_v6new.29
- tracker show: add common_window_summary field
- Journal: update leaderboard, experiment registry, improvement journal

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim f56b353c8b Update README: paper trading operations and Phase 6 reconciliation docs
- Add full paper trading CLI reference (create, list, run, positions, trades, close)
- Document reconciliation safety system (orphaned/ghost detection, stale orders, fill verify)
- Document kill switch (25% drawdown threshold, manual reset required)
- Expand paper backtest section with --overlay and --rank options

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 98923e8620 Add Phase 6 reconciliation: position integrity, kill switch, order fill verification
- 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>
5 months ago
I Luk Kim 76581ead04 Remove overlay backtesting and scoring 5 months ago
I Luk Kim 1d9507540b Add strategy aliases to key experiment configs
baseline(v29), docgate(v122), entropy_safe(v196), conviction(v307) etc.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 902b7d99b8 Add v6new.307: SQS 74.4 #1, CW 350.2% — high-WR engine risk boost
Boosting inline/guidance engine per_trade_risk from 0.015-0.020 to 0.040.
These engines have 73-100% WR — bigger positions on best signals.

v6new.307: SQS 74.4 (#1), CW 350.2%, Test +46.8%, MaxDD 2.4%, PF 14.74

Full progression: 262.9% → 284.4% → 312.6% → 320.5% → 350.2%

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 30eb311443 Add v6new.288: SQS 72.8 #1, CW 320.5% — core risk up + budget downsizing
Boosting core engine (WR 84%) per_trade_risk from 0.038 to 0.045 with
allow_budget_downsizing=true. Higher conviction = bigger positions on
the best engine. Budget downsizing prevents cash rejections.

v6new.288: SQS 72.8 (#1), CW 320.5%, Test +45.6%, PF 14.54

Progress: 262.9% → 284.4% → 293.2% → 312.6% → 320.5%

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim b00f87b6b0 Add uv.lock for reproducible dependency resolution
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 493b8a8d69 Add --overlay shorthand for lb command and gitignore *.db files
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim a81b3a6ac4 Update tracker, leaderboard, docs, and overlay leaderboard
Additional tracker/leaderboard updates, overlay leaderboard, and
documentation improvements.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 2aba6418e6 Add overlay engine, ranking models, snapshot pipelines, and research tools
New libs: overlay curve builder, ranking models, continuation/merged
snapshot export, intraday features. New tools: overlay evaluator,
ranking model builder, deep evaluation, fullsplit batch runner.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 9b92ab6589 Add paper trading system: broker integration, state management, reporter
New modules for live/mock broker interface, SQLite session state,
auto-trading engine, and backtest result reporting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 479eb76308 Update tests for pipeline, backtest engine, paper trader, and new modules
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 320a9d19df Clean up rank 100+ strategies and obsolete files
Removes experiment configs for strategies below leaderboard rank 100,
deletes obsolete PER-v1 strategy notes, and updates leaderboard/registry.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim ce2150789d Fix leaderboard performance regression (60min → 12s) and clean up CLI help
Replaces per-experiment rglob with single-pass manifest/metrics indexing
and adds lru_cache. Removes rarely-used commands from help display.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 057a311572 Improve paper backtest: overlay support, --top/--rank/--year options, speed optimization
Adds overlay strategy backtesting, flexible date parsing, --no-trades flag,
--rank range selection, session management improvements, circuit breaker
for screener failures, and bars_cache passthrough for 10x speed gain.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 784c581f19 Enhance backtest engine: v11 scoring, selector expansion, snapshot store improvements
Extends selector with new scoring model support, adds execution
enhancements, and improves snapshot store loading and split handling.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 57d38ecfe0 Add earnings surprise feature pipeline and snapshot export improvements
Adds earnings surprise extraction to parser/features/labeler pipeline,
improves filing fetcher robustness, and extends snapshot export with
new field support.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim bc4ffecb10 Add v6new.275: SQS 72.7 #1, CW 312.6% — OME early fail day 1
OME engine early_failure_no_progress_days=1 (from day 2 in v272) further
improves capital recovery speed. 198 trades, 312.6% CW return.

SQS 72.7 = new #1 on leaderboard (including overlays).
Test return +45.5%, Profit Factor 19.23.

Key: cutting OME losers at day 1 instead of day 2 frees capital faster
while losing only marginal OME winners that needed >1 day to show progress.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 165424ecc2 Add v6new.272: CW 310.8% breakthrough via OME early failure cut
Trade analysis revealed OME engines had 54-60% WR with stop-heavy exits.
Adding early_failure (day 2, R=0.0) for OME engines frees capital faster,
enabling 6 more trades (194→200) and boosting CW from 293.2% to 310.8%.

Key insight: cutting low-quality engine losers early improves compounding
more than any scoring/feature/sizing change tested in this session.

v6new.272: SQS 72.4 (#6), CW 310.8%, 200 trades, test +44.9%

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 7676ef7867 Register v6new.255 on leaderboard (SQS 72.2, #9, CW 293.2%)
Higher risk (0.069) + tighter stops (ATR 1.45) produce best CW return
but lower SQS than v6new.196 (72.6) due to WFV instability.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 1c38415cb7 Add v6new.265-268: small-cap expansion experiments
Lowering market cap floors to 2B added 15 trades (194→209) but CW return
dropped from 293.2% to 278.5%. Small-cap PEAD events have lower average
quality — individual outliers like SEDG exist but don't compensate.

v6new.255 (293.2%) confirmed as optimal trade-quality balance.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim e2229646e6 Add oversold bounce engine experiments (v6new.259-264) — blocked by architecture
Bounce engine (buy negative reaction, bet on mean reversion) could not
execute: system architecture ties scoring to single model per backtest,
and selector/store indexes are optimized for positive-reaction PEAD.
Negative-reaction candidates get score=0 from PEAD scoring, blocking
engine selection regardless of engine-level threshold overrides.

Implementing bounce trades requires: dual scoring model support,
selector changes for negative-reaction candidate routing, and
store indexing changes. Deferred to future refactor.

Current best CW return: 293.2% (v6new.255)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 74244b15d2 Add v6new.224-258: grid search risk×ATR toward 300% CW
Best: v6new.255 (293.2%) = risk 0.069 + ATR 1.45 + entropy + doc 0.50
ATR 1.45 is critical threshold — below it loses 1 trade and drops to 269%.
Risk 0.069 is max before trade loss at 0.070.

Progress: 262.9% → 284.4% → 288.3% → 290.4% → 291.8% → 293.2%

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 672098c077 Add v6new.215-223: three-way parallel search toward 300% CW
Best: v6new.220 (289.6%) = risk 0.065 + max_pos_value 1.5 + ATR 1.6.
194 trades fixed — event count is the structural bottleneck.
Management_change/oneoff relaxation hurt. Budget/leverage neutral.
300% requires fundamentally more trades or higher per-trade returns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 6dee2c24d2 Add v6new.197-214: parameter grid search around v196
Best CW return: v6new.207 (288.3%) = v196 + risk 0.060 + ATR 1.6.
Public SQS: v6new.196 (72.6) still best — v207 is 72.5.
ATR 1.6 is optimal stop distance. Sector limit increase hurts badly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim cc953949f1 Add v6new.196: new best SQS 72.6 (#3) — v29+entropy+risk+doc_quality
v6new.196 = v29 base + entropy scoring (v13e) + per_trade_risk 0.058
+ doc_quality 0.50. CW return 284.4% (+21.5pp over v122), 194 trades.

Key finding: v29 base with doc_quality 0.50 (not 0.55) is the optimal
quality gate when combined with entropy scoring.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 090bfa8e36 Add contrarian feature analysis + v15 scoring (v6new.174-188)
Data analysis revealed OBV Q1 (distribution) has 56.4% WR vs Q5 51.2% —
contrarian signal confirmed. Previous OBV bonus was applied in wrong
direction. Corrected with v15 scoring models.

Best result: v6new.185 (entropy + risk 0.058) CW 274.4% but SQS 72.2,
still below v6new.122 (72.4). WFV/robustness offsets CW gains.

v6new.122 confirmed as optimal under current SQS v4 formula.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 95c6b499c4 Add missing experiment configs v6new.129, 160-162
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 1e66b67c7a Add technical/scientific feature experiments (v6new.106-173) and v6new.122 SQS 72.4
Tier 1: Vol/RSI/BB/OBV features — sizing scalers hurt public SQS, scoring
adjustments ineffective on 28-30 trades. Only doc_quality gate lowering
(0.66→0.55) improved results (+2 trades, +0.8 SQS).

Tier 2: Hurst exponent, Shannon entropy, sector momentum — entropy bonus
CW +10.7pp but SQS equivalent (72.3 vs 72.4). Sector momentum hurt badly.

Tier 3: OU theta, gravitational pull, market temperature — all caused
large CW return drops (-80 to -103pp). Physics-based indicators don't
fit event-driven PEAD.

Best result: v6new.122 (SQS 72.4, #3 leaderboard) = v6new.29 + doc quality
gate 0.66→0.55. Single parameter change outperformed all feature engineering.

New code:
- libs/features/market_features.py: 9 new features (vol, RSI, BB, OBV,
  Hurst, entropy, OU theta, gravitational pull, market temperature)
- libs/backtest/scoring.py: v12-v14 scoring models with technical gates
- libs/backtest/allocator.py: volatility + conviction size scalers
- libs/backtest/domain.py: volatility_size_scaler + conviction_boost config
- scripts/enrich_*.py: snapshot enrichment scripts
- 68 experiment configs (v6new.106-173)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 83c7a66f77 Add v6new.37-38: final tuning attempts — v6new.30 confirmed as optimum
v6new.37 (prune 2 weak engines): +106.55% — neutral (+0.10%)
v6new.38 (boost top engines): +96.55% — worse (-9.90%, capital starvation)

38 experiments complete. v6new.30 is the confirmed framework optimum.
Paper BT: +106.45%, 48 trades, 67% WR, MaxDD 3.35%, Sharpe 3.66

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim daa8536546 Add v6new.36: mean reversion engine for high-VIX drops
New engine: next_open_long_mean_reversion_high_vix
  Targets: react < -7%, close 0.15-0.60, bearish/mixed/unknown direction
  Signal: VIX>20 + big drop = 62.9% WR, +3.91% 5d mean (n=167)
  VIX 25-30 sweet spot: 75% WR, +5.46% 5d mean

Test split: 3 MR trades, 67% WR, +5.59% total PnL
Paper BT: 51 trades vs 48 (v6new.30), return ~equal

Also fixes _rows_to_table to handle sparse feature columns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 16613f1758 Fix _rows_to_table to collect keys from ALL rows, not just first
Previously only used rows[0].keys() — columns present in later rows
(like earnings_surprise_pct from sparse features) were silently dropped.
Now collects all unique keys across all rows.

YoY earnings surprise tested: WR spread only 2.5pp (55.2% vs 52.7%).
Not actionable — YoY growth != analyst consensus surprise.
v6new.30 remains the framework optimum.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim fecdc12007 Add earnings surprise feature pipeline and v11 scoring
New data source integration:
- EarningsSurpriseService: GET /api/v1/earnings/surprise/{symbol}
  Returns actual vs estimated EPS with surprise_percentage
- Feature builder: creates earnings_surprise_v1 snapshots for earnings events
- Backfill script runs for existing 1,273 tickers (Alpha Vantage rate limited)

New scoring (v11):
- Small beat (0-3% surprise): +10% bonus (82.4% WR in sample)
- Medium beat (3-8%): +5% bonus
- Big beat (>8%): no bonus (already priced in)
- Miss (<=0%): -5% penalty

Signal validation (n=66 sample):
  Small beat: 82.4% WR, +1.79% mean 5d return
  Big beat: 54.8% WR, +0.47%
  Miss: 55.6% WR, -0.10%

Backfill running (~4 hours). Experiment pending data completion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim e8241d2924 Test execution model + short side — both rejected, v6new.30 confirmed
Short Side (Direction 3):
  Bearish events: 45-55% WR for short — no actionable edge
  Mean reversion after large drops cancels short PEAD

Execution Model (Direction 2):
  T+2 delayed entry: loses 54% of alpha (Day 1 = 54% of 5d return)
  Wider stops (v6new.34): -0.68pp — smaller positions offset fewer stop-outs
  Tighter trailing (v6new.35): -12.48pp — cuts winners too early
  reaction_close >> next_open (86% vs 57% WR) but post_market can't use RC

Direction 1 (new data: Form 4, XBRL, Earnings Surprise) requires Oracle API
implementation. Free sources identified: SEC EDGAR, Alpha Vantage, FINRA.

v6new.30 is the confirmed framework optimum.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim f2b3b57b3a Update v6new.30 on refreshed snapshot — SQS 62.3, WFV 100% positive
Pipeline refreshed: 528 new filings, 240 new events processed.
Snapshot re-exported with start_date=2022-03-01: 9350 rows (+230 vs old).
Test split now extends to 2026-03-23 (was 03-13).

v6new.30 on fresh data:
  SQS: 62.3 (down from 63.8 — OOT worst -4.61% from new period data)
  Train: 117 trades, +59.31%, SQS 92.6
  Valid: 33 trades, +41.05%
  Test:  27 trades, +34.09%
  WFV:   100% positive (worst +1.08%)
  OOT:   90.0% positive (worst -4.61%)
  Paper BT (1yr): +93.41%, 50 trades

Strategy holds up on fresh data with 100% WFV positive rate.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 85515f2db9 Add v6new.31-33: parameter tuning — all neutral/worse, v6new.30 confirmed optimal
v6new.31 (all OME risk reduced): +105.23% — worse, mixed_ome/other_material_mixed need full risk
v6new.32 (patient risk only): +108.15% — marginal, not worth
v6new.33 (core warmup 10): +108.62% — identical to v6new.30

v6new.30 (+108.62%, Sharpe 3.77, SQS 63.8) is the framework optimum.
Further parameter tuning yields diminishing/negative returns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim b6ea2a4b50 Add v6new.29-30: OME risk experiments — v6new.30 Paper BT +108.62%
v6new.29 (OME disabled): +104.75%, 30 trades, 90% WR — high quality but fewer trades
v6new.30 (OME risk further reduced): +108.62%, 45 trades, 71% WR, Sharpe 3.77
  - unknown_ome: 0.008→0.004
  - other_material_unknown: 0.003→0.002
  SQS: 63.8, WFV 100% positive, OOT 90% positive

Leaderboard: v6new.27 #1 (63.9), v6new.30 #2 (63.8)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 2a82c1e13c Record v6new.27 SQS 63.9 — new #1 validated by both SQS and paper backtest
Full integrated verification:
  SQS: 63.9 (vs v6.29 62.8, v6new.9 63.3)
  Train: 121 trades, +55.87%, SQS 91.3
  Valid: 22 trades, +42.23%, SQS 89.6
  Test:  27 trades, +64.22%, SQS 89.8
  WFV:   100% positive (worst +0.63%), mean +10.06%, gap 10.00%
  RM:    84.4% positive, worst -2.34%
  OOT:   90.0% positive, worst -0.84%
  Paper BT (1yr): +105.35%, MaxDD 3.35%, Sharpe 3.73, 45 trades, 71% WR

First strategy validated by BOTH backtester SQS AND paper backtest
using the unified engine system (no divergence between systems).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim dc16a1f88b Add v6new.28 (marginal) — v6new.27 confirmed as optimal at +105.35%
v6new.28: further recovery risk 0.0035→0.002 → +105.77% (marginal +0.42%)
v6new.27 is the sweet spot: +105.35%, MaxDD 3.35%, Sharpe 3.73

Session summary:
- 28 strategy experiments, 6 infrastructure fixes
- Paper trader unified with backtester (6 divergences resolved)
- Final strategy: v6new.27 (v6.100 base + OME risk reduction)
- Paper BT validated: 96% trade-by-trade match with backtester

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 1f996dfc8e Add v6new.25-27: paper-backtest-driven strategy improvement
v6new.25 (v6.29 base): OME risk halved → Paper BT +94.38% (vs +93.60%)
v6new.26 (v6new.25 on v6.100 snapshot): +93.75%
v6new.27 (v6.100 + further OME reduction): Paper BT +105.35%, MaxDD 3.35%, Sharpe 3.73
  - other_material_unknown: 0.005→0.003
  - unknown_ome: 0.012→0.008

All improvements validated by paper backtest (unified engine, same as backtester).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 7a2001a4fa Add v6new.25: OME risk halved — paper BT +94.38% beats v6.29 +93.60%
Based on paper backtest loss analysis (not backtester SQS optimization):
- OME engines contribute only +$1,405 on 8 trades but generate most losses
- Halving OME per_trade_risk reduces loss magnitude without removing trades
- Paper BT: +94.38% vs v6.29 +93.60%, MaxDD 4.07% vs 4.60%
- WFV: 100% positive fold rate (worst +0.02%)
- RM worst: -0.88%, OOT worst: -0.33%
- SQS: 62.9 (vs v6.29 62.8)

This is the first strategy improvement validated by BOTH backtester SQS
AND paper backtest return, using the now-unified engine systems.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 529477727f Add score and event_type to trade blotter output
FilledTrade now carries event_type and score from the Candidate.
These fields are written to trade_blotter.parquet and displayed in
paper backtest trade logs.

Previously score showed as 0.00 for all trades because the field
wasn't propagated from Candidate → FilledTrade → Parquet.

Score=0.00 is valid for trades from engines with score_threshold_override=0.0
(e.g. guidance_unknown_orderly) where engine gates, not score, determine entry.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 07bcfbe51d Complete engine unification Phase 5-6: residual reserve + macro data
Phase 5 — Engine selection (both entry paths):
  - Added residual_reserve_selected tracking between engines
  - Added prelimit amplification (5x) for attention-requiring engines
  - Added truncate_to parameter to select_candidates calls
  Matches BacktestRunner._select_candidates_for_date() behavior.

Phase 6 — Macro data:
  - Added FRED series fetch (VIXCLS, BAMLH0A0HYM2) to _fetch_macro()
  - Matches SnapshotStore._fetch_macro() which loads from MacroObservation DB
  - Enables VIX/HY regime sizing in live paper trading

All 6 phases of BacktestRunner ↔ PaperTradingEngine unification complete.
450 unit tests pass. Multi-strategy paper backtest verified.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim 26ca89c058 Integrate shared trade logic into PaperTradingEngine (Phase 3-4 complete)
PaperTradingEngine now uses:
1. AttentionFilterService after select_candidates (2 entry paths)
   - run_reaction_close: attention filtering added
   - run_next_open: attention filtering added
2. build_effective_execution_config via _resolve_execution_config delegation
   - Replaces 60-line inline implementation with shared function
   - Adds adaptive exit support (was missing)
   - Adds event_type_profile max_holding_days (was missing)
3. check_next_open_gap_cap before order submission
   - Rejects excessive gap-up entries (was missing)

This eliminates divergences #2 (attention), #3 (execution config),
and #4 (gap cap) from the unification plan. All 450 tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim fb4fec7dac Unify BacktestRunner and PaperTradingEngine trade decision logic
Phase 1-4 of engine unification to eliminate research/live divergence.

Phase 1 — Scoring (event_detector.py):
  EventDetector now uses config's scoring_model (v5/v9 etc.) when
  event_v1 features are present (parse_confidence_overall not null).
  Falls back to compute_entry_score only for incomplete events.

Phase 2 — Execution config (execution.py):
  Extracted build_effective_execution_config() as shared function.
  BacktestRunner delegates to it. PaperTradingEngine can now use
  identical per-engine overrides, adaptive exit, tiered targets.

Phase 3 — Attention filtering (attention.py):
  New AttentionFilterService class extracted from BacktestRunner.
  Provides: engine_requires_attention, apply_filters, rescoring.
  BacktestRunner now delegates to this service.
  PaperTradingEngine can import and use the same service.

Phase 4 — Gap cap (execution.py):
  check_next_open_gap_cap() shared function for next-open gap rejection.

All 450 unit tests pass. Paper backtest verified working.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago
I Luk Kim c747d5e4f0 Fix snapshot path resolution for paper backtest
Snapshots can be in data/parquet/ or data/datasets/snapshots/.
Now tries default parquet_dir first, falls back to data/datasets/snapshots/
if the snapshot exists there instead.

Fixes FileNotFoundError when running multi-strategy paper backtest with
configs that reference snapshots in the alternate directory.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 months ago