The Problem
Most AI trading demos are either toy examples with no real architecture, or black-box systems with no explainability. I wanted to build something that demonstrates genuine AI PM thinking: a production-grade agentic system with documented tradeoffs, risk management guardrails, and a self-improving feedback loop — all running live on real market data.
What I Built
A dual-strategy autonomous paper trading bot that runs 24/7 on Render, scanning US stocks and crypto every hour. The Conservative strategy ($1,000, Bridgewater-style discipline) and Aggressive strategy ($1,000, Citadel-style momentum) operate in parallel on separate Alpaca paper accounts. Claude makes every buy/sell/hold decision using a weighted 9-signal scoring engine. A dynamic screener replaces the fixed stock list — fetching the most active and highest-momentum US stocks from Alpaca each cycle so the bot always trades what's actually moving. A self-tuning end-of-day review fires at 4:05pm ET — Claude analyzes the day's trades and adjusts RSI thresholds, ATR multipliers, and strategy mode for the next session. Phase 7 adds adaptive macro regime detection — the bot reads VIX, SPY vs 200-day MA, and a quantitative spike trigger to switch between four strategy modes every cycle.
Key Product Decisions
- Claude over Finnhub for sentiment — Pre-computed sentiment scores can't distinguish "beat earnings but weak guidance" from "clean beat." Claude reads actual headlines and reasons about nuance. Same cost per call, better signal quality.
- Weighted scoring engine over vote counting — RSI and MACD are both momentum indicators — they correlate. Treating them as independent votes inflates confidence. Built a point-weighted system (news +3, congressional +2, regime +2, each technical +1) so signal quality determines weight, not just count.
- Two separate Alpaca paper accounts — One shared $2,000 account means kill switches fire at the wrong portfolio threshold and strategies compete for cash. Separate accounts give each strategy true independence and accurate floor monitoring.
- Earnings guard as a hard veto — No amount of bullish signals justifies holding into an unpredictable binary event. Alpaca's earnings calendar API blocks new positions within 2 days of earnings regardless of score.
- Manual crypto stop-loss in code — Alpaca doesn't support bracket orders for crypto. Rather than removing stop protection, implemented a state-persisted stop-loss checker that runs every cycle and triggers a market sell if price breaches the ATR-based stop.
- Health endpoint to avoid Render spin-down — Free tier Web Services sleep after inactivity. Added a lightweight HTTP health server running in a background thread so cron-job.org pings keep the bot alive 24/7.
- Whole shares for stocks — Alpaca doesn't support bracket orders on fractional shares. Rounded position sizes to whole shares to enable automatic stop-loss and take-profit on all stock trades.
- Self-tuning daily review loop — Static bots don't learn. Claude reviews its own trade log at 4:05pm ET, identifies what worked and what didn't, and outputs JSON parameter adjustments with safety bounds checking to prevent runaway values.
- SendGrid over Gmail SMTP — Render's free tier blocks outbound SMTP. Switched to SendGrid HTTP API (Mail Send only, restricted key) which works on all Render tiers and is more secure by design.
- Phase-based build with eval gates — Built in 7 phases, each with its own test file before proceeding. 22 checks in test_dry_run.py, 35 in test_signals.py, 25 in test_phase5.py, 22 checks in test_phase6.py, 33 checks in test_phase7.py — all passing before deployment.
- Adaptive regime strategy over static personas — Instead of always running the same Bridgewater or Citadel persona, both strategies now read live macro conditions (VIX, SPY vs 200MA, VIX spike) every cycle and switch between four modes: MOMENTUM, MEAN_REVERSION, DEFENSIVE, and MACRO_EVENT. Conservative holds cash in DEFENSIVE and MACRO_EVENT — Claude is never called. This eliminated the core failure mode of a momentum bot running in a bear market.
- ETF short selling over single-stock shorts — In DEFENSIVE mode, Aggressive can short SPY or QQQ only. Single-stock shorts (GameStop-style squeezes) are explicitly banned. ETF shorts are liquid, can't squeeze, and provide clean bear market exposure without catastrophic tail risk.
- Combined portfolio kill switch — Individual strategy floors ($700 Conservative, $600 Aggressive) protect each account in isolation. Added a combined check: if total equity across both accounts drops below $1,700 (−15% on $2,000), both strategies halt immediately. Catches scenarios where neither individual floor triggers but combined losses are significant.
- Dynamic screener over fixed stock list — Instead of always scanning the same 10 stocks, the screener fetches the most active and highest-momentum US stocks from Alpaca each cycle. UBER is permanently included. AMZN is permanently excluded due to trading restrictions — enforced at the config level and tested in the Phase 6 test suite.
- Reddit + StockTwits social sentiment — Retail momentum often appears on social media before price moves. Both APIs are free with no authentication required. Claude scores the combined signal (+2 bullish / -2 bearish) as the 9th weighted signal in the scoring engine.
Signal Architecture
News Sentiment — Claude (+3 / -3)
Social Sentiment — Reddit + StockTwits (+2 / -2)
Congressional Trades (+2 / -1)
Market Regime / ADX (+2)
Fear & Greed Index (+2 / -1)
RSI (+1 / -1)
MACD (+1 / -1)
EMA Crossover (+1 / -1)
Volume Ratio (+1)
Earnings Veto (hard block)
Learning Objective & Summary
My goal was to build a real agentic system — not a demo — and document every architectural decision. I wanted hands-on exposure to LLM-as-decision-maker patterns, risk management architecture, financial APIs, and the practical tradeoffs of running AI systems in production. The most important lesson: prompt framing matters as much as model choice. Telling Claude it's a "former Bridgewater portfolio manager who survived the 2008 crash" produces materially different risk reasoning than a generic system prompt.
Tech Stack
Claude Sonnet (Anthropic API)
Alpaca Markets API
Python 3.11
Streamlit
Render.com
SendGrid
Alpaca News API
CNN Fear & Greed
Capitol Trades API
pandas / numpy
cron-job.org
Reddit API (free, no auth)
StockTwits API (free, no auth)
What's Next
- Phase 7 — shipped: Adaptive regime detection (MOMENTUM / MEAN_REVERSION / DEFENSIVE / MACRO_EVENT), ETF short selling in bear markets, combined $1,700 portfolio kill switch, VIX + SPY/200MA macro trigger — 33 tests passing.
- Dashboard V3: Signal scorecard per trade and news headlines panel — requires Supabase decision logging so data persists across Render services.
- Real money deployment: After 4–6 weeks of paper trading validation with documented Sharpe ratio, win rate, and regime-adjusted returns.
- Options layer: Aggressive strategy V3 — calls/puts on high-conviction signals for leveraged upside with capped downside.