Commit Graph

187 Commits

Author SHA1 Message Date
Youssef Aitousarrah c792b17ab6 fix(discovery): fix three scanner hang/validation bugs found in ranker_debug.log
1. executor.shutdown(wait=True) still blocked after global timeout (critical)
   The previous fix added timeout= to as_completed() but used `with
   ThreadPoolExecutor() as executor`, whose __exit__ calls shutdown(wait=True).
   This meant the process still hung waiting for stuck threads (ml_signal) even
   after the TimeoutError was caught.  Fixed by creating the executor explicitly
   and calling shutdown(wait=False) in a finally block.

2. ml_signal hangs on every run — "Batch-downloading 592 tickers (1y)..." never
   completes. Root cause: a single yfinance request for 592 tickers × 1 year of
   daily OHLCV is a very large payload that regularly times out at the network
   layer. Fixed by:
   - Reducing default lookback from "1y" to "6mo" (halves download size)
   - Splitting downloads into 150-ticker chunks so a slow chunk doesn't kill
     the whole scan (partial results are still returned)

3. C (Citigroup) and other single-letter NYSE tickers rejected as invalid.
   validate_ticker_format used ^[A-Z]{2,5}$ requiring at least 2 letters.
   Real tickers like C, A, F, T, X, M are 1 letter. Fixed to ^[A-Z]{1,5}$.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 22:35:42 -08:00
Youssef Aitousarrah ce2a6ef8fa fix(discovery): fix infinite hang when a scanner thread blocks indefinitely
Two issues caused the agent to get stuck after the last log message
from a completed scanner (e.g. "✓ reddit_trending: 11 candidates"):

1. `as_completed()` had no global timeout. If a scanner thread blocked
   in a non-interruptible I/O call, `as_completed()` waited forever
   because it only yields a future once it has finished — the per-future
   `future.result(timeout=N)` call was never even reached.
   Fixed by passing `timeout=global_timeout` to `as_completed()` so
   the outer iterator raises TimeoutError after a capped wall-clock
   budget, then logs which scanners didn't complete and continues.

2. `SectorRotationScanner` called `get_ticker_info()` (one HTTP request
   per ticker) in a serial loop for up to 100 tickers from a 592-ticker
   file, easily exceeding the 30 s per-scanner budget.
   Fixed by batch-downloading close prices for all tickers in a single
   `download_history()` call, computing 5-day returns locally, and only
   calling `get_ticker_info()` for the small subset of laggard tickers
   (<2% 5d move) that actually need a sector label.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 22:14:53 -08:00
Youssef Aitousarrah 6a9a190af5 fix(ui): fix signal cards rendering as raw HTML in Streamlit
Two bugs were causing the signal card HTML to display as literal text:

1. CommonMark HTML block termination: Streamlit's markdown parser
   (CommonMark-compliant) terminates a <div> block at the first blank
   line. Empty optional fields (name_html, desc_html, risk_badge_html)
   left whitespace-only lines in the f-string template, ending the HTML
   block and causing the parser to render subsequent tags as text.
   Fixed by building HTML from a parts list and only appending optional
   elements when non-empty — no blank lines can appear in output.

2. Unescaped HTML chars in LLM-generated text: reason fields from the
   ranker contained raw > and & characters (e.g. '>5% move',
   '50 & 200 SMA') that corrupted the HTML structure. Fixed by running
   all LLM-generated fields through html.escape() before interpolation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 11:33:15 -08:00
Youssef Aitousarrah 07851feeda Update 2026-02-20 08:53:37 -08:00
Youssef Aitousarrah 0420e84283 Update 2026-02-20 08:44:03 -08:00
Youssef Aitousarrah 8e2392029a Update 2026-02-20 08:39:37 -08:00
Youssef Aitousarrah ec8309a34e Update 2026-02-20 08:38:15 -08:00
Youssef Aitousarrah 1c20dc8c90 feat: improve all 9 scanners and add 3 new scanners
Phase 1 - Fix existing scanners:
- Options flow: apply min_premium filter, scan 3 expirations
- Volume accumulation: distinguish accumulation vs distribution
- Reddit DD: use LLM quality score for priority (skip <60)
- Reddit trending: add mention counts, scale priority by volume
- Semantic news: include headlines, add catalyst classification
- Earnings calendar: add pre-earnings accumulation + EPS estimates
- Market movers: add price ($5) and volume (500K) validation
- ML signal: raise min_win_prob from 35% to 50%

