On the last simulation day, parking was entered at EOD close price
(when _had_event_activity_today=True) and immediately liquidated at
close by end-of-backtest cleanup → entry == exit → PnL = 0.
Fix: force all six parking entry code paths to use "open" price when
date == last_simulation_date, so entry and cleanup-close are always
different prices.
Also adds _parking_cap logic in _extend_store_to_requested_window to
cap _requested_end_date at the last date where QQQM/TQQQ/SGOV all
have Oracle close-price data, preventing the simulation from including
days where macro is incomplete and the exit fallback would fire.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Previously close_position(..., fill_price=X) was silently swallowed by
**kwargs while the DB wrote the simulated exit_price — broker and ledger
drifted on every exit.
- AlpacaBroker.close_position drops the **kwargs sink; docstring documents
that callers must poll get_order(order.id) for the actual filled_avg_price
- _poll_exit_fill(order_id, symbol, timeout=30s) added; 1s interval, returns
actual Alpaca fill price, logs timeout/terminal status
- 3 exit sites now poll and write the actual fill + re-derive net_pnl
with direction-aware sign (short-safe for future short configs):
run_daily main exit path (simulate_exit)
_monitor_close (intraday stop/target hits)
_process_exits (scheduled & forced exits incl. partial T1)
- WARN-level "paper_engine_exit_fill_drift" when actual vs simulated
diverges >0.5% so drift is visible in logs even when non-pathological
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- _is_market_open() now queries Alpaca's get_clock() so holidays, early
closes, and halted markets no longer skip orders; falls back to weekday
9:30–16:00 ET only on broker error (1.B.3)
- AlpacaBroker.get_clock() + MarketClock dataclass wrapping alpaca-py's
TradingClient.get_clock()
- PaperTradingEngine logs scoring_model at session startup (WARNING level)
so multi-session daemon makes the live-path scorer dispatch explicit
in every boot log — verifies v7.356 config's return_max_long_v13e
actually reaches _compute_score (1.C.1)
Co-Authored-By: Claude Sonnet 4.6 <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>
Parking positions now use parking_state.avg_price instead of Alpaca's
blended avg_entry_price, which gets polluted when multiple sessions
share one broker account.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests momentum_20d, grav_pull_20_50, range_pos_52w, obv_slope_20 on V46's
284-trade set (400d). All signals collapse vs V24 base: best G2=0.118R
(momentum_20d) vs 0.291R on V24 and pre-committed gate of 0.30R.
Composite gate (2+ features ≥ 0.20R) also fails. Axis permanently closed.
V46's PEAD event catalyst selection fundamentally changes the ticker/entry
universe vs V24's pure momentum base — momentum signals non-transferable.
V47 requires new data sources (options flow, 13F institutional ownership).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- scripts/backfill_finra_short_volume_cdn.py: bulk backfill FINRA short
sale CDN files (400d) into short_sale_daily table (382K rows inserted)
- apps/intraday_bt/scripts/diag_orb_short_volume_v46.py: Phase 1 diagnostic
on V46 400d trade set (180 trades, 99% coverage)
- scripts/audit_short_volume_coverage.py: fix asyncpg date param types
Result: all three short-ratio features fail G2 (max +0.168R vs gate 0.30R).
Direction is INVERTED from Boehmer (short squeeze dominates over informed-bear
signal in gap-up ORB). V25 axis permanently closed. V46 terminal.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
V31 research findings (2026-04-22):
- Hard gate (max_gap_zscore_20d=1.0): 45.2% vs V24 95.3% — catastrophically bad.
All three terciles are profitable; hard rejection removes positive-EV trades.
- Negative weight (weight_gap_zscore=-0.05): 90.6% DD-12.33% Sh=2.649.
Signal too weak (G2 failed at 0.181R < 0.30R threshold). G2 ≥ 0.30R
validated as reliable promotion gate: OBV-slope (G2=0.394R) passed; all
signals below 0.30R failed in backtest.
All 7 signal axes exhausted — V24 is the peak for current feature library.
domain.py: add max_gap_zscore_20d param (no-op at None default)
orb_simulator.py: add gainers_leader hard-gate (no-op at None default)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Was using non-existent gap_pct key in enrichment dict; now computes from
today_open and prev_close fields. V30 results: hurst INVERTED+G2 FAIL,
ou_theta G1 FAIL (near-zero Pearson). gap_vs_market re-running as V30b.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
5 1-min microstructure features tested on V24 200d trade set (n=101).
range_coil_orb shows directional signal (Pearson=-0.128, WR gap +9.9pp)
but fails G1 (n=101 < 120) and G2 (avg_R gap 0.195R < 0.30R threshold).
p-value ~0.10 — insufficient for promotion. V24 remains champion.
Script fetches 1-min bars from Oracle and caches to data/cache/intraday_1min/.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Phase 1 diagnostic (diag_orb_short_volume.py) tests 3 short-ratio features
(prior-day, 20d avg, 20d z-score) on V24 200d trade set via FINRA CDN data.
All features fail all gates (|Pearson| ≤ 0.062, avg_R gap < 0.30R, WR gap < 5pp).
Direction inverts Boehmer 2020 hypothesis: high short ratio correlates positively
with ORB r_multiple (short-squeeze dynamics dominate at intraday ORB timescale).
V25 short-volume overlay not wired. V24 remains live champion.
Also adds scripts/audit_short_volume_coverage.py (Phase 0 DB coverage audit).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
V23 400d TRUE (correct pipeline, 2026-04-21): +146.09%, DD -13.66%, Sharpe 2.33.
Prior result (+120.87%, DD -23.97%) was from buggy AH-close pipeline; data fix
improved DD by 10.31pp. V23 now strictly dominates Safe v9 on ALL 400d metrics
(+45pp return, +3.5pp DD, +0.34 Sharpe). Updated Safe v9 status to
validated_200d_only and clarified Korean framing to remove the misleading
"최종 검증 전략" without qualification.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Should be actual_sym (defined in _parking_evaluate_gate scope),
not sym (which is only defined in _parking_buy).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
If Oracle is unreachable at 09:20 ET, without this check the pre-screen silently
waits through 5 chunks × 15s timeout (75s) before logging the empty-bars warning.
The new 3s probe logs a CRITICAL warning immediately so the operator can restart
Oracle before the market opens.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
os.kill(pid, 0) returns success for zombie (defunct) processes.
Added ps stat check — if process is in Z state, treat as dead and
clean up PID file so subsequent start() calls work correctly.
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>
- orb_simulator.py: min_abs_gap_pct filter, premarket dollar vol filter,
rolling_loss circuit breaker, drawdown_governor, streak_sizing,
trailing_tighten_at_r, allow_doji/red_to_green breakout, abs_gap scoring
for gainers_leader, ORBSimulationState, run_orb_simulation_with_state API
- metrics.py: loss_containment_score and related metrics
- features.py: enrich_daily_bars with gap_zscore, ATR ratio, range compression
- domain.py: extended ORBStrategyParams with new fields
- cache.py: DailyBarCache with merged parquet storage and coverage metadata
- simulator.py: base simulator updates for new entry/exit mechanics
- configs/intraday: updated orb_gainers_v23.yaml with canonical params
- Added BLD to midlarge symbol snapshot
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two fixes:
1. _rebuild_daily_from_intraday_cache now filters to regular market hours
(9:30–16:00 ET) before computing OHLCV. Previously used bars[-1] which
included after-hours data, distorting prev_close for gap calculations.
Root cause of V23 regression: HIMS Aug-4 after-hours drop to $54.81
made it appear as a +0.89% gap on Aug 5 instead of the correct -12.85%
gap (from $63.45 market close), causing it to fail min_abs_gap_pct filter.
V23 with fix: +109.32%, WR 58.1%, Sharpe 3.01, DD -12.91%
2. Remove temporary debug instrumentation (HIMS/2025-08-05 trace blocks)
that was left in orb_simulator.py during regression investigation.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
_parking_evaluate_gate() was returning only QQQM or SGOV, never TQQQ,
because the low-vol overlay logic (_evaluate_low_vol_overlay_target in
backtester) was not implemented in the live engine. Add overlay check
at the end of the gate: vol threshold, temperature, entropy, and Hurst
R/S analysis — matching the backtester's conditions exactly.
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>
- run_eod_exit now queries DB for any pending candidates not in-memory
(guards against server restart mid-day leaving zombie pending records)
- Remove compound_returns=True force-override; live engine doesn't use it
and V23 config has compound_returns=false
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- screener.py: add min_atr_pct/max_atr_pct filters to live_pre_screen
- engine.py: prepend regime ticker (QQQ) to bar fetch so regime filter works
- engine.py: add rolling loss + account circuit breaker at run_orb_detection
- engine.py: patch today_open from first 1-min bar so regime gap is real
- engine.py: explicit regime + breadth filter before compute_orb_candidates
- engine.py: max_simultaneous_entries guard in run_breakout_check
- engine.py: _compute_sizing_capital with daily_budget_reset (fixed $10k base),
drawdown governor, and streak sizing (win bonus / loss penalty)
- engine.py: trailing_tighten_at_r in run_stop_check (tight multiplier at 2R)
Bug fixes in _compute_sizing_capital:
- streak direction: remove reversed() so outcomes[0] = newest trade
- daily reset: use initial_equity as base (not growing equity), matching V23
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Stage A for V28 (attention-axis second sleeve) exploration.
Probes existing orb_attention cache against V23 trade outcomes.
Result: ABORT — cache miss 35-43% on V23's traded (ticker, date) pairs;
only n=9 trades hit wiki>=1.5 across full 400d run (p=0.166, not significant).
Stage A inconclusive due to sparsity on V23's trading domain, not signal noise.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Make _parking_buy async (asyncio.sleep instead of time.sleep) and extend
confirmation from 5s to 30s per attempt with up to 3 retries on timeout.
On timeout, cancels the stale order before retrying with fresh price data.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
New mode (risk.daily_budget_reset=True) where cash_available and sizing
equity reset to initial_equity at the start of each day, regardless of
how many open positions or realized P&L exist. Unlike fixed_capital_sizing
(단리, sizing only), this also treats buying power as if no positions are
held — useful for evaluating signal quality independent of capital constraints.
- domain.py: daily_budget_reset field on RiskConfig
- run.py: _daily_budget_reset flag; _sizing_equity / _sleeve_equity_est /
_build_portfolio_state all honor the new flag
- backtest_sim.py: daily_budget_reset param threaded through
- direct_runner.py: --daily-budget-reset CLI flag
- routers/backtest.py: BacktestRequest field + cmd arg
- client.ts: BacktestParams / BacktestTask types updated
- Backtest.tsx: checkbox in form + DBR badge in task list
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
All five build_planned_order() calls in apps/paper_trader/engine.py were
missing execution_config, causing build_planned_order to fall back to
base config.execution and silently ignore per-engine target_1_r_override,
target_1_fraction_override, max_holding_days, tiered-target settings, etc.
The backtester has always passed execution_config=_build_effective_execution_config()
(run.py:2210). This divergence caused paper trading to compute wrong target
prices and partial-exit fractions — e.g. AVGO entered with target_r=1.5
(base) instead of 3.0 (engine override), triggering a premature partial
exit on 4/15 that the backtest never produced.
Fix: add execution_config=build_effective_execution_config(candidate, self._config)
to all five call sites and hoist the function to the module-level import.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add Copy button per run row in Run History table; opens pre-filled RunConfigPopup
with original run's period/universe/compound_returns settings
- Make RunConfigPopup larger (500px wide) and more spacious with proper header/X button
- Prevent dialog from closing on backdrop click; only Cancel or X button closes it
- Range date inputs laid out side-by-side in 2-column grid
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- When _parking_liquidate_for_event returns False but parking had shares
(sell failed due to transient Alpaca error), skip without recording so
event retries on next run_next_open instead of being permanently blocked
- Improve parking_sell_for_event_failed log: include exc_type, symbol, qty
so we can see the actual exception (was silently swallowed with empty msg)
- Also deleted AVGO from processed_events so it retries tomorrow
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>