Location: /raid/py_projects/stock_terminal/scripts/generate_report.py
Output: /raid/py_projects/stock_terminal/reports/<TICKER>_report_<YYYYMMDD>.pdf
cd /raid/py_projects/stock_terminal
source .venv/bin/activate
python scripts/generate_report.py XOM
python scripts/generate_report.py JPM
python scripts/generate_report.py AAPL --output /tmp/AAPL_custom.pdf
Output: reports/XOM_report_20260403.pdf
Prerequisites: The ticker must have data in massive_cache (company_info, ratios, risk_factors_scored, related_companies) and ORATS (spx.orats_core_data). All S&P 500 stocks are pre-populated.
Cost: ~$0.15 per report (Claude API for analysis). If analysis is already cached, no API cost — only chart generation.
| Page | Title | Content |
|---|---|---|
| 1 | Overview | Methodology, data sources table (Massive, Sharadar, ORATS, Benzinga, Claude), report structure guide, disclaimer |
| 2 | Investment Analysis | AI rating (Buy/Hold/Sell), 5 key finding bullets, investment thesis paragraph, 1-year price chart with 50/200 SMA, quarterly EPS & revenue bars, key statistics sidebar |
| 3 | Growth & Valuation | Analyst notes in two columns (Risks Materializing, De-Risking, News Sentiment | Options & SI Signal, Financial Resilience, Actionable Watchlist), 5-year financial tables with growth rates |
| 4 | Peer & Industry | 1-year performance vs S&P 500 and sector ETF (auto-selected by Sharadar sector), peer comparison table with PEG, AI-generated peer analysis bullets |
| 5 | Risk Factors | Peer risk heatmap comparing SEC 10-K risk factor counts by category, severity-rated risk factors (Critical + High) scored by Claude |
| 6 | Options & Implied Risk | IV smile chart (target vs peers), options positioning table, analytical bullets, IV percentile peer bars, IV vs realized volatility spread |
| 7 | References | AI model validation benchmarks, risk methodology (arXiv:2601.15247), data source API documentation links |
Step 1 — Risk Factor Scoring:
massive_cache.risk_factors_scoredStep 2 — Unified Investment Analysis:
massive_cache.ai_analysis (analysis_text + sections_json)| Source | Data Provided | Update Frequency | Database |
|---|---|---|---|
| Massive API | Real-time quotes, 20-year OHLCV, SEC filings, risk factors | Cached in massive_cache | massive_cache |
| Sharadar | Quarterly/annual financials, ratios, EPS, revenue | Weekly cron + daily M-F | sharadar |
| ORATS | IV, HV, percentile, skew, volume, OI, IV smile | Weekly cron | orats |
| Benzinga | Real-time news with RoBERTa sentiment scoring | Continuous poller | massive_benzinga |
| Claude | Risk scoring (Step 1), investment analysis (Step 2) | On-demand / cached | massive_cache |
Performance comparison chart auto-selects the correct SPDR Sector ETF from Sharadar's sector field:
| Sharadar Sector | ETF | Examples |
|---|---|---|
| Technology | XLK | AAPL, MSFT, NVDA |
| Communication Services | XLC | T, GOOG, META |
| Energy | XLE | XOM, CVX, COP |
| Financial Services | XLF | JPM, BAC, GS |
| Healthcare | XLV | JNJ, UNH, PFE |
| Consumer Cyclical | XLY | AMZN, TSLA, HD |
| Consumer Defensive | XLP | PG, KO, WMT |
| Industrials | XLI | BA, CAT, UPS |
| Basic Materials | XLB | LIN, APD, DD |
| Utilities | XLU | NEE, DUK, SO |
| Real Estate | XLRE | AMT, PLD, SPG |
Sunday 0 6 — Database stats report
Sunday 0 7 — Stock Terminal: cache refresh (ratios, SI, performance, 8-K)
Sunday 0 9 — Stock Terminal: report generation (Claude analysis + PDFs, top 100)
| Script | Purpose |
|---|---|
scripts/generate_report.py |
PDF report generator (7-page template) |
scripts/weekly_cache_refresh.py |
Update ratios, SI, performance for tracked tickers |
scripts/weekly_report_generation.py |
Regenerate Claude analysis + PDFs for stale tickers |
scripts/weekly_db_stats.py |
Log database record counts, sizes, freshness |
scripts/batch_populate.py |
Batch populate risk scores + analyses for top N stocks |
| Table (massive_cache) | Records | Purpose |
|---|---|---|
| company_info | ~483 | Company name, SIC, exchange, description |
| ratios | ~479 | P/E, ROE, D/E, market cap, EPS, FCF |
| stock_performance | ~100 | Price, returns, 52W range |
| short_interest | ~36,586 | 3-year SI history per ticker |
| related_companies | ~3,624 | Peer mappings |
| risk_factors | ~17,318 | Massive API 10-K risk factor classifications |
| risk_factors_scored | ~85 tickers | Claude-scored risks with severity |
| ai_analysis | ~85 tickers | Claude analysis text + sections_json + rating |
| report_cache | 100 | Report generation tracking |
| filings_8k | ~24,254 | Recent 8-K filing summaries |