Phase 2 - New scanners:
- Analyst upgrades: monitors rating changes via Alpha Vantage
- Technical breakout: volume-confirmed breakouts above 20d high
- Sector rotation: finds laggards in accelerating sectors

All 12 scanners register with valid Strategy enum values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 08:36:18 -08:00
Youssef Aitousarrah 573b756b4b fix(insider-buying): preserve transaction details, add cluster detection and smart priority
- Call get_finviz_insider_buying with return_structured=True and deduplicate=False
  to get all raw transaction dicts instead of parsing markdown
- Group transactions by ticker for cluster detection (2+ unique insiders = CRITICAL)
- Smart priority: CEO/CFO + >$100K = CRITICAL, director + >$50K = HIGH, etc.
- Preserve insider_name, insider_title, transaction_value, num_insiders_buying in output
- Rich context strings: "CEO John Smith purchased $250K of AAPL shares"
- Update finviz_scraper alias to pass through return_structured and deduplicate params

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 08:36:18 -08:00
Youssef Aitousarrah 2b74d298da Add scanner improvements design document
Documents the approved plan to fix signal quality issues in all 9
existing scanners and add 3 new scanners (analyst upgrades, technical
breakout, sector rotation).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 08:36:18 -08:00
github-actions[bot] 6342090a94 chore: update performance tracking 2026-02-20 2026-02-20 13:46:52 +00:00
github-actions[bot] 4f26536f46 chore: daily discovery 2026-02-20 2026-02-20 13:46:15 +00:00
github-actions[bot] aadb54e776 chore: update performance tracking 2026-02-19 2026-02-19 13:55:01 +00:00
github-actions[bot] 89c23751fa chore: daily discovery 2026-02-19 2026-02-19 13:54:25 +00:00
github-actions[bot] 4355f633b3 chore: update performance tracking 2026-02-18 2026-02-18 13:51:57 +00:00
github-actions[bot] a29cb9ca18 chore: daily discovery 2026-02-18 2026-02-18 13:51:26 +00:00
Youssef Aitousarrah 74e8703d60 Add daily price movement to charts and fix intraday data rendering
- Add daily price movement display with color coding (green/red)
- Add 1D (intraday) and 7D chart options with granular data:
  - 1D: 5-minute interval for detailed intraday view
  - 7D: hourly interval for smooth 7-day chart
