What happens when you let autonomous agents trade against each other? This project simulates a complete stock market where AI agents with different personalities and strategies compete for profit. Watch as market bubbles form, crashes unfold, and emergent behaviors arise from simple interactions.
basic_scenario.movThis video shows a basic bubble-and-crash scenario. You can see the price chart reacting in real-time as news events trigger buying frenzies and panic sells. The bubble forms as follower agents pile in, then pops when negative news hits. This gives you a quick sense of what to expect—emergent market dynamics from simple agent rules.
This is a multi-agent trading simulation built on JADE (Java Agent DEvelopment Framework) that recreates realistic market dynamics. Each agent has its own beliefs about the market, personal goals, and trading strategy. They react to price movements, news events, and each other's behavior—creating surprisingly realistic market patterns.
The system runs with 60x time acceleration, so you can watch an entire day of trading play out in under a minute.
The central authority that provides liquidity and keeps the market running. It maintains an order book, adjusts bid-ask spreads based on volatility, and executes all trades. Think of it as the exchange itself.
Beliefs: Order flow, total volume, market volatility Goals: Keep spreads tight, maintain liquidity, stay profitable Strategy: Adjust prices based on supply/demand imbalances
The cautious value investor who prioritizes capital preservation over quick gains.
Beliefs: Moving averages, long-term trends, fundamental ratios Goals: Steady 5-10% annual returns with minimal risk Strategy: Buy dips, sell modest rallies, use stop-losses (5%) and take-profits (10%)
The momentum chaser looking for explosive gains and willing to take big risks.
Beliefs: Short-term technical signals, momentum indicators, volume spikes Goals: High returns (>20%) regardless of volatility Strategy: High-frequency trading, leveraged positions, ride the trends hard
The herd. They watch what successful traders do and copy them, amplifying trends.
Beliefs: Other traders' actions, market sentiment, social signals Goals: Follow winning strategies Strategy: Mimic profitable traders, creating feedback loops
Generates market-moving news events that shift sentiment and trigger reactions.
Strategy: Broadcasts positive/negative news at strategic times to simulate real-world information shocks
Run the default scenario and watch this play out:
Phase 1 - Calm Market (0-17%) Price hovers around $100. Conservative traders dominate. Low volume, low volatility. Nothing exciting.
Phase 2 - Emerging Trend (17-33%) NewsProvider drops good news. Aggressive trader starts buying. Followers notice and join in. Price climbs to $110. Things are heating up.
Phase 3 - Bubble Formation (33-58%) Herd behavior kicks in. Everyone's buying. Price rockets to $140. Market maker widens spreads as volatility spikes. Conservative trader gets nervous and starts reducing positions.
Phase 4 - The Crash (58-75%) Bad news hits. Aggressive trader's stop-losses trigger. Panic selling ensues. Price plummets to $70. Conservative trader quietly starts buying again at bargain prices.
Phase 5 - Stabilization (75-100%) Market finds equilibrium around $85. Agents update their beliefs based on what just happened. Lessons learned (until next time).
Every trader follows the Beliefs-Desires-Intentions cognitive model:
Agents continuously update their beliefs, evaluate their desires, and form intentions that drive trading decisions.
Agents communicate via ACL (Agent Communication Language) messages:
The system tracks realistic performance indicators:
- Market: Average price per period, volatility (standard deviation), total volume, transaction count
- Per Agent: P&L, Sharpe ratio (return/risk), win/loss ratio, maximum exposure
Other scenarios: STABLE_MARKET, BULL_MARKET, BEAR_MARKET, VOLATILE_MARKET, NEWS_DRIVEN, PANIC_SCENARIO
The platform generates real-time price charts (saved to charts/) and complete trading logs (saved to sessions/).
Emergent Behavior: No agent is programmed to create bubbles or crashes. These patterns emerge naturally from the interactions between agents with different strategies and information.
Realistic Dynamics: The herd behavior, panic selling, and contrarian value buying you see here mirror real market psychology. Follower agents amplify trends. Conservative agents buy the dip. News shocks trigger cascades.
Time Acceleration: The 60x speedup lets you rapidly test scenarios that would take hours in real-time. Great for exploring edge cases and parameter tuning.
Full Observability: Unlike real markets, you can see exactly why each agent made each decision. Perfect for studying market microstructure and agent reasoning.
Some ideas if you want to hack on this:
- Limit orders: Currently only market orders are supported
- Multiple assets: Expand to portfolio optimization across correlated stocks
- Leverage and margin calls: Add realistic risk management constraints
- Machine learning agents: Train agents on historical data to develop strategies
- Market manipulation: Add a manipulator agent and see if others can detect it
- Flash crashes: Model cascading stop-loss orders and circuit breakers
Multi-agent systems are a powerful way to model complex social dynamics. Markets are just one application. The same techniques work for:
- Modeling economic systems and policy impacts
- Simulating traffic patterns and autonomous vehicle coordination
- Analyzing social network dynamics and information spread
- Testing algorithmic trading strategies before risking real money
The key insight: complex aggregate behavior often emerges from simple individual rules. You don't need to model the entire market—just model the participants.
Built with JADE for robust agent lifecycle management, message passing, and service discovery. Each agent runs autonomously with cyclic behaviors that process messages, update beliefs, and execute strategies.
The MarketMaker handles order matching, price discovery, and portfolio management. Traders register themselves, subscribe to market data feeds, and submit orders asynchronously.
Technical indicators (MA20/50, RSI, MACD, momentum) are calculated in real-time as beliefs are updated. News events decay in impact over time with exponential falloff.
A simulation where greed, fear, and herd mentality drive prices—just like the real thing.
.png)

