
This project is an autonomous AI trading agent built for the Alpaca AI Trading Agents Hackathon, implementing statistical pairs trading expressed through options rather than raw equity positions. The agent scans a curated universe of 348 liquid large and mid-cap S&P 500 stocks daily, verified live against Alpaca's own tradable-assets API. It identifies pairs whose prices are historically correlated (0.80+) and cointegrated (Engle-Granger test), then monitors the statistical spread between each pair for meaningful divergence (z-score 1.5+). When a divergence is detected, the agent expresses the directional view through a defined-risk options spread, capping maximum possible loss on every trade by construction. Risk management is genuinely enforced, not just described: every trade is sized at 2.5% of capital, no single stock can be committed to more than one open pair at once, positions carry both a statistical stop-loss and a 3-day time-based stop, a take-profit locks in gains at 35% of premium risked, and a two-tier portfolio drawdown system protects the account as a whole. Built as a standalone Python agent using Alpaca's Trading API and Market Data API directly, submitting genuine multi-leg options orders. It runs autonomously via a scheduled daily entry cycle plus a 30-minute risk-monitoring cycle. Live trading surfaced real production issues no dry-run testing caught: a fill-verification gap, a close-order bug targeting the wrong symbol type, a strike-collision edge case, and a concentration-risk gap letting one stock get committed to three simultaneous pairs. Each was diagnosed from real evidence and fixed with tested code. Results: the strategy finished the week at -5.55% (starting capital $100,000, final equity $94,449.87), never breaching its 12% hard drawdown limit.
4 Sep 2026