Inspiration
Financial illiteracy is no longer an access problem. It's a behavior problem.
India crossed 150 million demat accounts last year. Most were opened in the last five years by first-time investors with no formal training in markets, risk, or self-control. The result is predictable: 76% of retail investors lose money in their first three years — not because they lack information, but because of FOMO, revenge trading, sunk-cost averaging, and tip-driven trades from WhatsApp groups.
Textbooks describe these biases. They cannot trigger them. Demo trading accounts simulate price action but never the emotion that bankrupts traders. Scams like Harshad Mehta's 1992 fraud and FTX's 2022 collapse get taught as B-school case studies a decade after they have already destroyed millions of portfolios.
We built FinSim on a single hypothesis: if a learner feels a bias while trading, and a coach names it within 50 milliseconds, the lesson encodes permanently. The next time the same trigger appears in real life — a tweet, a pump, a loss streak — their brain recognizes the pattern, because they have already felt it in a safe sandbox.
That sandbox is FinSim.
What it does
FinSim is a 2D pixel-art financial metaverse where retail investors learn the techniques, methodology, and discipline of real trading — using fake currency, live market data, and a Gemini-powered AI coach that intervenes the moment a behavioral mistake happens.
The world is divided into six walkable districts, each engineered as a hands-on lab for a specific financial domain:
| District | What you master | Live data source |
|---|---|---|
| Wall Street | US equities, position sizing, the 1% rule, stop-loss discipline | Yahoo Finance |
| Dalal Street | Indian markets in INR, microstructure, FIFO tax lots, STCG/LTCG | NSE/BSE feeds |
| Crypto Cove | DeFi, AMM math (x · y = k), impermanent loss, rug-pull detection |
CoinGecko + Etherscan |
| Quant Quarter | Sharpe ratio, factor models, backtest honesty, out-of-sample testing | Custom engine |
| Vegas Vice | Expected value, Kelly criterion, the math of negative-EV games | Procedural |
| Scam Slum | Pattern recognition for fraud, MLM schemes, fake tips | 14 recreated scams |
The behavioral engine is the centerpiece. Every order ticket is intercepted by seven bias detectors before execution: FOMO, revenge trading, naked trade (no stop-loss), news-roulette (trading inside event windows), tweet-trade (post-social-media buys), overconfidence, concentration risk. When any detector fires, a Bias Toast surfaces in under 50ms with the option to cancel the trade — the player learns by being interrupted at the exact moment of the mistake.
Press I and the Bias Profile dashboard opens: top bias, FOMO percentile against retail baselines, patience score, disposition ratio (cutting winners early vs. riding losers), and median holding time. When signed in via Firebase Auth, a Gemini Pro Cloud Function generates personalized coaching from the player's actual pattern — no two learners receive the same advice.
And then there is Echo Mode — 14 anonymized historical scenarios. The player is dropped into a real chart from history with no labels, makes their call, and watches the reveal: you just executed Soros's 1992 short of the British pound. Or Burry's 2008 housing short. Or — sometimes — Harshad Mehta's bank receipt fraud, and the game ends in jail. The lesson lands with the same emotion the original trader felt.
How we built it
Stack: TypeScript 5.3 · Phaser 3.80 · Vite 5 · Firebase Auth & Firestore · Cloud Functions · Vertex AI (Gemini Pro). ~14,300 lines of TypeScript across 75+ modules, zero spritesheets, zero audio files, sub-500KB production bundle.
Architecture decisions that defined the project
1. Hybrid Phaser + DOM, communicating through the registry bus.
The Phaser canvas owns the game world — movement, physics, particles, tilemaps. The DOM owns every HUD, terminal, modal, and dashboard. Forms and tables are 10× more flexible in DOM; canvas is better for animated tiles. Scenes never import UI classes — they read callbacks from game.registry, achieving zero coupling between game world and UI layer.
2. Singletons + pub/sub. No React. No Redux.
Every system — PortfolioSystem, MarketEngine, BehaviorTracker, BiasProfile, TaxLedger — is a singleton exposing subscribe(fn) → unsub. UI modules re-render on notify. The result: zero global-state library overhead, zero re-render storms, and a single source of truth backing every chart, ticker, and modal.
3. Procedural everything. No PNG spritesheets. No MP3 files. Every NPC is a 32×32 RenderTexture drawn from a palette object at scene load. Every sound effect — train horn, station bell, brake squeal — is synthesized live in Web Audio with layered oscillators and ADSR envelopes. The entire game ships in under 500KB, critical for low-end Indian mobile networks.
4. Graceful offline fallback at every boundary. A Geometric Brownian Motion price simulator runs underneath every live feed at 2-second tick intervals. Missing Finnhub key? Seeded data takes over. Missing Firebase? Local leaderboard with 20 seeded bots. Learning never breaks because the network is unreliable.
5. The AI coach: Gemini Pro at fractional cost. When a bias fires for a signed-in user, we call a Firebase Cloud Function on Vertex AI. To control inference cost, we hash-bucket the user state — win rate quantized to 10%, FOMO percentile to 20%, trader tier to category. Equivalent triggers reuse the cache, reducing unique LLM calls by ~85% while preserving the feel of personalization. A hard 4-second timeout ensures the canned coaching string is faster than a slow LLM call. Any error returns null and falls through gracefully.
Challenges we ran into
Pre-trade vs. post-trade bias detection.
Our first version logged biases to the journal after execution. It was useless — the lesson was retrospective, the money was already gone. We rewrote behaviorTracker.checkPreTrade(ctx) to run synchronously inside the order ticket with a 50ms latency budget. Hitting that budget required pre-computing rolling windows of recent trades, candle returns, and event-window flags — every detector had to be O(1) at decision time.
LLM cost vs. personalization at scale. Calling Gemini on every bias trigger was financially impossible at meaningful user counts. Hash-bucketing the user state cut unique LLM calls by ~85% while keeping the coaching personally relevant. This is the difference between an unsustainable demo and a product that costs ~$0.065 per monthly active user.
Procedural sound that doesn't sound procedural. Web Audio out of the box sounds like a 1990s synthesizer. The cinematic train horn that opens every district transition required layering three sawtooth oscillators (165, 220, 330Hz) with a noise-based steam puff and a per-layer ADSR envelope. The station bell — a descending major-third "ding-dong" — needed carefully tuned decay curves to feel ambient instead of robotic.
Echo Mode without spoilers. The reveal only lands if the player cannot pattern-match the scenario from chart shape alone. We anonymize tickers, scrub headline names, and add ±2% noise to anchor points — enough to disguise the chart while preserving the macro story. Get this wrong and the entire pedagogy collapses.
Accomplishments that we're proud of
- Six fully walkable districts — bespoke art, NPCs, dialogues, and curricula, every asset generated procedurally
- Seven-detector behavioral engine firing real interventions in under 50ms with optional trade cancellation
- 27 dialogue trees and 14 Echo Scenarios spanning Soros 1992, GameStop 2021, FTX, Madoff, LTCM, Burry 2008, Bitconnect, and more
- Live integrations with Finnhub, FRED, NewsAPI, Etherscan, and CoinGecko — each with curated offline fallback
- Firebase + Vertex AI + Gemini Pro pipeline delivering personalized coaching at production-grade unit economics through hash-bucketed caching
- FIFO tax ledger auto-classifying STCG and LTCG on every sell — teaches Indian capital-gains taxation by showing it, not explaining it
- Sub-500KB production bundle with zero asset files, fully playable on a 3G connection
- 14,300 lines of TypeScript across 75+ modules
What we learned
Interventions must fire before the action, not after. Reflection after a loss is therapy. Interruption before a loss is education. The 50ms latency budget reshaped the entire architecture.
Spatial memory beats text every time. "The lesson I learned at Quant Quarter" sticks in a way no textbook chapter ever does. The metaverse isn't a gimmick — it is the pedagogy.
Procedural assets are a feature, not a constraint. Every sprite, sound, and animation generated in code means infinite variation, zero asset pipeline, instant load times, and a sub-500KB bundle that runs on any device.
LLM cost engineering is a product feature. Hash-bucketing isn't a workaround — it's the architectural choice that turns a clever demo into a financially viable product at scale.
Singletons + pub/sub outperform React for game UI. Zero coupling between Phaser and DOM, zero re-render storms, and a debugger that actually works. We will never go back.
What's next for FinSim
Months 1–3 — Foundation. Order book and Level 2 depth simulation. Realistic fills, slippage, partial executions. Personalized Bias Profile dashboard with longitudinal analytics. Decision Replay with Mira voice synthesis (ElevenLabs).
Months 4–7 — Reach. Mobile companion app (React Native). Hindi and Punjabi localization for tier-2 and tier-3 cities. Full Gemini-powered Mira tutor with multi-turn conversation and safety layer. Weekly AI Trade Coach review service (Cloud Run). Daily mission loop and Trade Cards sharing for social virality.
Months 8–12 — Depth. Personal Finance Plaza, Forex Plaza, and Bias Lab as the 7th, 8th, and 9th districts. Tick-replay Echo Scenarios with millisecond fidelity. Options Greeks visualization and strategy builder. Trading Clubs for cohort-based multiplayer learning.
Months 13–18 — Defensibility. FinSim Trader Score (0–1000) with verifiable, hashed LinkedIn certificates. University partnerships across the IITs, IIMs, and North American business schools. Real Estate Row and Bond Bazaar districts. Algorithmic trading sandbox via Pyodide for in-browser Python. Steam launch and a community modding ecosystem.
The vision. FinSim becomes to financial education what Duolingo is to language: the daily streak, the verifiable credential, the loop that turns a beginner into someone who can survive a real market. And — quietly, in the background — the product that prevents the next 150 million retail investors from learning finance the most expensive way possible.
Built With
- alpha-vantage
- cloud-run
- coingecko
- css3
- etherscan
- finnhub
- firebase
- firebase-auth
- firebase-cloud-functions
- firestore
- fred-api
- gemini
- gemini-pro
- github
- google-cloud
- html
- html5
- javascript
- newsapi
- node.js
- phaser.js
- typescript
- vertex-ai
- vite
- web-audio-api
- yahoo-finance
Log in or sign up for Devpost to join the conversation.