Files
2026-01-06 15:05:27 +00:00

4.6 KiB

C++ Refresher Plan for Quantitative/HFT Development

This plan is designed for an experienced programmer returning to C++ with a focus on quantitative finance (Quant) and High-Frequency Trading (HFT). It incorporates expert feedback from "Optimizing C++" by Agner Fog and "Modern C++ for Financial Engineering" (arXiv:2309.04259).


Part 1: The Modern Development Environment on Linux

This part establishes a professional, reproducible development workflow.

  • Tutorial 1.1: Your First Modern C++ Project

    • Objective: Build a simple program using the modern toolchain (CMake, vcpkg) and link an external library (spdlog).
    • Tools: g++/clang++, CMake, vcpkg, VSCode with C++ & CMake extensions.
    • Key Takeaway: Automate building and dependency management, leaving manual Makefiles in the past.
  • Tutorial 1.2: incorporate gtest unit testing framework


Part 2: Core Language, Libraries, and Concepts

This section bridges the 20-year gap from C++98 to C++20+.

  • Tutorial 2.1: Resource Management & The Rule of Zero

    • Objective: Master RAII and move semantics to eliminate manual memory management.
    • Concepts: Smart Pointers (std::unique_ptr, std::shared_ptr), Move Semantics (&&, std::move), and The Rule of Zero.
    • Project: Refactor a C++98-style class using raw pointers to a modern class using std::vector and smart pointers, demonstrating the elimination of manual destructors/constructors.
  • Tutorial 2.2: Modern STL Containers & Algorithms

    • Objective: Use the workhorse containers and algorithms with a focus on performance.
    • Concepts: std::vector, std::array (for stack allocation), std::string_view (for zero-copy parsing), std::unordered_map, Lambdas, and range-based for loops.
    • Project: Parse mock CSV tick data, using algorithms and lambdas to perform queries.
  • Tutorial 2.3: Compile-Time Programming & Type Safety

    • Objective: Use the compiler to improve performance and safety.
    • Concepts: constexpr for compile-time calculations, enum class for type-safe enums, auto for type deduction.
    • Project: A simple program using these features to enforce type safety and move runtime calculations to compile-time.

Part 3: Design Patterns & Idioms for Low-Latency C++ (Revised)

This section focuses on HFT/Quant performance, emphasizing hardware-aware programming.

  • Tutorial 3.1: Static vs. Dynamic Polymorphism (CRTP vs. Virtual Functions)

    • Objective: Understand the performance cost of virtual functions and learn the Curiously Recurring Template Pattern (CRTP) as a zero-cost, compile-time alternative.
    • Hardware Insight: virtual calls can cause branch mispredictions; CRTP enables inlining.
  • Tutorial 3.2: Custom Memory Management & Cache Locality

    • Objective: Understand that heap allocation (new) is slow primarily because it destroys cache locality.
    • Concepts: Memory Pools / Arena Allocators. The key benefit is placing related data contiguously in memory to maximize CPU cache efficiency.
  • Tutorial 3.3: Data-Oriented Design (Struct of Arrays)

    • Objective: Implement a powerful, cache-friendly optimization by changing data layout.
    • Concepts: Switch from Array of Structs (AoS), e.g., vector<Tick>, to Struct of Arrays (SoA), e.g., struct { vector<double> prices; vector<int> volumes; }.
    • Project: Benchmark a calculation on a large dataset using both AoS and SoA layouts to demonstrate the significant performance gain of SoA, which is ideal for cache utilization and SIMD vectorization.
  • Tutorial 3.4: Type-Safe Polymorphism with std::variant

    • Objective: Learn the modern, safe, and performant way to handle objects of different types (e.g., financial events).
    • Concepts: std::variant as a type-safe union and std::visit to operate on the contained types without virtual functions or unsafe casts.

Part 4: Additional Essential Material (Revised)

  • Concurrency: std::thread, std::mutex, std::atomic (critical for lock-free code), std::condition_variable.
  • Essential Quant Libraries: Eigen for linear algebra, Boost for various utilities.
  • Advanced Topic - Adjoint Algorithmic Differentiation (AAD): An introduction to the key technique used in modern derivatives pricing for calculating risk sensitivities ("Greeks") efficiently.
  • Further Reading: cppreference.com, "Effective Modern C++" (Scott Meyers), CppCon talks.