Learning Modern C++ for Finance

Book description

A lot of financial modeling has gravitated toward Python, R, and VBA, but many developers hit a wall with these languages when it comes to performance. This practical book demonstrates why C++ is still one of the dominant production-quality languages for financial applications and systems. Many programmers believe that C++ is too difficult to learn. Author Daniel Hanson demonstrates that this is no longer the case.

Financial programmers coming from Python or another interpreted language will discover how to leverage C++ abstractions that enable safer and quicker implementation of financial models. You'll also explore how popular open source libraries provide additional weapons for attacking mathematical problems. C++ programmers unfamiliar with financial applications will also benefit from this handy guide.

  • Learn C++ basics: syntax, inheritance, polymorphism, composition, STL containers, and algorithms
  • Dive into newer features and abstractions including functional programming using lambdas, task-based concurrency, and smart pointers
  • Employ common but nontrivial financial models in modern C++
  • Explore external open source math libraries, particularly Eigen and Boost
  • Implement basic numerical routines in modern C++
  • Understand best practices for writing clean and efficient code

Publisher resources

View/Submit Errata

Table of contents

  1. 1. An Overview of C++
    1. C++ and Quantitative Finance
      1. C++11: The Modern Era is Born
      2. Open Source Mathematical Libraries
      3. Some Myths about C++
      4. Compiled vs Interpreted Code
    2. The Components of C++
      1. C++ Language Features
      2. The C++ Standard Library
    3. Some New Features since C++11
      1. The auto Keyword
      2. Range-Based for Loops
      3. Use the using Keyword instead of typedef
      4. Uniform Initialization
      5. Formatting Output
      6. Class Template Auto Deduction (CTAD)
      7. Enumerated Constants and Scoped Enumerations
      8. Lambda Expressions
    4. Mathematical Operators, Functions, and Constants in C++
      1. Standard Arithmetic Operators
      2. Mathematical Functions in the Standard Library
      3. Mathematical Special Functions
      4. Standard Library Mathematical Constants
    5. Naming Conventions
    6. Summary
    7. References
  2. 2. User-Defined Classes
    1. Introduction
    2. A Black-Scholes Class
      1. Representing the Payoff
      2. The Class Declaration
      3. The Class Implementation
      4. Using a Functor for Root Finding: Implied Volatility
    3. Move Semantics and Special Class Functions
      1. Move Semantics
      2. Special Class Functions
    4. The Three-Way Comparison Operator (Spaceship Operator)
    5. Lambda Expressions and User-Defined Class Members
    6. Summary
    7. References
  3. 3. Smart Pointers, Class Inheritance, and Polymorphism
    1. Introduction
    2. Polymorphism: A Review in a Modernized Context
    3. Handling Polymorphic Member Resources with Raw Pointers
      1. The Problem
      2. The (Pre-C++11) Solution
    4. Introducing Smart Pointers
      1. Unique Pointers
      2. Shared Pointers
    5. Replacing Raw Pointers with Unique Pointers in Class Design
      1. Case 1:
      2. Case 2: Copy Operations Required
    6. Summary
    7. References
  4. 4. The Standard Template Library
    1. Introduction
    2. Templates
      1. Function Templates
      2. Class Templates
      3. Compiling Template Code
    3. STL Containers and Iterators
      1. Sequential Containers
      2. Associative Containers
    4. STL Iterators
      1. Use auto to Reduce Verbosity
      2. Constant Iterators
      3. Iterators or Indices?
      4. Iterators on Associative Containers
    5. STL algorithms
      1. A First Example
      2. A First Example with Ranges
      3. Some Commonly-Used Algorithms
      4. Numeric Algorithms
    6. Views, Range Adaptors, and Functional Programming
      1. A Line-by-Line Introduction of Range Views
      2. Chaining for Functional Composition
      3. Views, Containers, and Range-Based for Loops
    7. Parallel STL algorithms
    8. Summary
    9. References
  5. 5. Random Number Generation and Concurrency
    1. Introduction
    2. Distributional Random Number Generation
      1. Engines and Distributions
      2. Other Distributions
      3. Shuffling
    3. Monte Carlo Option Pricing
      1. A Review of Monte Carlo Option Pricing
      2. Generating Random Equity Price Scenarios
    4. Calculating the Option Price
      1. Path-Dependent Options
      2. Concluding Remarks (for now)
    5. Concurrency and Parallelism
      1. Parallel Algorithms from the Standard Library
    6. Task-Based Concurrency
      1. Concluding Remarks on async and future
    7. Summary
    8. References
  6. 6. Dates and Fixed Income Securities
    1. Introduction
    2. Representation of a Date
      1. Serial Representation and Date Differences
      2. Accessor Functions for Year, Month, and Day
      3. Validity of a Date
      4. Leap Years and Last Day of the Month
      5. Weekdays and Weekends
      6. Adding Years, Months, and Days
    3. A Date Class Wrapper
      1. Class Declaration
      2. Public Member Functions and Operators
      3. Private Members and Helper Function
      4. Class Implementation
    4. Day Count Bases
    5. Yield Curves
      1. Deriving a Yield Curve from Market Data
      2. Discount Factors
      3. Forward Discount Factors
      4. A Yield Curve Class
      5. A Linearly Interpolated Yield Curve Class Implementation
    6. A Bond Class
      1. Bond Payments and Valuation
      2. Designing a Bond Class
      3. Bond Class Implementation
      4. A Bond Valuation Example
      5. Summary
      6. References
  7. 7. Linear Algebra
    1. Introduction
    2. valarray and Matrix Operations
      1. Arithmetic Operators and Math functions
      2. valarray as a Matrix Proxy
    3. Eigen
      1. Lazy Evaluation
      2. Eigen Matrices and Vectors
      3. Matrix and Vector Math Operations
      4. STL Compatibility
      5. Matrix Decompositions and Applications
    4. Future Directions: Linear Algebra in the Standard Library
      1. mdspan (P0009)
      2. BLAS Interface (P1673)
      3. Linear Algebra (P1385)
      4. Summary (Linear Algebra Proposals)
    5. Chapter Summary
    6. References
  8. 8. The Boost Libraries
    1. Introduction
    2. Mathematical Constants
    3. Statistical Distributions
      1. Probability Functions
      2. Random Number Generation with Boost Distributions
    4. MultiArray
      1. A Simple Two-Dimensional MultiArray
      2. Binomial Lattice Option Pricing
      3. Accumulators
    5. Conclusion
    6. References
  9. About the Author

Product information

  • Title: Learning Modern C++ for Finance
  • Author(s): Daniel Hanson
  • Release date: October 2024
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098100803