OptionStrat AI follows a modern three-tier architecture with clear separation between presentation, business logic, and data layers. The system is designed for real-time options pricing, multi-model strategy simulation, and AI-powered insights.
The application uses Zustand for centralized state management with debounced calculations to optimize performance.Key Store Implementation (frontend/src/store/strategyStore.js:1-195):
View Complete Store Implementation
import { create } from 'zustand';import api from '../api/client';let _calcTimeout = null;let _calcVersion = 0; // Lock anti-concurrenciaexport const useStrategyStore = create((set, get) => ({ // Estado Global ticker: '', spotPrice: 0, riskFreeRate: 0.05, // Expiraciones disponibles allExpirations: [], selectedExpiration: '', // Cadena de opciones para la expiración seleccionada optionChain: { calls: [], puts: [] }, // Parámetros Interactivos del Heatmap volatilityShock: 0, daysToSimulate: 30, // Posiciones armadas por el usuario legs: [], // Resultados del Backend heatmapData: [], aiInsights: null, marketContext: null, // ... actions}));
The core calculation endpoint (backend/app/api/routers/calculations.py:10-34):
@router.post("/heatmap", response_model=HeatmapResponse)async def generate_advanced_heatmap(state: StrategyState): """ Ruta PRINCIPAL (Estrella) de OptionStrat. Recibe un estado base (la estrategia del usuario en React). Genera un grid numérico 2D cruzando iteraciones de tiempo y de precio subyacente consumiendo Black Scholes. """ try: result = StrategyBuilder.generate_heatmap_grid(state) return { "status": "success", "max_profit": result["max_profit"], "max_loss": result["max_loss"], "heatmap_grid": result["heatmap_grid"] } except Exception as e: logging.error(f"Error calculating Heatmap: {e}") return {"status": "error", "heatmap_grid": []}
Handles market data fetching:
GET /options/expirations/{ticker} - List available expiration dates
GET /options/chain/{ticker} - Get option chain for specific expiration
Uses OptionsDataManager for data retrieval
Provides intelligent analysis:
POST /ai/greeks - Fast Greeks calculation and interpretation
POST /ai/insights - Deep LLM-powered strategy analysis
The data manager implements exponential backoff and circuit breaking:
def _safe_request(self, func, *args, **kwargs): """Envoltorio para manejar Rate Limits y pausas.""" time.sleep(self.delay) try: return func(*args, **kwargs) except Exception as e: msg = str(e) if "Too Many Requests" in msg or "429" in msg: logger.critical(f"RATE LIMIT (429) detectado. Deteniendo.") raise ConnectionError("RATE_LIMIT_HIT") raise e
When rate limits are hit, the system raises a RATE_LIMIT_HIT exception that propagates to the frontend, preventing further API abuse.