PyMPDATA_examples.Arabas_and_Farhat_2020.Black_Scholes_1973
1import numpy as np 2from scipy.special import erf # pylint: disable=no-name-in-module 3 4 5def N(x: float): 6 return (1 + erf(x / np.sqrt(2))) / 2 7 8 9def c_euro(S: np.ndarray, K: float, T: float, r: float, b: float, sgma: float): 10 d1 = (np.log(S / K) + (b + sgma * sgma / 2) * T) / sgma / np.sqrt(T) 11 d2 = d1 - sgma * np.sqrt(T) 12 return S * np.exp(b - r) * N(d1) - K * np.exp(-r * T) * N(d2) 13 14 15def p_euro(S: np.ndarray, K: float, T: float, r: float, b: float, sgma: float): 16 d1 = (np.log(S / K) + (b + sgma * sgma / 2) * T) / sgma / np.sqrt(T) 17 d2 = d1 - sgma * np.sqrt(T) 18 return K * np.exp(-r * T) * N(-d2) - S * np.exp((b - r) * T) * N(-d1)
def
N(x: float):
def
c_euro( S: numpy.ndarray, K: float, T: float, r: float, b: float, sgma: float):
def
p_euro( S: numpy.ndarray, K: float, T: float, r: float, b: float, sgma: float):