Noureddine RAMDI / MarS: a generative foundation model for realistic financial market simulation

Created Mon, 06 Jul 2026 15:15:52 +0000 Modified Mon, 06 Jul 2026 15:16:10 +0000

microsoft/MarS

Financial market simulation often relies on agent-based models with handcrafted rules to mimic trader behavior. MarS by Microsoft Research takes a different approach: it treats market orders as tokens in a sequence and uses a generative foundation model to learn the joint distribution of order types, prices, sizes, and inter-arrival times directly from historical data. This enables realistic, order-level market data generation that supports forecasting, impact analysis, and interactive market exploration.

How MarS simulates financial markets with generative foundation models

MarS is a market simulation engine designed to replicate order-level market data using a generative foundation model based on LLaMA. Instead of encoding explicit agent behaviors or hand-tuned rules, MarS reframes market simulation as a token prediction problem. Each market order—characterized by its type, price, size, and timing—is treated as a token in a sequence. The model learns the joint distribution of these tokens from historical market data and generates new sequences that mimic real market dynamics.

The system architecture splits responsibilities into three main components:

  • OrderModel: This is the core generative model that predicts the next order token based on the sequence history. It uses a LLaMA-based Transformer architecture trained on historical order flow data.

  • OrderState: Represents the current state of the simulated market, including the order book and relevant market statistics. It updates dynamically as new orders are generated.

  • OrderAgent: Orchestrates the simulation by coordinating the OrderModel and OrderState components. It manages the generation of multiple trajectories (parallel market simulations) and handles the interaction with external systems.

MarS is deployed using Ray Serve, which enables scalable inference and parallel execution. The system runs 128 trajectories in parallel on 128 GPUs, allowing robust signal generation and efficient exploration of market behaviors under different scenarios.

Technical strengths and tradeoffs in MarS’s design

The standout feature of MarS is its use of a generative foundation model to simulate market order flows at the token level. Treating market simulation as a sequence generation problem is a shift away from traditional agent-based models that rely on handcrafted rules. This approach brings several advantages:

  • Data-driven realism: By learning directly from historical data, MarS captures complex dependencies and joint distributions of order attributes that are hard to model explicitly.

  • Scalability: Using Ray Serve for distributed inference allows the simulation of many parallel market trajectories, which is essential for robust statistical analysis and downstream applications.

  • Calibration with stylized facts: MarS evaluates its simulation outputs against 11 stylized facts — well-known statistical properties observed in real financial markets. This ensures that the generated data reflects fundamental market characteristics, not just superficial patterns.

Under the hood, the generative model uses a vocabulary of tokens representing discrete order attributes, including order type (e.g., limit, market), price levels, sizes, and time intervals between orders. The model is trained to predict the next token given the sequence so far, similar to how language models predict the next word. This framing allows the use of powerful Transformer architectures and training methods developed for natural language processing.

A typical simulation run involves the OrderAgent requesting order tokens from the OrderModel, updating the OrderState accordingly, and repeating this process to generate full trajectories of market events. Parallelism is achieved by running multiple such simulations concurrently, each with independent random seeds.

There are tradeoffs to this approach. Because the model is trained on historical data, it inherits biases and limitations present in the training set. It may struggle with rare or unseen market events. Also, the core generative model remains private pending final review, limiting direct inspection of its internals. The complexity of training and deploying large Transformer models requires substantial computational resources (128 GPUs in this case), which can be a barrier for smaller teams.

Despite these tradeoffs, MarS offers a novel angle on market simulation that sidesteps the need for hand-engineered agent strategies while still producing realistic order-level data.

Quick start with MarS

The repository provides two main options to get started, both detailed in the README:

# Clone the repository
git clone https://github.com/microsoft/MarS.git
cd MarS

Then, with VS Code and the Dev Containers extension installed:

  1. Open the project folder in VS Code
  2. Important: Before reopening in container, modify the .devcontainer/devcontainer.json file to change "source=/data/" to a path that exists on your host machine
  3. When prompted, click “Reopen in Container” or use the command palette (F1) and select “Dev Containers: Reopen in Container”
  4. The container will build with all dependencies and extensions configured
  5. Once inside the container, install the project dependencies:
pip install -e .[dev]

Option 2: Using Docker Directly

# Clone the repository
git clone https://github.com/microsoft/MarS.git
cd MarS
# Build the Docker image
docker build -t mars-env -f .devcontainer/Dockerfile .

These steps set up the environment for development and experimentation with the simulation engine.

verdict

MarS is a specialized research tool that brings a fresh perspective to financial market simulation by using a generative foundation model to produce realistic order-level data. Its modular architecture and scalable deployment make it suitable for researchers and advanced practitioners interested in exploring market dynamics beyond traditional agent-based models.

The main limitation is that the core generative model is not yet publicly released, which restricts immediate use of the full simulation capabilities. The computational demands for running large-scale simulations are also significant.

If you work in quantitative finance research, market microstructure analysis, or are exploring AI-driven market modeling, MarS is worth a close look. It offers a data-driven alternative to hand-crafted simulation models and demonstrates how foundation models can be applied outside natural language processing.

For practitioners focused on production trading systems or needing lightweight simulation tools, this repo may currently feel heavyweight and experimental. But for pushing the state of the art in market simulation research, it’s a solid resource with a clean, well-documented codebase and clear evaluation metrics.


→ GitHub Repo: microsoft/MarS ⭐ 1,724 · Python