Skip to Content

Stock Trading Agent Swarm

A distributed multi-agent swarm for stock trading simulation — 10 specialized agents coordinating via an async message bus, backtested across 250 trading days on S&P 500 data


⚠️ Disclaimer: This is a simulation project for educational and research purposes only. It does not constitute financial advice. Stock trading involves significant risk. Always consult a qualified financial advisor before making investment decisions.


Problem Statement

We Asked NEO to: Build a distributed multi-agent swarm for stock trading simulation with:


Solution Overview

NEO built a production-grade multi-agent trading simulation with 10 specialized agents across 4 tiers:

  1. 3 Analyst Agents scan market data and generate BUY/SELL signals using SMA crossovers and volume trend analysis
  2. 4 Trader Agents each manage a $250K portfolio slice — consuming signals, executing trades, and tracking positions independently
  3. 2 Risk Manager Agents handle dual validation — pre-trade order approval and post-trade stop-loss monitoring
  4. 1 Reporter Agent aggregates P&L across all portfolios and generates structured JSON/CSV reports

On $1M capital over 250 trading days, the swarm returned +4.62% ($46,155 profit) with a max drawdown of just 0.46%.


Workflow / Pipeline

StepDescription
1. Data IngestionDataLoader fetches S&P 500 tickers and downloads historical OHLCV data via yfinance — cached as CSVs for reproducible reruns
2. Market Environment InitMarketEnvironment loads historical data, initializes the trading clock, and exposes a day-by-day market feed to all agents via the message bus
3. Signal Generation3 Analyst Agents compute SMA crossovers and volume trends per symbol each day — publishing typed SignalMessage events to the async pub/sub bus
4. Pre-Trade Risk ValidationRisk Managers evaluate each order against position size limits and concentration thresholds before any trade executes — approving or rejecting in real time
5. Trade Execution4 Trader Agents consume approved signals, place orders at current day prices, and update their Portfolio objects with new positions and cash balances
6. Stop-Loss MonitoringAfter each trading day, Risk Managers scan all open positions against STOP_LOSS_PERCENT=0.10 — autonomously closing any that breach the threshold
7. P&L AggregationReporter Agent collects daily snapshots from all 4 Trader portfolios and appends records to reports/daily_pnl.json and reports/trades_history.csv
8. Simulation ReportAt run completion, the Reporter outputs a final summary — total return, max drawdown, trade count, approval rate, and per-agent breakdown

Repository & Artifacts

dakshjain-1616/Stock-trading-Agent-Swarm---BY-NEOView on GitHub

Generated Artifacts:


Technical Details


Results

Simulation Summary (250-Day Backtest, $1M Capital)

============================================================ STOCK TRADING AGENT SWARM — SIMULATION RESULTS ============================================================ Capital Configuration: Total Capital: $1,000,000 Per-Trader Allocation: $250,000 × 4 agents Performance Metrics: Total Return: +4.62% ($46,155 profit) Max Drawdown: 0.46% Simulation Period: 250 trading days Data Source: S&P 500 historical (yfinance) Trade Statistics: Total Trades Executed: 86 Order Approval Rate: 86.9% Orders Blocked (Risk): 26 Stop-Losses Triggered: 20 Agent Activity: Analyst Agents (×3): SMA crossovers + volume trend signals Trader Agents (×4): Order execution — $250K portfolios each Risk Managers (×2): Pre-trade approval + stop-loss monitoring Reporter Agent (×1): Daily P&L aggregation + final report ============================================================

Risk Layer Breakdown

Pre-Trade Validation: Orders Submitted: 112 Orders Approved: 86 (86.9%) Orders Blocked: 26 (23.2%) Block Reasons: Position size limit (18), Concentration risk (8) Post-Trade Monitoring: Stop-Losses Triggered: 20 Avg Loss at Trigger: -8.3% (within 10% threshold) Capital Protected: Est. $34,000+ in avoided further losses

Best Practices & Lessons Learned


Next Steps


References

View source on GitHub


Learn More