End-to-End HFT Mini Capstone
Read at your own pace. Code execution, quizzes, progress tracking, and the AI tutor are available in the interactive view with JavaScript enabled.
Bring It Together
The final trading loop
Now that we've covered Deployment, Monitoring & Performance Tuning, we're ready for the course finish line: a small end-to-end HFT-style lab.
This capstone is not a real exchange connector and it is not investment advice. It is a systems integration exercise that ties together what you built across the course:
- replayed market data from Backtesting, Simulation & Replay
- parsed feed events from Feed Message Parsing in C++
- simple top-of-book state from Market Data Handling & Order Book Reconstruction
- signal generation from Statistical Arbitrage & Latency Strategies
- risk gates from Pre-Trade Risk Checks
- OMS-style state from Order Management & FIX Integration
- metrics and preflight from the previous deployment lesson
The goal is simple: one replayed event goes in; a safe, observable decision comes out.

Capstone Shape
One process, many responsibilities
Earlier production lessons described a multi-service topology. For the mini capstone, we compress that topology into one C++ process so you can see the full path clearly.
sample_feed.txt
|
v
Replay reader -> Parser -> Top-of-book state -> Strategy
|
v
Risk gate
|
v
OMS order record
|
v
Fill simulator + metrics
The important habit is not the number of files. The important habit is the boundary discipline:
- parser returns typed events, not loose strings
- book state owns market prices
- strategy proposes intent, not final authority
- risk approves or rejects before orders exist
- OMS records the state transition
- metrics summarize what happened
This is the same mental model you would use in a larger system, just scaled down for a beginner-friendly C++ lab.

