Compounding and a Black-Scholes call
See compounding and black-scholes.
import math
# $A = P(1 + r/m)^{mt}$ approaches $P e^{rt}$ as m grows
P, r, t = 1000.0, 0.05, 10
for m in (1, 12, 365):
print(f"m={m:<3} A={P * (1 + r / m) ** (m * t):.2f}")
print(f"continuous A={P * math.exp(r * t):.2f}")def norm_cdf(x):
return 0.5 * (1 + math.erf(x / math.sqrt(2)))
def bs_call(S, K, T, r, sigma):
d1 = (math.log(S / K) + (r + 0.5 * sigma**2) * T) / (sigma * math.sqrt(T))
d2 = d1 - sigma * math.sqrt(T)
return S * norm_cdf(d1) - K * math.exp(-r * T) * norm_cdf(d2)
print(f"call = {bs_call(S=100, K=100, T=1, r=0.05, sigma=0.2):.4f}")