This repository implements a simulation framework for studying optimal execution in competitive markets using Mean-Field Games (MFGs) under latent market dynamics.
The project is inspired by:
Philippe Casgrain & Sebastian Jaimungal
Algorithmic Trading in Competitive Markets with Mean Field Games
The framework models:
- heterogeneous trading agents
- latent market regimes
- endogenous price impact
- posterior filtering
- aggregate equilibrium interactions
The long-term objective is to analyze how strategic execution changes under:
- imperfect information
- finite-population effects
- parameter misspecification
- varying market impact regimes
A hidden Markov process governs the latent drift state:
with regime switching intensities:
The fundamental asset evolves as:
Agents collectively generate endogenous price impact through aggregate order flow:
where:
-
$$F_t$$ : fundamental price -
$$\lambda$$ : impact coefficient -
$$\bar{\nu}_t$$ : mean trading rate
Each agent chooses a continuous trading rate:
based on:
- filtered belief of latent drift
- inventory level
- risk aversion
- aggregate market behavior
The control objective penalizes:
- inventory risk
- execution cost
- terminal inventory
- deviation from equilibrium liquidation
The equilibrium is determined through a fixed-point interaction between:
- individual optimal controls
- aggregate market flow
- endogenous impacted prices
The current implementation uses:
- finite-agent simulation
- iterative mean-field approximation
- posterior filtering for latent state estimation
Mean-Field-Game-Simulation-for-Optimal-Execution/
├── src/
│ ├── main.py # Entry point
│ ├── params.py # Model parameter configuration
│ ├── latent.py # Hidden Markov latent drift dynamics
│ ├── filtering.py # Posterior belief filtering
│ ├── control.py # Optimal control computation
│ ├── equilibrium.py # Mean-field equilibrium solver
│ ├── population.py # Heterogeneous agent population
│ ├── simulate.py # Simulation engine
│ ├── pipelines.py # End-to-end experiment pipelines
│ └── plotting.py # Visualization utilities
├── experiments/
│ ├── verify_filtering.py # Posterior filter validation
│ ├── verify_mean_field.py # MFG equilibrium convergence check
│ ├── verify_price_impact.py # Price impact decomposition test
│ └── verify_sensitivity.py # Risk-aversion parameter sweep
├── scripts/
│ ├── run_full_demo.py # Full simulation pipeline
│ ├── run_control_demo.py # Control dynamics demo
│ ├── run_latent_demo.py # Latent regime demo
│ ├── run_population_demo.py # Population heterogeneity demo
│ └── run_subpop_demo.py # Subpopulation analysis demo
├── docs/
│ ├── equation_map.md # Mathematical notation reference
│ ├── parameter_table.md # Parameter definitions and defaults
│ └── symbol_table.md # Symbol glossary
├── assets/ # README figures
├── output/figure/ # Generated simulation plots
├── requirements.txt
└── README.md
- heterogeneous liquidation behavior
- aggregate vs subpopulation inventory trajectories
- risk-aversion sensitivity
- fundamental vs impacted prices
- endogenous market impact
- aggregate execution pressure
- latent regime estimation
- belief dispersion across agents
- filtering under noisy observations
- iterative equilibrium computation
- Picard fixed-point convergence
- numerical stability diagnostics
git clone https://github.com/SpencerOzgur/Mean-Field-Game-Simulation-for-Optimal-Execution.git
cd Mean-Field-Game-Simulation-for-Optimal-Executionpython -m venv venv
source venv/bin/activatepip install -r requirements.txtpython src/main.pyAll model parameters are configured in:
src/params.py
Key configurable components include:
| Category | Parameters |
|---|---|
| Latent Dynamics | lambda01, lambda10, A0, A1 |
| Simulation | sigma, lambda_ |
| Execution | Q0, T, N |
| Subpopulations | prior, kappa, weight |
The implementation currently combines:
- hidden Markov filtering
- finite-agent simulation
- iterative mean-field approximation
- discretized stochastic dynamics
This repository is intended as a research-oriented simulation framework rather than a production trading system.
The simulation framework generates quantitative diagnostics across:
- price impact dynamics
- inventory liquidation behavior
- posterior filtering distortion
- mean-field equilibrium convergence
The following results were generated from the baseline heterogeneous-agent experiment.
| Metric | Value |
|---|---|
| Terminal Fundamental Price | 100.1459 |
| Terminal Impacted Price | 100.0959 |
| Terminal Price Distortion | -0.0500 |
| Mean Absolute Price Distortion | 0.0207 |
| Maximum Absolute Price Distortion | 0.0500 |
The endogenous impact term produces a persistent deviation between the fundamental and impacted market prices. Aggregate execution pressure generated an average distortion of approximately 2.1 bps throughout the simulation horizon.
| Metric | Value |
|---|---|
| Terminal Aggregate Inventory | 0.0000 |
| Mean Terminal Individual Inventory | 0.0300 |
| Std. Terminal Individual Inventory | 0.0425 |
| Mean Individual Trading Volume | 0.9988 |
| Std. Individual Trading Volume | 0.0726 |
The aggregate population successfully liquidates inventory by terminal time while preserving heterogeneous liquidation trajectories across individual agents.
| Metric | Value |
|---|---|
| Mean Aggregate Trading Rate | 1.0000 |
| Maximum Aggregate Trading Rate | 3.1346 |
| Aggregate Trading Volume | 1.0000 |
| Metric | SubPop1 | SubPop2 |
|---|---|---|
| Risk Aversion |
0.5 | 2.0 |
| Mean Trading Rate | 1.0000 | 1.0000 |
| Maximum Trading Rate | 1.9421 | 4.3272 |
| Posterior Distortion | 0.2232 | 0.2260 |
Higher-risk-aversion agents exhibit significantly larger peak trading intensities despite maintaining similar aggregate liquidation volumes.
| Metric | Value |
|---|---|
| Mean Fundamental Posterior | 0.6473 |
| Mean Impacted Posterior | 0.4228 |
| Mean Absolute Posterior Difference | 0.2246 |
| Maximum Absolute Posterior Difference | 0.6112 |
Endogenous market impact materially alters latent-state inference. Filtering under impacted observations produces substantial posterior distortion relative to the fundamental process.
| Metric | Value |
|---|---|
| Initial Fixed-Point Error | 0.1000 |
| Final Fixed-Point Error | 0.0010 |
| Error Reduction Factor | 100× |
| Picard Iterations | 7 |
The iterative fixed-point procedure demonstrates stable contraction behavior and converges to the prescribed tolerance within seven iterations.
-
Casgrain, P., & Jaimungal, S. Algorithmic Trading in Competitive Markets with Mean Field Games
-
Carmona, R., Delarue, F. Probabilistic Theory of Mean Field Games
-
Guéant, O. The Financial Mathematics of Market Liquidity
Spencer Ozgur M.S. Financial Engineering — Columbia University B.S. Computer Science — Arizona State University




