Building a High-Performance C++ Backtesting Framework with Order Simulator

yiweileng1 pts0 comments

Building a High-Performance C++ Backtesting Framework with an Order Matching Simulator Plugin | by DolphinDB | Jul, 2026 | MediumSitemapOpen in appSign up<br>Sign in

Medium Logo

Get app<br>Write

Search

Sign up<br>Sign in

1. Background<br>2. System Design<br>3. Interface Design3.1 Configuration Items

3.2 Interfaces3.2.1 Create an Order Matching Simulator<br>3.2.2 Replay Market Data<br>3.2.3 Market Data Callbacks<br>3.2.4 Implement a Strategy<br>3.2.5 Order Submission/Cancellation Responses and Notifications

4.1 Implementation Using Swordfish4.1.1 Remote Connection<br>4.1.2 Plugin Loading and Usage<br>4.1.3 Streaming Data Subscription, Parsing, and Callback Handling

4.2 Implementation Using the C++ API4.2.1 Remote Connection<br>4.2.2 Plugin Loading and Usage<br>4.2.3 Streaming Data Subscription, Parsing, and Callback Handling

5. Backtesting Example<br>6. Performance Testing<br>7. Summary

Building a High-Performance C++ Backtesting Framework with an Order Matching Simulator Plugin

DolphinDB

12 min read·<br>1 hour ago

Listen

Share

Press enter or click to view image in full size

For institutions that have already built a C++ backtesting framework, rebuilding the entire system to support more realistic order matching and high-performance market replay is often impractical. DolphinDB’s high-performance market data replay and Order Matching Simulator Plugin provides a low-latency, high-throughput solution for strategy validation. By integrating the plugin directly into an existing C++ backtesting framework, institutions can reuse their current infrastructure while taking advantage of DolphinDB’s ultra-fast computing capabilities, making it an ideal solution for high-frequency strategy simulation.<br>This tutorial is intended for quantitative engineers who are familiar with C++ development and have a basic understanding of DolphinDB. It focuses on how to seamlessly integrate the DolphinDB order matching simulator plugin into a standalone C++ trading system by using either the Swordfish library or the C++ API. Compared with backtesting in the DolphinDB scripting language, this approach delivers a low-latency, highly concurrent backtesting workflow and is particularly well suited to time-sensitive simulation scenarios such as algorithmic trading and market-making strategies.<br>1. Background<br>Backtesting is a critical part of quantitative trading research and development. Before a quantitative strategy is applied to live trading, its performance on historical data must be evaluated through backtesting. In medium- and high-frequency strategy backtesting, you cannot simply assume that every order is filled in full at the current price or the end-of-day price. Instead, you need an order matching simulator to model the actual trading process, including whether an order can be filled, the execution price, trading volume, and market impact. DolphinDB provides an order matching simulator plugin that supports Level-2 tick-by-tick and snapshot market data from the Shanghai and Shenzhen stock exchanges. It delivers high-precision order matching consistent with exchange rules under the “price priority, time priority” principle, supports matching modes based on multiple types of market data, and offers extensive order matching configuration options to simulate real-world trading conditions. It also supports medium- and high-frequency quantitative trading strategy development and testing in the DolphinDB scripting language, Python, and C++, providing a high-performance and highly extensible backtesting solution.<br>Swordfish is a high-performance analytical computing library designed specifically for the financial industry, with excellent in-memory processing capabilities and optimized computational performance. In addition to a wide range of general-purpose computing functions, it supports real-time streaming data processing and user-defined functions to meet the needs of complex analytics and low-latency stream processing. Swordfish runs on any platform that supports C++, and users can invoke its APIs directly in C++ code for efficient computation.<br>The DolphinDB C++API can connect to the DolphinDB server and a C++ client, enabling bidirectional data transfer and remote script execution. It lets you conveniently use DolphinDB in C++ programs for data processing, analysis, modeling, and more, helping you accelerate these workloads with DolphinDB’s excellent computing performance and powerful storage capabilities.<br>This tutorial explains how to encapsulate the order matching simulator plugin in C++ to build a simple, extensible backtesting framework with high-precision order matching, which can be easily integrated into an existing C++ backtesting or simulation system. This tutorial defines a unified event-driven interface and provides two implementations: Swordfish and C++API. The applicable scenarios for the two approaches are as follows:<br>Table 1–1 Scenario comparison between the Swordfish and C++API backtesting framework implementations<br>Press enter or click to view image...

order backtesting high matching dolphindb performance

Related Articles