Skip to content

Codebase analysis: findings report (no code changes)#2

Draft
Copilot wants to merge 1 commit intofeature/comprehensive-improvementsfrom
copilot/analyze-and-criticize-again
Draft

Codebase analysis: findings report (no code changes)#2
Copilot wants to merge 1 commit intofeature/comprehensive-improvementsfrom
copilot/analyze-and-criticize-again

Conversation

Copy link

Copilot AI commented Mar 1, 2026

Deep audit of the ensemble branch (feature/comprehensive-improvements) to identify remaining issues after three prior audit rounds. No code was changed — this PR documents findings only.

Confirmed fixed (from prior audits)

All original P0 execution bugs resolved: per-position _update_equity, stale-position closing in reconcile_target_weights, equity snapshot before reconciliation loop, sell weight_change sign, purged walk-forward CV replacing iloc split, LightGBM early stopping, risk engine initialization, bracket leg preservation, bridge created once outside loop, fill verification polling.

Remaining issues found

High

  • _cancel_existing_sl_tp_orders cancellation logic is inverted (live_bot.py:357): None is included in the order_class allowlist, so any sell-side order without an explicit class (regular limit sells, manual orders) gets cancelled. Only orders with a recognized bracket class (oco, oto, bracket) should be cancelled.

Medium

  • Active feature columns not winsorized: mom_12_1, mr_zscore_60, sector_rel_mom are in FEATURE_COLS but absent from _WINSORIZE_COLS in features.py. Outliers in these flow raw into training and inference.
  • HMM normal state runs at 70% exposure (hmm_regime.py:70): Permanent 30% cash drag in baseline market conditions. Makes A/B comparison with Bot A (full exposure) structurally unfair and depresses returns mechanically.
  • Ensemble IC gate fails the whole ensemble when only stacking fails (ensemble.py:365): When _fit_meta_learner has insufficient OOS data, validation_ic stays 0.0 and the quality gate (< 0.02) triggers equal-weight fallback — even though the base models may have positive individual ICs.
  • _has_traded_today fails closed silently on broker error (live_bot.py:522): Transient API errors at startup cause the bot to skip the cycle entirely with only a log line — no CRITICAL alert fired.
  • ATR comment/code mismatch (live_bot.py:119–125): Comment documents 3x SL / 5x TP; live defaults are 2x / 3x.
  • Confidence sizing uses min-max normalization (predict.py:768): Single outlier score collapses all others toward zero, concentrating conviction weight and undermining HRP diversification. Rank-based normalization is more robust.

Low

  • No Bonferroni correction in drift detection: 11 KS tests at p=0.01 → ~10.5% false-positive rate per cycle.
  • Module-level globals read by Telegram thread without locks (predict.py:83–88): _last_drift_report, _last_raw_ohlcv, _last_prediction_scores written by main loop, read by polling thread — no synchronization.
  • HMM re-fetches SPY 3mo on every rebalance cycle (live_bot.py:1464): Redundant HTTP call; could slice the already-fetched 2y SPY data from initialization.
  • MLflow run nesting risk (predict.py:1027): Drift start_run inside get_ml_weights could become a child of an unclosed training run on exception paths.
  • base.py reconcile_portfolio target_weight=0 skip (original Finding #6): execution.py was fixed; BaseBroker.reconcile_portfolio was not reviewed — status unconfirmed.
  • sector_rel_mom universe mismatch: Cross-sectional feature computed on a slightly different ticker universe at inference vs. training due to min-history filtering — structural (non-stochastic) drift.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link

vercel bot commented Mar 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboard Error Error Mar 1, 2026 1:25am

Copilot AI changed the title [WIP] Analyze and criticize existing codebase for improvements Codebase analysis: findings report (no code changes) Mar 1, 2026
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.

2 participants