Lab File Plan
Where this fits in trading-lab/
Use the project shape from Trading Lab Project Skeleton. A clean capstone version can start with this layout:
trading-lab/
include/
trading_lab/
types.hpp
src/
capstone_main.cpp
data/
capstone_feed.txt
config/
capstone.conf
build/
For learning speed, the next code examples are standalone. In your lab, you can split them later:
-
types.hpp:Side,Quote,Order,Metrics -
capstone_main.cpp: replay loop and orchestration -
capstone_feed.txt: deterministic event input -
capstone.conf: symbol and risk limits
A useful final project is not huge. It is small enough to reason about and structured enough to extend.
Event Contract
Start with deterministic input
Before the full loop, lock down the event contract. This example reads a tiny replay feed where each line is:
sequence symbol bid ask
Example:
1 ESU5 5000.25 5000.50
2 ESU5 5000.00 5000.25
3 ESU5 4999.75 5000.00
The parser performs the same job you practiced earlier: convert text into a typed object and reject malformed input. Deterministic input makes debugging fair: if the program changes behavior, the cause is your code, not the data source.
```cpp
#include <iostream>
#include <optional>
#include <sstream>
#include <string>
#include <vector>
struct QuoteEvent {
long sequence;
std::string symbol;
double bid;
double ask;
};
std::optional<QuoteEvent> parseQuoteLine(const std::string& line) {
std::istringstream in(line);
QuoteEvent e{};
if (!(in >> e.sequence >> e.symbol >> e.bid >> e.ask)) {
return std::nullopt;
}
if (e.sequence <= 0 || e.symbol.empty() || e.bid <= 0.0 || e.ask <= 0.0 || e.bid >= e.ask) {
return std::nullopt;
}
return e;
}
int main() {
std::vector<std::string> lines = {
"1 ESU5 5000.25 5000.50",
"2 ESU5 5000.00 5000.25",
"bad line",
"3 ESU5 4999.75 5000.00"
};
for (const auto& line : lines) {
auto event = parseQuoteLine(line);
if (event) {
std::cout << "QUOTE seq=" << event->sequence
<< " symbol=" << event->symbol
<< " bid=" << event->bid
<< " ask=" << event->ask << "\n";
} else {
std::cout << "REJECT malformed line: " << line << "\n";
}
}
}
```
Run The Loop
A minimal end-to-end engine
This standalone C++ program compresses the course into one replay loop:
- validate configuration
- parse replayed quotes
- update top-of-book state
- generate a simple signal
- apply risk checks
- create an OMS-style order record
- simulate a fill
- print metrics
The strategy here is intentionally tiny: if the mid-price drops below a threshold, attempt to buy one unit. The point is not alpha. The point is proving the system path is wired safely.
```cpp
#include <algorithm>
#include <iostream>
#include <optional>
#include <sstream>
#include <string>
#include <vector>
enum class Side { Buy, Sell };
enum class OrderState { New, Rejected, Filled };
struct Config {
std::string symbol = "ESU5";
int maxOrderQty = 2;
int maxPosition = 3;
double buyBelowMid = 5000.10;
};
struct QuoteEvent {
long sequence;
std::string symbol;
double bid;
double ask;
};
struct BookTop {
bool valid = false;
double bid = 0.0;
double ask = 0.0;
double mid() const { return (bid + ask) / 2.0; }
};
struct Order {
int id;
Side side;
int qty;
double limitPrice;
OrderState state;
};
struct Metrics {
int events = 0;
int signals = 0;
int ordersAccepted = 0;
int ordersRejected = 0;
int fills = 0;
};
std::optional<QuoteEvent> parseQuoteLine(const std::string& line) {
std::istringstream in(line);
QuoteEvent e{};
if (!(in >> e.sequence >> e.symbol >> e.bid >> e.ask)) return std::nullopt;
if (e.sequence <= 0 || e.symbol.empty() || e.bid <= 0.0 || e.ask <= 0.0 || e.bid >= e.ask) return std::nullopt;
return e;
}
std::vector<std::string> validateConfig(const Config& c) {
std::vector<std::string> errors;
if (c.symbol.empty()) errors.push_back("symbol is empty");
if (c.maxOrderQty <= 0 || c.maxOrderQty > 1000) errors.push_back("maxOrderQty outside approved range");
if (c.maxPosition <= 0 || c.maxPosition > 500) errors.push_back("maxPosition outside approved range");
if (c.buyBelowMid <= 0.0) errors.push_back("buyBelowMid must be positive");
return errors;
}
bool riskAllowsBuy(int currentPosition, int qty, const Config& c) {
if (qty <= 0 || qty > c.maxOrderQty) return false;
int projected = currentPosition + qty;
return projected <= c.maxPosition;
}
int main() {
Config cfg{};
auto configErrors = validateConfig(cfg);
if (!configErrors.empty()) {
std::cout << "PREFLIGHT FAIL\n";
for (const auto& e : configErrors) std::cout << " - " << e << "\n";
return 1;
}
std::cout << "PREFLIGHT PASS\n";
std::vector<std::string> feed = {
"1 ESU5 5000.25 5000.50",
"2 ESU5 5000.05 5000.25",
"3 ESU5 4999.90 5000.10",
"4 ESU5 4999.80 5000.00",
"5 ESU5 4999.70 4999.95"
};
BookTop book{};
Metrics metrics{};
int position = 0;
int nextOrderId = 1;
for (const auto& line : feed) {
auto event = parseQuoteLine(line);
if (!event || event->symbol != cfg.symbol) {
std::cout << "SKIP invalid or unsupported event: " << line << "\n";
continue;
}
metrics.events++;
book.valid = true;
book.bid = event->bid;
book.ask = event->ask;
std::cout << "EVENT seq=" << event->sequence
<< " mid=" << book.mid()
<< " position=" << position << "\n";
if (book.valid && book.mid() < cfg.buyBelowMid) {
metrics.signals++;
int qty = 1;
if (!riskAllowsBuy(position, qty, cfg)) {
metrics.ordersRejected++;
std::cout << " SIGNAL buy -> RISK REJECT projected position too high\n";
continue;
}
Order order{nextOrderId++, Side::Buy, qty, book.ask, OrderState::New};
metrics.ordersAccepted++;
std::cout << " SIGNAL buy -> ORDER id=" << order.id
<< " qty=" << order.qty
<< " limit=" << order.limitPrice << "\n";
// Toy fill model: marketable buy fills at current ask.
order.state = OrderState::Filled;
position += order.qty;
metrics.fills++;
std::cout << " FILL id=" << order.id
<< " new_position=" << position << "\n";
}
}
std::cout << "\nRUN SUMMARY\n";
std::cout << "events=" << metrics.events << "\n";
std::cout << "signals=" << metrics.signals << "\n";
std::cout << "accepted=" << metrics.ordersAccepted << "\n";
std::cout << "rejected=" << metrics.ordersRejected << "\n";
std::cout << "fills=" << metrics.fills << "\n";
std::cout << "final_position=" << position << "\n";
}
```
Safety Boundary
Capstone check
In the mini capstone, the strategy emits a buy signal after seeing a favorable quote. Where should the system decide whether the order is allowed under position and order-size limits?
Replay Runbook
What a good final run proves
A capstone run should produce evidence, not vibes. Before you call the lab complete, you should be able to answer:
- Did preflight pass?
- How many events were processed?
- Were invalid events rejected safely?
- How many signals fired?
- How many orders were accepted versus rejected?
- What was the final position?
- Did the run produce the same result twice?
A simple expected output shape is:
PREFLIGHT PASS
EVENT seq=1 mid=...
EVENT seq=2 mid=...
SIGNAL buy -> ORDER id=1 ...
FILL id=1 new_position=1
RUN SUMMARY
signals=...
accepted=...
rejected=...
final_position=...
That final summary is your audit trail for the lab. In a real system, it would become structured logs, metrics, and alertable dashboards. Here, printed output is enough to prove the integration path.