- Fix discontinuous chart rendering by plotting against sequential index for intraday data
- Eliminate overnight/weekend gaps in hourly charts
- Add timezone normalization for consistent date handling between daily and intraday data
- Improve fallback logic when data is sparse
- Better handling of yfinance column names (Datetime vs Date)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-02-17 12:55:12 -08:00
Aitous f4dba2940c
Merge pull request #8 from Aitous/feature/discovery-enhancements
Update
2026-02-17 12:14:19 -08:00
Youssef Aitousarrah 22433d6b7d Update 2026-02-17 12:12:20 -08:00
Aitous f8c6e2afcb
Merge pull request #7 from Aitous/feature/discovery-enhancements
Update
2026-02-17 12:08:22 -08:00
Youssef Aitousarrah fd951be8bc Update 2026-02-17 12:07:07 -08:00
Aitous feccdb77fc
Merge pull request #6 from Aitous/feature/discovery-enhancements
Feature/discovery enhancements
2026-02-17 10:27:57 -08:00
Youssef Aitousarrah 457d650e42 Update 2026-02-17 10:27:13 -08:00
github-actions[bot] 60a4fdd98d chore: update performance tracking 2026-02-17 2026-02-17 13:51:48 +00:00
github-actions[bot] 743ef2c56e chore: daily discovery 2026-02-17 2026-02-17 13:50:40 +00:00
Youssef Aitousarrah aef83cd6e0 Update the price chart 2026-02-16 22:41:54 -08:00
Aitous 3c0a6b427c
Merge pull request #5 from Aitous/feature/discovery-enhancements
Feature/discovery enhancements
2026-02-16 14:18:29 -08:00
Youssef Aitousarrah 6831339b78 Remore unused code and improve the UI 2026-02-16 14:17:43 -08:00
Youssef Aitousarrah 8d3205043e Update 2026-02-16 14:17:41 -08:00
Aitous 080f626a22 Update cron schedule to run one hour earlier 2026-02-16 13:27:01 -08:00
Aitous 7f326b1df8 Update cron schedule to run one hour earlier 2026-02-16 13:25:57 -08:00
Aitous 763c44691e
Merge pull request #4 from Aitous/feature/discovery-enhancements
feat: add performance tracking step to daily discovery workflow
2026-02-16 13:24:57 -08:00
Youssef Aitousarrah 683d42a9e2 feat: add performance tracking step to daily discovery workflow
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 13:24:15 -08:00
github-actions[bot] e3f3c02dc9 chore: daily discovery 2026-02-16 2026-02-16 14:32:42 +00:00
Aitous f535b78b2e Update cron expression in daily-discovery.yml 2026-02-15 14:37:51 -08:00
Aitous bb1c32f3ea Update cron expression to run daily including weekends 2026-02-15 14:36:41 -08:00
github-actions[bot] 18f6907857 chore: daily discovery 2026-02-13 2026-02-13 14:20:20 +00:00
github-actions[bot] 85ec1cb88f chore: daily discovery 2026-02-12 2026-02-12 14:38:41 +00:00
github-actions[bot] 53078c6319 chore: daily discovery 2026-02-12 2026-02-12 14:22:14 +00:00
github-actions[bot] 54f5af2036 chore: daily discovery 2026-02-12 2026-02-12 06:47:07 +00:00
Aitous c4fe114e84
Merge pull request #3 from Aitous/feature/discovery-enhancements
fix: add missing tweepy dependency to pyproject.toml
2026-02-11 22:32:40 -08:00
Youssef Aitousarrah b41fe8c69c fix: add missing tweepy dependency to pyproject.toml
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 22:26:51 -08:00
Aitous 9442de7868
Merge pull request #2 from Aitous/feature/discovery-enhancements
Feature/discovery enhancements
2026-02-11 22:12:06 -08:00
Youssef Aitousarrah f4aceef857 feat: add daily discovery workflow, recommendation history, and scanner improvements
- Add GitHub Actions workflow for daily discovery (8:30 AM ET, weekdays)
- Add headless run_daily_discovery.py script for scheduling
- Expand options_flow scanner to use tickers.txt with parallel execution
- Add recommendation history section to Performance page with filters and charts
- Fix strategy name normalization (momentum/Momentum/Momentum-Hype → momentum)
- Fix strategy metrics to count all recs, not just evaluated ones
- Add error handling to Streamlit page rendering

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 22:07:02 -08:00
Youssef Aitousarrah ab8d174990 Add recommendations folder so that the UI can display it 5 2026-02-10 22:43:46 -08:00
Youssef Aitousarrah 1ead4d9638 feat: add theme module and fix Streamlit Cloud deployment
- Add tradingagents/ui/theme.py (design system: colors, CSS, Plotly templates)
- Add .streamlit/config.toml for dark theme configuration
- Fix Plotly duplicate keyword args in performance.py and todays_picks.py
- Replace deprecated use_container_width with width="stretch" (Streamlit 1.54+)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 22:40:08 -08:00
Youssef Aitousarrah 8ebb42114d Add recommendations folder so that the UI can display it 4 2026-02-10 22:28:52 -08:00
Youssef Aitousarrah 0bc7dda086 Add recommendations folder so that the UI can display it 3 2026-02-10 09:43:54 -08:00
Youssef Aitousarrah 50eee9b945 Add recommendations folder so that the UI can display it 2 2026-02-09 23:53:55 -08:00
Youssef Aitousarrah 8273870e0a Add recommendations folder so that the UI can display it 2026-02-09 23:41:57 -08:00