A C++ project implementing both the binomial tree and Black-Scholes models for option pricing.
This repository provides implementations of two widely used option pricing models:
- Binomial Tree Model: A discrete-time model for pricing European and American options.
- Black-Scholes Model: A continuous-time model for pricing European options.
- Implements a Depth-First Search (DFS) approach for traversing the binomial tree.
- Supports European and American options.
- Handles call and put options.
- Configurable for discrete or continuous interest rates.
- Outputs the binomial tree structure, option values, and delta values.
- Supports European options only.
- Handles call and put options.
- Outputs the option price and Greeks.
- CMake
- C++17-compatible compiler
# Create a build directory and navigate into it
mkdir -p build
cd build
# Generate build files using CMake
# Note: You need to write your own CMakeLists.txt file to configure the build process.
cmake ..
# Compile the project
make -jProvide a configuration file as the single command-line argument. An example configuration file is included at config/setting.cfg.
./financeModel config/setting.cfg- Configuration Loading:
cfgManager::loadCommonInforeads the configuration file and initializes the models. - Model Execution:
cfgManager::processruns the binomial tree and Black-Scholes models. - Binomial Tree Logic:
binomialTree::mainProcesscalculates option values and deltas. - Black-Scholes Logic:
blackScholesModel::mainProcesscalculates the option price and delta.
The configuration file specifies the following parameters:
spot: Initial stock pricestrike: Strike price of the optionrate: Risk-free interest ratesigma: Volatility of the underlying assettime: Time to maturitysteps: Number of steps in the binomial tree (only for the binomial model)regionType: Option type (EUfor European,USfor American; only for the binomial model)interestType: Interest rate type (DiscreteorContinuous; only for the binomial model)optionType: Option style (callorput)
The binomial tree model calculates option prices using the following steps:
-
Time Step:
$$\Delta t = \frac{T}{N}$$ -
Up/Down Factors:
$$u = 1 + \sigma \cdot \sqrt{\Delta t}, \quad d = 1 - \sigma \cdot \sqrt{\Delta t}$$ -
Risk-Neutral Probability:
- Discrete:
$$p = 0.5 + \frac{r \cdot \sqrt{\Delta t}}{2 \cdot \sigma}$$ - Continuous:
$$p = 0.5 + \frac{\exp(r \cdot \Delta t) - 1}{2 \cdot \sigma \cdot \sqrt{\Delta t}}$$
- Discrete:
-
Discount Factor:
- Discrete:
$$df = \frac{1}{1 + r \cdot \Delta t}$$ - Continuous:
$$df = \exp(-r \cdot \Delta t)$$
- Discrete:
-
Backward Induction:
$$V = df \cdot (p \cdot V_{\text{up}} + (1 - p) \cdot V_{\text{down}})$$ For American options, the immediate exercise value is compared with the continuation value:
$$V = \max(\text{exercise value}, \text{continuation value})$$
The Black-Scholes formula calculates the price of European options as follows:
-
Key Terms:
$$d_1 = \frac{\ln(S / K) + (r - q + \sigma^2 / 2) \cdot T}{\sigma \cdot \sqrt{T}}, \quad d_2 = d_1 - \sigma \cdot \sqrt{T}$$ where$q$ is the continuous dividend yield. -
Call Option Price:
$$C = S \cdot e^{-q \cdot T} \cdot \Phi(d_1) - K \cdot e^{-r \cdot T} \cdot \Phi(d_2)$$ -
Put Option Price:
$$P = K \cdot e^{-r \cdot T} \cdot \Phi(-d_2) - S \cdot e^{-q \cdot T} \cdot \Phi(-d_1)$$ -
Greeks:
-
Delta:
- Call:
$\Delta = e^{-q \cdot T} \cdot \Phi(d_1)$ ; - Put:
$\Delta = e^{-q \cdot T} \cdot (\Phi(d_1) - 1)$
- Call:
-
Gamma:
$\Gamma = \frac{e^{-q \cdot T} \cdot \phi(d_1)}{S \cdot \sigma \cdot \sqrt{T}}$ -
Theta:
- Call:
$\Theta = -S \cdot e^{-q \cdot T} \cdot \phi(d_1) \cdot \sigma / (2\sqrt{T}) - r \cdot K \cdot e^{-r \cdot T} \cdot \Phi(d_2) + q \cdot S \cdot e^{-q \cdot T} \cdot \Phi(d_1)$ - Put:
$\Theta = -S \cdot e^{-q \cdot T} \cdot \phi(d_1) \cdot \sigma / (2\sqrt{T}) + r \cdot K \cdot e^{-r \cdot T} \cdot \Phi(-d_2) - q \cdot S \cdot e^{-q \cdot T} \cdot \Phi(-d_1)$
- Call:
-
Vega:
$\nu = S \cdot e^{-q \cdot T} \cdot \phi(d_1) \cdot \sqrt{T}$ -
Rho:
- Call:
$\rho = K \cdot T \cdot e^{-r \cdot T} \cdot \Phi(d_2)$ ; - Put:
$\rho = -K \cdot T \cdot e^{-r \cdot T} \cdot \Phi(-d_2)$
- Call:
-
Delta:
Check the headers of third-party libraries (e.g., rapidcsv/rapidcsv.h) for licensing details.
