Oft3r/agentic-trading-desk
AI-assisted trading desk for short-term technical analysis on stocks & ETFs via Robinhood MCP. Deterministic Python engines score each asset on a three-pillar framework (Trend · Momentum · Macro-Sentiment) using EMA, RSI, MACD, TRIX & Bollinger Bands. The AI fetches data; the scripts compute; the human approves every order.
Agentic Trading Desk
What it is – A locally‑run personal trading system that lets a Claude (or Gemini) AI agent fetch market data, run deterministic Python calculations, and (optionally) place trades on a Robinhood account. The AI only handles data retrieval and orchestration; all numeric analysis is performed by pure‑Python scripts that use only the standard library.
Core idea
The system follows a strict “AI = fetch, scripts = calculate, user = approve” workflow. An AI Skill (for Claude Code) talks to Robinhood via the MCP protocol, pulls price histories and quotes, then calls three Python modules:
indicators.py– computes EMA, RSI, MACD, TRIX, Bollinger %B, etc.macro_pillar.py– builds a macro‑sentiment score from cross‑asset ratios (SPY/RSP, yield spread, credit spreads, size factor, etc.).score.py– combines the Trend, Momentum, and Macro‑Sentiment pillar scores (each –2 … +2) into a total –6 … +6, flags special patterns, and outputs a concrete trade decision (e.g., HOLD, EXIT / TRIM, RE‑ENTRY, WAIT).
The AI then formats the three‑pillar scorecard, adds qualitative context (news from Investing.com, analyst consensus from Google Finance), and, if the decision is executable and respects the Mandate, sends a market order to Robinhood.
Architecture snapshot
graph TD
A[Robinhood MCP] -->|historicals/quotes| B[Claude Agent]
C[Investing.com] -->|macro data| B
B -->|JSON closes| D[scripts/macro_pillar.py]
B -->|JSON closes + holding| E[scripts/score.py]
D -->|macro score| E
E -->|scorecard & decision| B
B -->|order (if allowed)| A
B -->|push notification| G[User]
All scripts run locally, require only Python 3 and jq (for the guard hook).
Key components
| File / Directory | Role |
|---|---|
SKILL.md |
Human‑readable operations manual and the guard‑rail policy that the AI must obey. |
scripts/indicators.py |
Pure‑Python technical‑indicator engine (EMA, RSI, MACD, TRIX, Bollinger %B). |
scripts/macro_pillar.py |
Macro‑regime detector using eight ETFs and the 10Y‑2Y Treasury spread. |
scripts/score.py |
Pillar‑scoring logic, flag detection, and decision tree. |
scripts/prepare_inputs.py |
Converts raw Robinhood JSON into the per‑ticker format expected by the other scripts. |
hooks/mandate-order-guard.sh |
Pre‑tool hook that blocks any place_equity_order call that violates the hard Mandate (market‑only, regular‑hours, $≤1,200 per buy, etc.). |
gemini-spark/ |
A sanitized copy that removes discretionary order‑guard logic for use with Gemini Spark’s stricter security model. |
How to use (CLI)
# 0. Convert Robinhood output to work/ files
python3 scripts/prepare_inputs.py \
--historicals hist1.json hist2.json \
--quotes quotes.json \
--out work/
# 1. See raw indicators for a ticker
python3 scripts/indicators.py work/ticker_AAPL.json
# 2. Compute the macro score (once per session)
python3 scripts/macro_pillar.py work/macro_input.json --json
# 3. Get the full three‑pillar scorecard & decision
python3 scripts/score.py work/ticker_AAPL.json --json
Running any script with no arguments executes a self‑test using synthetic data.
AI integration (Claude Code Skill)
- Install – copy the repo into
~/.claude/skills/agentic-trading-desk(or upload to claude.ai). The skill’s.claude/settings.jsonregisters themandate-order-guard.shhook. - Workflow – When you ask Claude “Analyze AAPL”, the skill:
- pulls daily history & live quote via Robinhood MCP,
- runs
macro_pillar.pyonce per session, - runs
score.pyfor the ticker, - returns the scorecard, flags, and a textual recommendation,
- if the recommendation is an executable market order and all Mandate limits are satisfied, the guard allows the
place_equity_ordercall; otherwise the trade is blocked and a reason is reported.
- Mandate – Hard limits enforced by the guard:
- market orders only during regular NYSE hours,
- buys limited to ≤ $1,200 (fractional dollar‑based),
- no limit/stop orders, no after‑hours trading, and a daily‑loss circuit‑breaker (‑4%).
- The guard fails closed – if
jqis missing or the script crashes, the order is denied.
Safety & limitations
- No back‑testing – the authors explicitly state the framework has never been back‑tested; users should treat signals as research aids, not proven strategies.
- Deterministic core – all numeric scores are reproducible; only the qualitative news/analyst overlay is non‑deterministic and never influences the numeric decision.
- Guard reliability – the order‑guard is a client‑side script; it protects only Claude Code runs that load the skill. Running the scripts manually or from another agent bypasses the guard.
- Broker constraints – works only with Robinhood’s MCP (fractional, dollar‑based market orders) and assumes the account has the Agentic flag set.
- Scope – the system is designed for short‑term, technical‑analysis‑driven trading of US stocks/ETFs; it does not handle options, futures, or non‑US assets.
Quick take‑away
The Agentic Trading Desk is a concrete example of an AI‑augmented trading workflow: a language‑model skill orchestrates data fetching, a set of pure‑Python indicator scripts provides transparent, reproducible scores, and a hard‑coded pre‑tool guard enforces a risk‑limited execution policy. It is a genuine, open‑source project aimed at users who want a locally‑run, deterministic trading assistant that can be plugged into Claude (or Gemini Spark) without relying on external SaaS APIs for the core calculations.
Related
- Project
- Project
- Project
- Project
- Project