My AI Trading Stack: GPT-4, Python, and Alpaca API
Related Link:
https://github.com/example/gpt4-trading-stack →After 6 months of experimentation, I've landed on a stack that actually works for AI-powered systematic trading.
The Stack
Signal Generation: GPT-4 API
Execution Framework: Python 3.11 + Backtrader
Brokerage: Alpaca API (commission-free, great API)
Data: Polygon.io (real-time + historical)
Deployment: AWS Lambda (serverless, runs every 15 min)
How It Works
-
Market Scan (GPT-4) — Every 15 minutes, I feed GPT-4 a prompt with:
- Current price action for my watchlist (50 stocks)
- Recent news headlines (scraped from FinViz)
- Technical indicator values (RSI, MACD, volume)
-
Signal Extraction — GPT-4 returns a structured JSON with trade recommendations:
{ "symbol": "AAPL", "action": "BUY", "confidence": 0.78, "reasoning": "Strong volume breakout + bullish news..." } -
Execution — Python script validates the signal (checks confidence > 0.7) and submits orders via Alpaca API.
Results So Far
6-month backtest: +18% (vs SPY +12%)
3-month live trading: +7.2% (small account, $5k)
Not life-changing yet, but it's beating buy-and-hold with zero manual intervention.
Key Learnings
- GPT-4 hallucinates if you don't constrain the output format. Use strict JSON schemas.
- News sentiment is gold. Adding news to the prompt boosted win rate from 54% to 61%.
- Backtests lie. Live results are always worse. Plan for slippage and API latency.
GitHub repo linked above—feedback welcome!