Generative AI Analysis
Relevant source files
The following files were used as context for generating this wiki page:
Generative AI Analysis in the Rabid Raccoon project provides a multi-layered diagnostic overlay for MES (Micro E-mini S&P 500) futures trading. It combines raw mathematical signal processing with Large Language Model (LLM) reasoning to generate tradeable narratives, chart pattern recognition, and macro-economic forecasting. The system is designed to remove "black box" uncertainty by grounding AI narrative overlays in transparent technical data, such as Fibonacci levels, measured moves, and cross-asset correlations.
The system primarily utilizes OpenAI (GPT-4/5 series) and Anthropic (Claude Opus) models to process technical indicators, market regimes, and visual chart data. It serves as a decision-support layer within the Next.js dashboard, offering probabilistic framing for various trading horizons.
Sources: src/lib/instant-analysis.ts:1-12, src/app/api/analyse/chart/route.ts:133-145, README.md:53-58
System Architecture and Data Flow
The Generative AI Analysis system operates through a specialized pipeline that transforms raw market data into structured prompts for AI models. The architecture distinguishes between "Deterministic Analysis" (pure math) and "AI Analysis" (narrative overlay).
Analysis Execution Flow
The following diagram illustrates how market data is processed through the technical engine before being sent to the AI for overlay.
The system computes over 200 technical signals across 15M, 1H, and 4H timeframes before involving an AI model.
Sources: src/lib/instant-analysis.ts:5-12, src/lib/instant-analysis.ts:601-650
Instant Multi-Timeframe Analysis
The runInstantAnalysis function is the primary entry point for generating AI-enhanced market insights. It aggregates data from the MarketContext and technical snapshots to build a comprehensive macro strategist prompt.
Key Components of the Analysis
| Component | Description | Source File |
|---|---|---|
| Technical Signals | RSI, Stochastic, MACD, Bollinger Bands, and SMA/EMA crossovers across 3 timeframes. | src/lib/instant-analysis.ts:125-275 |
| Market Regime | Classification of current environment as RISK-ON, RISK-OFF, or MIXED based on asset performance. | src/lib/market-context.ts:162-175 |
| VIX Filter | A hard filter that dampens "BUY" signals or forces "SELL" bias if VIX >= 20.00. | src/lib/instant-analysis.ts:468-490 |
| Theme Scores | AI-generated scores for market themes like Tariffs, Rates, and AI/Tech. | src/lib/market-context.ts:311-330 |
AI Model Redundancy
The system implements a fallback chain for model selection to ensure high availability.
function getAnalysisModelCandidates(): string[] {
const fromEnv = (process.env.OPENAI_ANALYSIS_MODEL || '').trim()
const candidates = [
fromEnv,
'gpt-5.2-pro',
'gpt-5-pro',
'gpt-5.2',
'gpt-5.1',
'gpt-5',
].filter(Boolean)
return [...new Set(candidates)]
}
Sources: src/lib/instant-analysis.ts:38-48
Computer Vision Chart Analysis
The system utilizes Anthropic's Claude Opus 4.6 Vision model to analyze base64-encoded screenshots of trading charts. This process combines visual pattern recognition with structured OHLCV (Open, High, Low, Close, Volume) data.
The analysis identifies specific chart formations including reversals (Head & Shoulders), continuations (AB=CD measured moves), and breakout levels.
Sources: src/app/api/analyse/chart/route.ts:74-120, src/components/AnalysePanel.tsx:69-90
Macro Strategic Forecasting
The forecast.ts module generates tactical trading plans for specific sessions (Morning, Premarket, Midday, Afterhours). It focuses on "probabilistic framing" and requires the AI to generate concrete trade triggers and invalidation levels.
Key Data Structures
The ForecastResponse includes:
- Directional Bias: BULLISH or BEARISH based on composite signals.
- Confidence Score: A value between 50-95.
- Key Levels: Support and resistance arrays derived from measured moves.
- Narrative: 4-7 sentences including a TL;DR and invalidation risk.
7,000 Breakout Detector
A specific logic gate is implemented for the SPX 7,000 level, requiring a strict "two-close" rule before the AI is permitted to confirm a breakout.
Sources: src/lib/forecast.ts:161-175, src/lib/market-context.ts:435-465
Technical Configuration and Environment
The Generative AI Analysis system relies on specific environment variables and model configurations defined in the project.
| Variable | Default / Fallback | Purpose |
|---|---|---|
OPENAI_API_KEY | Required | Authentication for OpenAI analysis/forecasting. |
ANTHROPIC_API_KEY | Required | Authentication for Claude Vision chart analysis. |
OPENAI_ANALYSIS_MODEL | gpt-5.2-pro | Primary model for narrative technical analysis. |
OPENAI_FORECAST_MODEL | Match Analysis Model | Optional override for session forecasting. |
Sources: README.md:53-58, src/lib/instant-analysis.ts:39-45, src/lib/forecast.ts:33-40
Logic Constraints
The system enforces strict directional consistency:
- BUY Setup: Stop < Entry < Target; Entry must be below current price.
- SELL Setup: Target < Entry < Stop; Entry must be above current price.
- VIX Influence: If VIX >= 20.00, the AI is constrained to generate "SELL" verdicts for timeframe gauges to manage risk.
Sources: src/lib/instant-analysis.ts:805-815, src/lib/instant-analysis.ts:470-480
Conclusion
Generative AI Analysis in Rabid Raccoon serves as a sophisticated synthesis layer that bridges raw quantitative data and qualitative market strategy. By utilizing high-tier LLMs like GPT-5 and Claude Opus, the system provides traders with structured, math-grounded trade plans while maintaining strict risk controls through VIX-based filters and multi-close breakout confirmation logic.