Trading Town — agent-based artificial stock market
Agent-based artificial stock market — a deterministic, unit-tested Rust engine (Santa Fe ASM) where traders evolve forecasting rules via a genetic algorithm, wrapped in a Tauri 2 + PixiJS desktop world.

What I built
- Implemented the Santa Fe Artificial Stock Market (Arthur et al., 1996) as a deterministic, unit-tested Rust engine where traders evolve classifier-based forecasting rules under a genetic algorithm.
- Drove the simulation with real exogenous price history, letting bubbles, herding and volatility clustering emerge from agent behaviour and social-network rule copying rather than scripted logic.
- Built a Tauri 2 desktop app with a PixiJS pixel world and a per-agent inspector surfacing each trader's active rule, forecast, conviction and signal usage.
How a trading day works
- The real share price moves, and the town reads it off the notice board.
- Every trader picks its best-matching rule and forecasts tomorrow's return.
- It takes a long or short position, sized by conviction divided by recent volatility.
- Money is settled on the actual move: right calls grow wealth, wrong calls shrink it.
- Every rule that fired learns from its error; periodically a genetic algorithm breeds the fittest rules and traders copy successful neighbours, which is where herding comes from.
The traders
- Five guilds you can mix in one run (Value, Calm, Bubbly, Herders and Reckless), each with its own temperament, herding tendency and risk appetite.
- Click any townsperson to see its active rule, forecast, conviction and the market signals it watches.
- A live insights column tracks the strategy mix (trend vs contrarian), belief spread, signal usage and a per-guild wealth leaderboard.
Design decisions
- Real data: daily price history from Yahoo Finance (AAPL, MSFT, NVDA, TSLA and more), with an offline fallback. The price is exogenous, so the town reacts to the market rather than inventing it.
- Deterministic: the same seed always produces the same run, so bubbles and crashes can be replayed and compared.
- Honest labels: with a real price there is no fundamental value in the model, so strategies are called trend vs contrarian rather than fundamentalist vs trend-follower.
- A research and learning sandbox, not a trading or forecasting tool.
Built by Nijeesh NJ, AI Engineer in Bengaluru. See more projects.