An agentic trading system
that grades itself.
Most trading bots lie to you — dead components hiding behind green P&L, risk quietly inverted by a config default, backtests that never survive contact with the market. StockMachina is an open-source framework for intraday US equities on Interactive Brokers built on the opposite premise: every intelligent component is graded against what the market actually did next — a local LLM as second pair of eyes on every entry, a 12-check risk engine in front of every order, and it all runs on hardware you own.
Green P&L can hide dead components.
We learned this the honest way: our LLM screener silently failed open for two weeks — and a profitable week hid it completely. Only a counterfactual scorecard (grading every GO/SKIP decision against forward price action) exposed that a core component was dead. StockMachina is built around that lesson: every intelligent component must be measured against reality, continuously— or you don't actually know what's driving your returns.
Lie #1 — “it's working”
Dead components hide behind lucky weeks. Answer: counterfactual scorecards. Every screener GO/SKIP graded against forward price action; exit quality measured with MFE/MAE; forecaster disagreement quantified.
Lie #2 — “risk is handled”
A config default silently inverted our R:R — losers 2.4× bigger than winners. Answer: one risk middleware, 12 fail-fast checks, in front of EVERY order. Staleness halts, reconciliation halts, hard notional caps.
Lie #3 — “the backtest says so”
Backtests flatter. Answer: realistic cost models, out-of-sample validation on split windows for every change, negative results documented — and a public forward test as the only pitch that counts.
Event-driven core. Agentic where it pays.
Deterministic engines wired over an event bus, with LLMs placed only where judgment adds value — and always fail-open, so a dead model degrades the system instead of stopping it.
LLM Screener
judgmentA local LLM gives every proposed entry a GO / WEAK / SKIP verdict with a strict JSON contract — the second pair of eyes before any order exists.
Every decision is recorded and later graded against forward price action (counterfactual scorecard). That scorecard once caught the screener silently dead for two weeks behind green P&L.
Circuit breaker + fail-open: if the model is down, signals pass ungated — but flagged 'degraded', counted, and alerted. Absence is measured, never hidden.
click a stage to inspect it — including how it fails
Runs on a Mac mini
The trading core is lightweight: Python + SQLite + an IBKR gateway. The orchestrator node schedules, supervises, and alerts via Telegram.
GPU box optional
LLM + forecaster inference served via any OpenAI-compatible endpoint (vLLM, LM Studio, Ollama). We run a DGX Spark; a gaming GPU works too.
Degrades, never stops
Screener down? Fail-open with telemetry. Forecasters down? Typed votes go absent, gates relax. Data stale? New entries halt, exits still work.
Built from real trading scars, not feature lists.
Counterfactual scorecards
Every screener GO/SKIP graded against forward MFE. False-rejection rate and verdict separation, measured — not assumed.
Exit engineering
ATR brackets that preserve intended R:R after stop-flooring. Asymmetry root-caused in research: fixed it OOS before shipping.
Let winners run — both ways
Trend-aware far targets with ATR trailing, symmetric for longs and shorts, with a chop guard that reverts to tight targets in ranges.
Entry windows, OOS-validated
Edge-of-day entries were 49% of trades and ~78% of losses across both validation halves. The midday filter shipped with evidence.
12-check risk middleware
One pluggable pipeline in front of every order. Data-staleness halts, reconciliation halts, fat-finger caps, daily-loss circuit.
MFE/MAE telemetry
Max favorable / adverse excursion tracked per position, surfaced to the nightly reflection as exit-quality metrics.
Realistic backtest costs
State-dependent slippage, spread and commission modeling. Deflated metrics and walk-forward validation against overfitting.
Fail-open agentics
LLMs advise, engines decide. Any AI component can die without stopping the system — and its absence is measured, not hidden.
Architecture beats backbone.
Live-trading benchmarks keep finding the same thing we did: the agent's architecture matters more than which model you plug in. StockMachina treats models as replaceable parts behind typed contracts — and measures each one's real contribution instead of trusting the marketing.
The screener and the nightly reflector. Reasoning disabled for the hot path (a hard-won lesson: reasoning tokens can silently eat your entire output budget).
Ops and reporting agents — daily summaries, premarket briefs, system monitoring. Fast local serving keeps the entire agent fleet at $0 cloud spend.
Candlestick-native forecaster used as a soft veto/boost on entry confidence. Its votes are typed, cached, and its live accuracy is continuously measured.
Second voice of the forecast ensemble. Our own disagreement metric showed it conflicts with Kronos on direction 54% of the time — we publish that number too.
Third ensemble voice. Every forecaster is optional and fail-open: an unreachable service degrades to an absent vote, never to a fabricated one.
Financial sentiment scoring over news, social and influencer feeds — aggregated by a sentiment hub with per-source freshness tracking and deduplication.
Everything speaks OpenAI-compatible API through a LiteLLM gateway. Swap the screener model with one config line — then let the scorecard tell you if it's better.
All inference through one OpenAI-compatible endpoint. Same client, different model, measured contribution.
Boring where it should be, sharp where it matters.
No exotic infrastructure: Python, SQLite, one broker API, one inference gateway. The sophistication lives in the risk engine, the exits, and the measurement loops — the parts that actually move P&L.
- Python 3.11
- Event bus (in-proc)
- ib_insync (IBKR)
- Pydantic settings
- loguru
- SQLite ledger + warehouse
- Live 5-min bars + ticks
- Freshness heartbeats
- Corporate-action guards
- LiteLLM gateway
- vLLM (or LM Studio / Ollama)
- OpenAI-compatible API
- Typed vote contracts
- Qwen 3.5 (screener + reflector)
- MiniMax (ops agents)
- Kronos · TimesFM · Chronos
- FinBERT sentiment
- Offline backtester + cost model
- Walk-forward / OOS splits
- Hyperopt sweeps (deflated)
- Per-trade attribution
- 1,150+ pytest suite
- Telegram alerts
- Watchdog + heartbeats
- Dashboard (P&L, exec quality)
Built for people who treat their capital like quants.
Independent quants
You run capital through IBKR and want an agentic layer with institutional risk discipline — without trusting a black box.
Engineers entering trading
You reason about systems for a living. Start with an architecture that measures itself instead of a strategy script that lies to you.
LLM-agent researchers
A real, instrumented testbed for agentic trading: screener scorecards, reflection loops, and fail-open patterns on live market data.
Builders of small desks
A private, auditable, on-prem stack where every order passes one risk choke point and every AI decision leaves a graded trace.
The forward test is the roadmap.
No 18-week promises. The system is built and hardened; what remains is evidence. Paper-to-live transition is governed by numbers agreed in advance.
Build + harden
Event-driven core, 12-check risk middleware, LLM screener with scorecards, exit engineering (R:R preservation, symmetric trailing), reflection loop. 1,150+ tests green.
Forward test — in public
≥100 trades with zero rule changes, profit factor > 1.3, rolling-20 consistency, zero false safety halts. Results published as they happen — including the bad days.
Public repository
MIT-licensed release via a clean allowlist export: the full framework, the test suite, and the research journal. No cherry-picked backtests — the forward test IS the pitch.
Live capital, gated
Start at 10–20% of intended capital, scale only on sustained consistency. The same quantitative gates decide — not a good week, not a gut feeling.
Reflection lessons injected into the screener context · Bull/bear debate for high-conviction entries · Entry-alpha research continues (regime and time-of-day cohorts) · Community strategies behind the same risk middleware.
MIT. Inspectable. Forkable. Yours.
StockMachina will be released under the MIT license — no usage limits, no telemetry, no enterprise tier gating the parts that matter. The repository opens together with forward-test results, because a trading framework's pitch should be its measured behavior, not its README. It opens with the forward-test numbers attached — the wins, the losses, and the lessons.
Measure everything. Trust nothing. Ship evidence.
StockMachina is being forward-tested in public right now. Follow along, inspect the architecture, and bring your own hardware when the repo opens.