Skip to content

laurin-rodacker/options-pricing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Options Pricing

Analytical and semi-analytical pricing for European vanilla and barrier options. Pure Python, no black-box dependencies — every formula derives directly from the mathematics.

Models

Black-Scholes (black_scholes.py)

Closed-form pricing, first-order Greeks, and implied volatility inversion for European calls and puts.

Output Formula
Price $C = S N(d_1) - K e^{-rT} N(d_2)$
Delta $\Delta = N(d_1)$
Gamma $\Gamma = \frac{N'(d_1)}{S,\sigma\sqrt{T}}$
Vega $\mathcal{V} = S,N'(d_1)\sqrt{T}$
Theta $\Theta = -\frac{S,N'(d_1),\sigma}{2\sqrt{T}} - r K e^{-rT} N(d_2)$

where $d_1 = \frac{\ln(S/K) + (r + \sigma^2/2),T}{\sigma\sqrt{T}}$ and $d_2 = d_1 - \sigma\sqrt{T}$.

Implied volatility is recovered via Brent's method with arbitrage-bound checks.

import black_scholes as bs

result = bs.greeks(S=100, K=105, T=0.5, r=0.05, sigma=0.20, option_type="call")
# BSResult(price=5.14, delta=0.398, gamma=0.019, vega=0.271, theta=-0.017, rho=0.089)

iv = bs.implied_vol(market_price=5.14, S=100, K=105, T=0.5, r=0.05)
# 0.19999...

Heston Stochastic Volatility (heston.py)

Semi-analytical pricing via Gil-Pelaez Fourier inversion of the Heston (1993) characteristic function.

$$dS = r,S,dt + \sqrt{v},S,dW_1$$ $$dv = \kappa(\theta - v),dt + \sigma_v\sqrt{v},dW_2, \quad d W_1 d W_2 = \rho,dt$$

The characteristic function is evaluated using the Albrecher et al. (2007) formulation to avoid branch-cut discontinuities. The option price is:

$$C = S,P_1 - K e^{-rT} P_2, \quad P_j = \frac{1}{2} + \frac{1}{\pi}\int_0^\infty \text{Re}!\left[\frac{e^{-iu\ln K},\phi_j(u)}{iu}\right]du$$

Calibration to a strip of market prices via L-BFGS-B (minimises sum of squared relative errors).

from heston import HestonParams, price, calibrate

params = HestonParams(v0=0.04, kappa=2.0, theta=0.04, sigma_v=0.30, rho=-0.70)
c = price(S=100, K=105, T=0.5, r=0.05, params=params)

fitted = calibrate(market_prices, strikes, S=100, T=0.5, r=0.05)

Barrier Options (barrier_options.py)

All eight standard single-barrier types under Black-Scholes dynamics (Reiner & Rubinstein, 1991).

Barrier Call Put
Down-and-Out
Down-and-In
Up-and-Out
Up-and-In

In-Out parity $V_{\text{KI}} + V_{\text{KO}} = V_{\text{vanilla}}$ is verifiable via check_in_out_parity. Optional cash rebate on knock-out.

import barrier_options as barrier

p = barrier.price(S=100, K=100, H=90, T=0.5, r=0.05, sigma=0.20,
                  barrier_type="down-and-out", option_type="call")

assert barrier.check_in_out_parity(S=100, K=100, H=90, T=0.5, r=0.05, sigma=0.20)

Installation

pip install -r requirements.txt
python examples/demo.py

References

  • Black, F. & Scholes, M. (1973). The Pricing of Options and Corporate Liabilities. Journal of Political Economy.
  • Heston, S. L. (1993). A Closed-Form Solution for Options with Stochastic Volatility. Review of Financial Studies.
  • Reiner, E. & Rubinstein, M. (1991). Breaking Down the Barriers. Risk Magazine.
  • Albrecher, H., Mayer, P., Schachermayer, W. & Teichmann, J. (2007). The Little Heston Trap. Wilmott Magazine.

About

Black-Scholes · Heston · Barrier Options — analytical pricing in Python

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages