C++ Deep Dive: Black-Scholes Option Pricing and Sieve of Eratosthenes

Inspired by Quant Insider sessions, I am focusing on C++ to solidify theory. I implemented the Sieve of Eratosthenes and the full Black-Scholes-Merton model option pricing model.

After watching several webinars and revisiting Options, Futures, and Other Derivatives, I came across a Quant Insider session featuring Dr. Paul Bilokon. His insights on low-latency systems and quantitative finance were especially valuable and gave me the push to dive back into C++.

With a bit more time available, I have decided to focus on deepening my coding skills, using implementation to better understand the theory. I started by setting up a clean GitHub repository to track my progress: https://github.com/JohannesMeyerYC/RoadToQuant

The first thing I tackled was a prime number generator using the Sieve of Eratosthenes. It took a few rounds of trial and error, but I eventually got it working:

cpp #include #include using namespace std; vector sieve(int n) { vector prime(n + 1, true); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } vector res; for (int p = 2; p <= n; p++){ if (prime[p]){ res.push_back(p); } } return res; } int main(){ int n = 35; vector res = sieve(n); for(auto ele : res){ cout << ele << ' '; } return 0; }

Next, I moved on to the Black-Scholes-Merton model. I am still learning the underlying concepts, but writing the code helped a lot with intuition and structure. I utilized a couple of free resources for the structure of it. Here is the full C++ implementation: