C++ for Quantitative Finance: Hands-On from Foundations to Model Implementation

APLIED COMPUTATIO, QUANT METHODS 

RELEVANT FOR QUANTITATIVE FINANCE

Basic notion of programming required 

 

[WORK IN PROGRESS] 

This blog adopts a hands-on, laboratory-based approach: concepts are developed through direct implementation and problem solving. And practice with real data, implementing calculations and models. The objective is to accelerate the practical application of C++ in computational quantitative finance, emphasizing efficiency, numerical rigor, and real-world modeling. 

The content is organized as follows:

  1. Setup and Configuration
  2. Language and Syntax (moderm C++, C++20)
  3. Object-Oriented Programming (OOP)
  4. Efective and Functional Programming 
  5. Generic Programming (GP)
  6. Applications in Computational Finance
  7. Boost C++ Libraries
  8. Data Strcutures and Algorithms 

# --------------------------------------------------------------------------------------------------------------- #

1 - Fast Setup and Configuration

Software

Standard Environment

It’s most efficient for the staff if everyone uses the same environment:

  • Compiling: gcc, g++
  • Debugging: gdb, some use valgrind
  • About IDEs for programing: If you prefer using a GUI—which is often beneficial—Visual Studio Code is a versatile option. You may also explore other alternatives if time permits. Regardless of the IDE, your code must run correctly and be properly tested across and in standard environments.

 Windows

  •  Use MSYS2 is a collection of tools. Or the most frequent necessary packages are available in cygwin (gcc-core, gcc-g++, gdb).
    •  Cywing : a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows.
    • Check your availability or version:
gcc --version
g++ --version
gdb --version

 Linux

  • In the case of linux the componenst are integrate in the build essential; and you will need gdb. If you use Visual Studio Code equally you can use the public intructions.
sudo apt-get install build-essential #or equivalent.

sudo apt-get install build-essential gdb


Setup c++ standar to 20 (linux or windows)
    - Change the c_cpp_properties.json file with ["cppStandard": "gnu++20",] or add [-std=c++20], in task.json (thes files will be generate after the first execution or configuration).

# --------------------------------------------------------------------------------------------------------------- #

2 - C++ syntax

Don’t get lost in this session. Focus on the basic idea, the structure, and a few key terms (the ones shown in the examples). Then review some additional sample code and move directly to hands-on, coding is how you will truly learn.
 
The key elements in C++ syntax are:
  • Library importation: # include
  • Execution starts (main function) and group of statement (scope or blocks): intmain () { }
  • In the scope will be the:
    • Variable declaration
    • Output definition
    • Return Statement 
  • The required at end of statement; 
  • Namespace, functions, class and identifiers 

A simple and a complex sample:

 [WORKING - IMPROVING THE CASE CODE SAMPLES]

 
Library (Header)
 
The C++ Standard Library is included via header files at the beginning of a program, the standard library can be consulted in cppreference. See above a header ilustration as in the previous code samples:
 
# include <iostream> // for standard I/O
# include <vector > // for std :: vector
# include <map > // for std :: map
# include <set > // for std :: set
# include <algorithm > // for std :: sort , std :: accumulate
# include <functional > // for std :: function
# include <memory > // for smart pointers
# include <iterator > // for iterators
 
 
 
Data types and variables

 

Operators and expressions
Control flow and loops
Arrays and data aggregates
Keywords 

 

# --------------------------------------------------------------------------------------------------------------- # 

3 - Object Oriented Programming

  • functions
  • Class
  • memory management
  • pointer and references
  • inheritance and polymorphism 
  • preprocessor macros
  • object-oriented programming and modeling
  •  

lambda functions

auto

namespaces 

preprocessor

exception handling.

 

Standard Template Library (STL)

# --------------------------------------------------------------------------------------------------------------- #

4 - Efective and Functional Programming 

Modern design patterns (functional programming= OOP, templates 

  


 I can use only what I declare above

 

 # --------------------------------------------------------------------------------------------------------------- #

5 - Generic programming (GP)

containers and algorithms

combining OOP and GP.


 # --------------------------------------------------------------------------------------------------------------- #

 6 - Applications in Computational Finance

Black Scholes pricing and Greeks

Monte Carlo methods

Finite difference methods (Euler, Crank-Nicolson)

Lattice methods

Exact methods (Barone-Adesi-Whaley, bonds, swaps, swaptions).


Monte Carlo and partial differential equations 

 

 # --------------------------------------------------------------------------------------------------------------- # 

 

7 - Boost C++ Libraries
continuous and discrete statistical distribution

random number generator.

 

8 - Data Strcutures / Algorithms  

 

 # --------------------------------------------------------------------------------------------------------------- #

REFERENCE SOURCE: 

Lippman, S. and J. Lajoie. C++ Primer. 3rd ed. Reading, MA: Addison Wesley Professional. April 1998. 

MIT - Introduction to C and C++ : basic sytax and programming flow base notion.

MIT - C++ efective programming 


Additional source to consult:

Deitel, H. and P. Deitel. C++ How to Program. 4th ed. Upper Saddle River, NJ: Prentice Hall PTR. August 2002.
Stroustrup, B. The C++ Programming Language. 3rd ed.
Winston, H. On to C++. 2nd ed.
Johnsonbaugh & Kalin. Object Oriented Programming in C++. 2nd ed. Upper Saddle River, NJ: Prentice Hall, August 1999.
Cline, M., M. Girou, and G. Lomow. C++ FAQs. Reading, MA: Addison Wesley Professional, December 1998.

 

To go a little deep:

MIT-computation_structures_course: don't lose, get the notions and idea 

Advanced C++ Programming 

MIT-Students_guide_Computation_Structures 

6.01SC Introduction to Electrical Engineering and Computer Science - Book - focus in chapter 3 

 

Applied in Data Structures and Algorithms:

Sedgewick, R. Algorithms in C++. Reading, MA: Addison-Wesley Longman, Incorporated. June 2001. ISBN: 0201849380.

Weiss, M. Algorithms, Data Structures and Problem Solving with C++. Reading, MA: Addison Wesley, November 1999. 

Entradas populares

SQL