Replay Myth
True or false?
If a strategy is only running in replay mode, it is safe to bypass risk checks because no real exchange order will be sent.
Deterministic Blank
Fill in the blank
A repeatable offline run that feeds historical or synthetic events through the trading loop is called deterministic ____.
Capstone Extensions
If you want to push further
The mini capstone is intentionally small. Once it runs cleanly, useful extensions are straightforward:
- add sequence-gap detection and recovery behavior from Snapshot Recovery and Gap Handling
- replace the toy fill rule with a costed model from Slippage, Fees, and Fill Models
- add p50/p90/p99 timing around parse, strategy, risk, and OMS stages from Latency Instrumentation and Histograms
- split the loop into producer/consumer stages using the SPSC ideas from Concurrency & Lock-Free Programming
- compare array-based state layouts using the patterns from Cache-Aware Data Layout
Add one extension at a time. Measure before and after. Keep the replay deterministic so every change has a fair comparison.
Course Finish Line
What you can now explain
You started this course by setting up a C++ lab and measuring a tiny program. You now have the mental model for a simplified HFT-style system:
market events -> typed state -> strategy intent -> risk approval -> order state -> fills -> metrics
That is a serious foundation. You have practiced the engineering habits that matter in trading systems:
- prefer typed boundaries over stringly-typed shortcuts
- validate before trusting input
- keep hot-path work predictable
- treat risk gates as mandatory, not decorative
- replay deterministically before believing a strategy
- monitor tails and failure states, not just averages
- make every deployment start with preflight
From here, keep using AlgoDaily's lesson completion flow and your /dashboard momentum to revisit weak spots. The strongest next step is to keep the capstone alive: refactor it, test it, benchmark it, and explain each boundary out loud.
If you can explain why each stage exists and what can go wrong there, you are no longer just reading about HFT systems. You are thinking like a trading systems engineer.

One Pager Cheat Sheet
One Pager Cheat Sheet
- The capstone turns prior course components into one replay-driven, risk-gated trading loop.
- Keep component boundaries explicit: parse, state, signal, risk, order, fill, metrics.
- A strong capstone is small, deterministic, and organized around reusable project boundaries.
- A deterministic feed contract makes the rest of the trading loop testable and repeatable.
- The end-to-end loop should validate config, process events, gate risk, record orders, simulate fills, and summarize results.
- Risk checks must approve strategy intent before the OMS accepts an order.
- A capstone run is complete only when it produces repeatable evidence: preflight, events, orders, rejections, fills, and final state.
- Replay should preserve production safety boundaries so tests catch real integration bugs.
- Deterministic replay is the foundation for repeatable trading-system debugging.
- Extend the capstone incrementally: one feature, one measurement, one deterministic comparison.
- A trading systems engineer can trace every event from market input to risk-gated order state and measured outcome.