Build a Simulation Monitor
A 6-chapter project tutorial. You will build a trading simulation that generates events, detect patterns with fabula's incremental engine, react to matches in real time, score them by surprise, and use engine forking for speculative "what-if" analysis.
| Total time | ~2 hours |
| Difficulty | Intermediate |
| Prerequisites | Getting Started, basic Rust |
What you'll build
A command-line program that:
- Runs a simple trading simulation producing timestamped events (trades, price changes, alerts)
- Detects three patterns: insider trading (sequence + negation), market manipulation (repeat-range), and flash crash (concurrent group)
- Reacts to
SiftEvent::CompletedandSiftEvent::Negatedas they occur - Uses
why_notto explain near-misses - Scores matches with
SurpriseScorerandStuScorer - Forks the engine to evaluate hypothetical "what if this trade happened?" scenarios
Chapters
| # | Chapter | What you learn |
|---|---|---|
| 1 | Simulation Loop | Build an event-producing simulation with MemGraph |
| 2 | Define Patterns | Write 3 patterns using both builder API and DSL |
| 3 | Incremental Matching | Wire the engine into the simulation loop |
| 4 | React to Events | Handle SiftEvents, drain matches, use deadlines |
| 5 | Score and Rank | Add surprise scoring to rank matches |
| 6 | Speculate with MCTS | Fork the engine for what-if analysis |
Each chapter builds on the previous one. Complete code at the end of each chapter.
Setup
cargo new fabula-monitor
cd fabula-monitor
Add to Cargo.toml:
[dependencies]
fabula = { path = "../fabula/crates/fabula" }
fabula-memory = { path = "../fabula/crates/fabula-memory" }
fabula-dsl = { path = "../fabula/crates/fabula-dsl" }
fabula-narratives = { path = "../fabula/crates/fabula-narratives" }
Or, if using published crates:
[dependencies]
fabula = "0.1"
fabula-memory = "0.1"
fabula-dsl = "0.1"
fabula-narratives = "0.1"