Black-Scholes Pricing in Python
Table of Contents
Let us verify the Black-Scholes call price formula numerically. The closed form is:
$$C = S_0 N(d_1) - K e^{-rT} N(d_2)$$
where the d-terms are $d_1 = \frac{\ln(S_0/K) + (r + \sigma^2/2)T}{\sigma\sqrt{T}}$ and $d_2 = d_1 - \sigma\sqrt{T}$.
import numpy as np
from scipy.stats import norm
def black_scholes_call(S0, K, T, r, sigma):
d1 = (np.( /) + (r + 0.5 * sigma**2) * T) / (sigma * np.())
d2 = d1 - sigma * np.()
return S0 * norm.() - K * np.(- *) * norm.()
(100, 100, 1, 0.05, 0.2)np.float64(10.450583572185565)Visualising the payoff
Now let us plot the call option value across a range of spot prices.
import matplotlib.pyplot as plt
S = np.(50, 150, 200)
C = [(, 100, 1, 0.05, 0.2) for s in S]
fig, ax = plt.(figsize=(8, 4))
ax.(,, label='Call value')
ax.(100, color='gray', ls='--', label='Strike')
ax.('Spot price')
ax.('Call price')
ax.()
ax.('Black-Scholes call value vs spot')
plt.()
plt.()