lablab.ai × Alpaca · AI Trading Agents Hackathon

The P&L an agent can actually collect

Every trading agent reports a number. MARKGAP reports the number the account would receive if it closed right now — and drives itself flat before its deadline.

Live paper account SPY credit spread · exp 2026-09-04
+$312.40
What a dashboard shows — marked at the midpoint
$47.10
can’t be collected
+$265.30
Collectable now — what the account would actually receive
the gap

The midpoint is a convenience, not a price. Between the bid you’d hit and the ask you’d pay lives a spread you have not paid yet. On a wide multi-leg book that gap is real money — and it is invisible on every other dashboard.

Built on
Alpacamulti-leg options, paper Featherlessopen-weight regime read Own Black–Scholes Greeks Pythondeterministic engine Alpaca MCPinspection surface
The thesis
Most agents optimise expected return. MARKGAP optimises the cash it can collect at a fixed timestamp.

This competition takes one number at one moment: 11:00 on Friday. A book that is up at 11:00 and still open is not up — it is holding an unpriced liability.

So MARKGAP changes the objective function. It carries two books at once — one marked at the midpoint, one marked at what it could liquidate for — and treats the distance between them, the markgap, as the headline metric rather than a footnote. A clock decays its own risk budget toward zero and forces the book flat before the horizon. The gap ends at zero, and one honest number remains.

Three invariants

Rules the system cannot trade its way around

Not preferences — constraints checked in code before any order exists.

01 · defined risk

Known maximum loss

Every structure has a finite, computed worst case before submission. No naked shorts, no undefined-risk legs — a rule and a hard constraint of the account.

02 · closability

Price the exit first

Nothing opens until the agent has priced what it would cost to close it this instant, and that modelled exit passes the gate. If it can’t price its exit, it doesn’t enter.

03 · the horizon

Flat before the mark

The book must be flat before the deadline. A position still open at the horizon is a bug, not a trade — settled by a hard flatten, not by hope.

How it works

Judgement and arithmetic, kept apart

A deterministic engine does everything that touches money. The model is confined to a single dial it can only turn down.

Reads

Regime summary

VIX and term structure, realised vs implied vol, a trend filter, scheduled events — all computed deterministically.

Featherless LLM

One clamped scalar

Returns a risk-budget multiplier in [0, 1] that can only shrink exposure, then writes the journal rationale. Never on the critical path.

Executes

Deterministic engine

Strike, width, size, gates, order, exit — pure functions, unit-tested. The math, not the model, decides.

The model never picks a strike, never sizes a position, never places an order. If inference times out, a constant multiplier is used and trading continues.

Twelve gates

Every candidate clears all twelve, or it’s refused

01Defined risk, finite max loss
02Closability — exit priced first
03Quote sanity — no zero bid/ask
04Greek divergence vs Alpaca
05Horizon feasibility
06Clock-state permission
07Remaining risk budget
08Positive Kelly, quarter-cap
09Concentration limits
10Net delta / gamma / vega
11Latching daily-loss kill switch
12Order hygiene — increments
refused · negative_gamma dealer GEX ratio −0.59 < −0.3 — short-gamma, trending regime. A refusal is a first-class output, journalled with its gate named and shown live.
Alpaca depth

Real mechanics, not a wrapper

The failure points on Alpaca’s options stack are where the engineering actually lives.

Multi-leg, sign-correct

Structures go as one order_class="mleg" with the net-price sign convention handled — positive debit, negative credit — plus GCD-1 ratio and penny-increment validation before submission.

The 42210000 fallback

Exits try a combined multi-leg close and fall back to a leg-by-leg sequence on error 42210000 — short leg first, never leaving an uncovered short.

Our own Greeks

Alpaca returns no Greeks for 0DTE or when a quote is one-sided, so MARKGAP computes Black–Scholes itself and uses Alpaca’s as a cross-check — standing down when they diverge.

Never trust HTTP 200

Order state comes from the trade_updates stream, with REST polling for assignment and expiry. An accepted request is not a fill.

Build log

Built in public

See the number it can collect

The full engine — dual-book marks, the twelve gates, the clock, and the live dashboard — is open source. The 2-minute demo walks the real paper account.