Agentic Hackathon · Alpaca Paper Trading

Five agents.
One veto. Real fills.

An autonomous momentum + options trading system where a risk agent has hard veto power over every order — and the execution agent is structurally incapable of bypassing it.

1
Market Data
2
Strategy
3
Judgment (AI)
4
Risk — veto
5
Execution
6
Position
Architecture

Discipline doesn't scale by hand

Momentum investing works — but running it with real discipline means position sizing, earnings-drift detection, options-overlay collateral math, risk vetoes, and exit timing, done consistently, every day. So it runs as a pipeline of five specialized agents, each with one narrow job, plus an optional sixth.

01

Market Data Agent

Scores every liquid stock on momentum and reads real SEC earnings filings for post-earnings drift signals.

02

Strategy Agent

Turns the snapshot into buy/trim/exit proposals and options-spread candidates. Rules only — no risk checks, no sizing.

Optional
03

Judgment Agent (AI)

Can flag a name as risky. Cannot invent or size a trade. Abstains entirely without an API key — the pipeline runs unchanged.

04

Risk Agent

Veto authority. Position limits, per-name caps, and the single-pot capital rule — no dollar spent twice.

05

Execution Agent

The only agent that talks to the broker. Refuses anything not approved — it raises an exception rather than submitting.

06

Position Agent

Reports P&L, exposure, and reconciles the book against the broker after every cycle.

"The one-way valve: only Execution can write to the broker, and it structurally cannot bypass Risk."
The Strategy

Three sleeves, one pot of capital

Money is never spent twice — portfolio.py enforces it with runtime assertions that raise, not logic that could silently drift.

Momentum Core

Top 6 stocks by a vol-adjusted momentum score (12-month minus last month, 3-month, trend, relative strength vs. SPY), equal-weighted. Goes to 100% cash if SPY is below its 200-day moving average.

80%

PEAD Sleeve

Buys stocks the day after a confirmed earnings beat, using real SEC EDGAR filing data — not simulated. Two independent signals (SUE score + volume-confirmed gap) must both agree.

5%/event

Options Overlay

Sells 20-delta put credit spreads on stocks the other sleeves already own. Closes at 50% of max profit, or unconditionally within 5 days of expiry to avoid assignment.

15% max
Backtest Evidence

Train / validate / test — never re-tuned

2011–2026, mechanically screened. The test period was run exactly once.

PeriodReturnWin RateProfit FactorMax DDSharpeAlpha (ann)
Train 2011–18+360.1%95.2%2.12−15.3%0.95+12.0%
Validate 2019–21+221.7%92.7%1.20−47.0%1.17+32.0%
Test 2022–26+1072.1%94.3%2.47−30.6%1.88+64.5%

Test period was run once and never tuned on.

Intellectual Honesty

How much of that is universe selection?

The headline numbers use a 39-name universe hand-picked in 2026. The identical strategy was rerun on a mechanically screened, survivorship-bias-free 951-name universe — including delistings and bankruptcies the hand-picked list omits.

SPY (baseline)
+70.7%
Sharpe 0.60
951-name universe
+329.2%
Sharpe 0.93 · alpha +28.7%/yr
Hand-picked 39 names
+249.1%
Basis for the table above
~40% of the headline return was universe selection, not the strategy.
Expect ~+29%/yr alpha going forward — not the hand-picked number.
Live Proof — This Actually Happened

From broken fills to a real credit spread, in 6 days

Not just a backtest — a real, verifiable trading bug found and fixed on paper capital.

Aug 28

Momentum core deployed live — bought 6 stocks (CNC, JAZZ, TD, UTHR, VLO, WBD) equal-weight. Clean fill.

Aug 28

3 option spread orders submitted — all three expired unfilled. Root cause: the limit price was calculated from a Black-Scholes model's own strikes and expiry, not the real listed contracts — every order asked for more credit than the spread could pay.

Sep 2–3

Diagnosed and fixed 4 independent defects. Also found the agents could open a spread but had no path to close one — built a leg-pairing module that reconstructs an open spread directly from the broker's own position data.

Sep 3, 10:33am ET

The TD 115/105 put credit spread filled. Sold the 115 put at $0.95, bought the 105 put at $0.40 — net credit $0.55/share ($110 total) on 2 contracts. Real premium collected.

Sep 3, later

The 12:45pm and 3:45pm scheduled cycles both correctly recognized the open position, did not duplicate it, and correctly left it alone — the full open → hold → close lifecycle running unattended, on real fills, not a backtest.

"This is the exact failure the system is fixed against, working live, autonomously, without a human in the loop."
Safety Design

Four layers between a proposal and a fill

Paper trading only, by construction — no live-trading code path exists.

Paper trading only, structurally

4 independent gates must ALL pass: env flag, paper API endpoint, account number prefix, and a SHA-256 hash checked against a tracked source allowlist — not just a .env file.

Capital cannot be double-spent

Enforced by runtime assertions, not logic that could silently drift. An earlier bug where this wasn't enforced inflated a 15-year backtest CAGR by ~8 percentage points before it was caught.

64 automated tests

Including tests that pin the capital invariants, and tests that specifically prove the Execution Agent raises an exception if handed an unapproved order.

Silent-safe on a schedule

Runs 3× per weekday with zero human intervention — but a run that finds nothing to do is safe by default: if the market is closed, every proposal is automatically rejected.

A Note for the Judges

On backtesting rigor

I built this to survive rigorous backtesting, not just produce a good-looking curve. Parameters were fit only on 2011–2018, checked once on 2019–2021, and the 2022–2026 test window was run exactly once — never touched again to adjust a threshold or a gate. Across that out-of-sample test period: +1072% return, a 2.47 profit factor, a 1.88 annualized Sharpe, and +64.5%/year alpha versus SPY, on a mechanically screened universe rather than a handful of cherry-picked tickers.

The earnings-drift sleeve is backtested on real data, not a simulated distribution: it pulls actual quarterly EPS and filing dates from SEC EDGAR's XBRL API, and only counts a signal when two independent measures — a SUE score and a volume-confirmed price gap — both agree.

Capital accounting is enforced structurally, not just in spirit. One pot of money, shared by the momentum core, the earnings-drift sleeve, and the options overlay, with runtime assertions that raise the moment a dollar would be spent twice — not application logic that could silently drift out of sync.

The same discipline carries into live trading. A risk agent has hard veto authority over every order, checking position limits, per-name concentration, and the capital rule before anything reaches the broker. The execution agent is the only component allowed to talk to Alpaca, and it structurally cannot submit anything the risk agent didn't approve — it raises rather than executes. All of this is pinned by 64 automated tests, including ones that specifically prove that refusal behavior. And it isn't just a backtest anymore — the system is live on Alpaca paper trading, running autonomously three times a day, and has already sold a real put credit spread and collected the premium.

Five agents. One veto. Real fills.

Momentum + Options Agents — Agentic Hackathon, Alpaca Paper Trading