Skip to content

About

Event-driven trading simulator in C++17 modeling market data ticks, momentum-based order generation, risk checks, execution, portfolio MTM PnL, and latency/throughput metrics.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

This project is a minimal event-driven trading engine simulator written in modern C++ (C++17). Its goal is not to model a realistic financial market, but to demonstrate how the core components of a trading system interact in a clean, modular, and performance-aware architecture.

The engine follows a message-passing / event-queue design, where all interactions between components are expressed as events flowing through a single queue. This mirrors the structure of real trading systems, where market data, orders, and executions are processed asynchronously and in strict sequence.

The simulation includes:

        Market data generation
        A synthetic market data feed produces price ticks following a normal distribution. Each tick carries a sequence number and a high-resolution timestamp, simulating a real-time feed.

        Strategy layer
        A simple momentum-based strategy reacts to incoming ticks by comparing the current price to the previous one. If the price movement exceeds a configurable threshold, the strategy generates a market order request (buy or sell).

        Risk checks
        Before execution, all order requests pass through a basic risk layer that validates order quantities against predefined limits. This models the “gatekeeper” role of risk management in real trading systems.

        Execution simulator
        Orders that pass risk checks are immediately converted into fills at the latest market price. While simplified, this component represents the execution layer where orders interact with the market.

        Portfolio accounting
        The portfolio module updates position and cash balances on each fill and computes a mark-to-market PnL based on the latest observed price.

        Performance metrics
        The engine measures:

            Total number of processed events
            End-to-end latency (event creation → event handling)
            Latency distribution statistics (average, p50, p95, p99)
            Overall throughput (events per second)

        These metrics provide insight into the performance characteristics of the event loop and reflect concerns commonly found in low-latency and real-time systems.

The entire system runs in a single-threaded deterministic loop, prioritizing clarity and correctness over realism. All components are explicitly separated, making the code easy to extend, refactor, or optimize.

About

Event-driven trading simulator in C++17 modeling market data ticks, momentum-based order generation, risk checks, execution, portfolio MTM PnL, and latency/throughput metrics.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages