Skip to content

yizhangele/OptionPricingModels

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QuantModels — Binomial and Black-Scholes Option Pricing

A C++ project implementing both the binomial tree and Black-Scholes models for option pricing.

Framework Architecture

Overview

This repository provides implementations of two widely used option pricing models:

  1. Binomial Tree Model: A discrete-time model for pricing European and American options.
  2. Black-Scholes Model: A continuous-time model for pricing European options.

Features

Binomial Tree Model

  • 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.

Black-Scholes Model

  • Supports European options only.
  • Handles call and put options.
  • Outputs the option price and Greeks.

Quick Build

Requirements

  • CMake
  • C++17-compatible compiler

Build Instructions

# 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 -j

Run

Provide a configuration file as the single command-line argument. An example configuration file is included at config/setting.cfg.

./financeModel config/setting.cfg

Runtime Flow

  1. Configuration Loading: cfgManager::loadCommonInfo reads the configuration file and initializes the models.
  2. Model Execution: cfgManager::process runs the binomial tree and Black-Scholes models.
  3. Binomial Tree Logic: binomialTree::mainProcess calculates option values and deltas.
  4. Black-Scholes Logic: blackScholesModel::mainProcess calculates the option price and delta.

Configuration

The configuration file specifies the following parameters:

  • spot: Initial stock price
  • strike: Strike price of the option
  • rate: Risk-free interest rate
  • sigma: Volatility of the underlying asset
  • time: Time to maturity
  • steps: Number of steps in the binomial tree (only for the binomial model)
  • regionType: Option type (EU for European, US for American; only for the binomial model)
  • interestType: Interest rate type (Discrete or Continuous; only for the binomial model)
  • optionType: Option style (call or put)

Theory

Binomial Tree Model

The binomial tree model calculates option prices using the following steps:

  1. Time Step:
    $$\Delta t = \frac{T}{N}$$

  2. Up/Down Factors:
    $$u = 1 + \sigma \cdot \sqrt{\Delta t}, \quad d = 1 - \sigma \cdot \sqrt{\Delta t}$$

  3. 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}}$$
  4. Discount Factor:

    • Discrete: $$df = \frac{1}{1 + r \cdot \Delta t}$$
    • Continuous: $$df = \exp(-r \cdot \Delta t)$$
  5. 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})$$

Black-Scholes Model

The Black-Scholes formula calculates the price of European options as follows:

  1. 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.

  2. Call Option Price:
    $$C = S \cdot e^{-q \cdot T} \cdot \Phi(d_1) - K \cdot e^{-r \cdot T} \cdot \Phi(d_2)$$

  3. Put Option Price:
    $$P = K \cdot e^{-r \cdot T} \cdot \Phi(-d_2) - S \cdot e^{-q \cdot T} \cdot \Phi(-d_1)$$

  4. Greeks:

    • Delta:
      • Call: $\Delta = e^{-q \cdot T} \cdot \Phi(d_1)$;
      • Put: $\Delta = e^{-q \cdot T} \cdot (\Phi(d_1) - 1)$
    • 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)$
    • 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)$

License

Check the headers of third-party libraries (e.g., rapidcsv/rapidcsv.h) for licensing details.

About

C++ implementations of Binomial Tree and Black-Scholes models for pricing European and American options, including Greeks calculations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages