Petra is an autonomous options trading agent developed as a submission for the Alpaca AI Trading Hackathon. It operates on a $100k Alpaca paper trading account to automatically sell defined-risk credit spreads, which include put credit spreads, call credit spreads, and iron condors. The agent is built on a full-stack architecture utilizing FastAPI, MongoDB, React, and Claude Sonnet 4.6. Architecture & Risk ManagementThe core philosophy behind Petra is that options selling accounts typically blow up due to sizing and liquidity mistakes rather than bad directional calls. Therefore, the system strictly separates AI intelligence from financial risk: Signal Generation: Claude Sonnet 4.6 acts as the brain, determining the market regime, direction, confidence, and strategy choice. Strike & Size Engine: Deterministic code calculates the delta-targeted short strike, spread width, and contract count based on a strict risk budget. Execution & Management: The system routes multi-leg limit orders at a net credit. It continuously manages positions utilizing a 50% take-profit target and a 2x-credit stop loss. The Trading CycleThe agent operates autonomously on a strict schedule:An in-process scheduler triggers a cycle every 15 minutes while the market is open. It captures a snapshot of a defined universe of assets (such as SPY, QQQ, AAPL, and NVDA) and requests a trading verdict from Claude. The deterministic engine builds the spread and evaluates it against a 7-rule risk gate, where any failure immediately halts the order. Safety & Transparency Fail-Closed Design: Any LLM schema violation, data fetch failure, or risk gate rejection guarantees that no trade is executed. Full Audit Trail: Every prompt, verdict, risk check, and exit reason is saved in a MongoDB database and displayed on a live dashboard for complete transparency. Would you like to explore the specific parameters of Petra's 7-rule risk gate or dive deeper into how the dashboard visualizes the data?
Category tags: