📈 Financial Market — Agent-Based Model

200 heterogeneous agents — fundamentalists, trend followers and noise traders — interact in an order book. Watch bubbles and crashes emerge spontaneously from simple behavioural rules.

🇺🇦 Українська
Price chart — price (white), fundamental value (dotted), moving average (yellow)
Order book depth — bids (green) / asks (red) around current price

Market Parameters

Market Status

● STABLE
Price100.00
Fundamental V100
P / V ratio1.000
Volatility (σ₂₀)
Bid-ask spread
Tick0

Agent Population

Fundamentalists
Trend followers
Noise traders
Price update rule:
Pt+1 = Pt · exp(λ·D̃ + σ·ε)
D̃ = excess demand/N
ε ~ N(0,1)

How the Simulation Works

200 agents each submit a buy or sell order each tick based on their type. Fundamentalists compare price to the fundamental value V: they buy when P < V(1−δ) and sell when P > V(1+δ), acting as a stabilising force. Trend followers look at the 10-tick price momentum: they buy in uptrends and sell in downtrends, amplifying movements and creating bubbles. Noise traders send random orders, injecting stochastic fluctuations. The price update is log-linear in excess demand, so the model can produce fat-tailed return distributions similar to real markets. Increase trend followers (and reduce fundamentalists) to trigger bubble-crash cycles.

About Financial Market Simulation

Agent-based financial market simulations model price formation by populating a virtual order book with heterogeneous traders: fundamentalists who buy when price falls below intrinsic value, chartists who follow trends, and noise traders who act randomly. The interaction of these agents through limit and market orders replicates key features of real markets including fat-tailed return distributions, volatility clustering, and occasional flash crashes—phenomena that simple equilibrium models cannot explain.

The order book is the core mechanism: buyers submit limit bids at various prices and sellers submit limit offers; trades occur when bid and ask prices cross. The mid-price between best bid and best ask forms the quoted price. Market microstructure—the bid-ask spread, market depth, and order flow imbalance—determines transaction costs and price impact. Agent-based models have become standard tools for stress-testing exchanges, designing circuit breakers, and studying algorithmic trading strategies.

This simulator lets you control the mix of trader types, their aggressiveness, and fundamental value to observe how different market regimes emerge. With many fundamentalists the price is stable and mean-reverting; with many trend-followers the price exhibits momentum and bubbles; with many noise traders price becomes nearly random. Real markets contain all three types, producing the rich statistical properties observed in empirical price data.

Frequently Asked Questions

What is an order book and how does it work?

An order book is a real-time list of all outstanding buy (bid) and sell (ask) limit orders at various price levels. When a new market order arrives to buy, it matches against the lowest available ask; a market sell matches the highest bid. The best bid and best ask form the spread, with trades occurring at the intersection. The order book reveals supply and demand at each price and determines the immediate market impact of large orders.

What causes fat tails in financial return distributions?

Empirically, extreme price moves occur far more often than a normal (Gaussian) distribution would predict—this is called fat tails or leptokurtosis. In agent-based models, fat tails emerge from herding: when trend-followers trigger further trend-followers, cascades of correlated orders amplify small shocks into large moves. Feedback loops between price and agent behavior, combined with endogenous liquidity crises, produce the power-law tails observed in all major financial markets.

What is volatility clustering and why does it occur?

Volatility clustering means that large price changes tend to be followed by large changes (of either sign), and calm periods cluster together—captured statistically by GARCH-type models. In agent-based markets, this arises because large moves change agents' beliefs and risk appetite, increasing order flow variability. The positive feedback between recent volatility and future volatility mirrors the behavioral herding and risk-adjusting behavior of real market participants.

How do circuit breakers prevent flash crashes?

Circuit breakers are market-wide or individual-stock trading halts triggered when prices move beyond a threshold in a short time. They give market participants time to re-evaluate, break liquidity-withdrawal spirals where market makers pull orders, and allow erroneous algorithmic orders to be cancelled. Studies of the 2010 Flash Crash (Dow dropped ~1000 points in minutes) showed that coordinated circuit breakers and order cancellation policies can significantly reduce the depth and recovery time of such events.

What is the efficient market hypothesis and how does this simulation relate to it?

The efficient market hypothesis (EMH) states that prices instantly and fully reflect all available information, making it impossible to consistently beat the market. Agent-based simulations challenge the strong form of EMH by showing that even if individual agents use public information, price dynamics can diverge from fundamental value due to coordination failures, herding, and feedback loops. The coexistence of fundamentalists and trend-followers creates predictable short-term patterns that a sufficiently sophisticated strategy could exploit, consistent with empirical evidence of short-term return autocorrelation.

About this simulation

This model recreates price discovery in a limit order book populated by 200 heterogeneous traders. Each tick, fundamentalists, trend followers and noise traders submit buy or sell orders, and the resulting excess demand feeds a log-linear price rule, P(t+1) = P(t) × exp(λ·D̃ + σ·ε), where D̃ is net demand per agent and ε is drawn from a standard normal distribution. Because growth compounds multiplicatively rather than additively, the price can never turn negative, whilst still producing the fat-tailed returns and volatility clustering seen on real exchanges. Adjust the mix of trader types to swing the market between calm mean-reversion and a full bubble-crash cycle.

🔬 What it shows

Two linked canvases: a price chart plotting the traded price against the dashed fundamental value V and a 20-tick moving average, plus a synthetic order-book depth chart showing bid and ask volume either side of the mid-price. A status panel reports the price/value ratio, realised volatility and the current market regime.

🎮 How to use

Drag Fundamental value V, Fundamentalists %, Market impact λ, Noise σ and Trend sensitivity to reshape agent behaviour; the population of 200 agents rebuilds instantly. Use ⏸ Pause / ▶ Resume to freeze the simulation and study the current price path and order book.

💡 Did you know?

The price rule is a discrete geometric random walk with a demand-driven drift term, from the same mathematical family used in Black-Scholes option pricing — which is why turning up λ alone can transform gentle noise into runaway bubbles.

Frequently asked questions

How does the price update on each tick?

Every agent casts a buy or sell order, and their net excess demand D̃ (demand divided by 200) is combined with a random noise term ε and fed through P(t+1) = P(t) × exp(λ·D̃ + σ·ε). The market impact λ controls how strongly demand moves price, whilst σ controls the size of the random shock.

What distinguishes fundamentalists, trend followers and noise traders?

Fundamentalists buy when the price sits more than 3% below the fundamental value V and sell when it sits above, acting as a stabilising anchor. Trend followers buy when the 10-tick momentum is positive and sell when it is negative, amplifying moves into bubbles or crashes. Noise traders simply buy or sell at random each tick.

How is the market regime classified as stable, bubble or crash?

The regime badge compares the current price to the fundamental value V. A price/value ratio above 1.2 is labelled a bubble, below 0.8 a crash, and anything in between is classed as stable.

What do the market impact λ and noise σ sliders control?

Market impact λ scales how much excess demand pushes the price on each tick, so a higher λ produces sharper swings for the same order flow. Noise σ scales the size of the random shock added every tick, representing idiosyncratic order flow unrelated to fundamentals or trends.

Why does volatility get measured over a 20-tick window?

Realised volatility is calculated as the standard deviation of the log returns over the most recent 20 ticks, giving a rolling measure of how turbulent recent trading has been, similar to how short-window realised volatility is estimated from real intraday price data.