Skip to content

Instantly share code, notes, and snippets.

@Fabiocke
Created September 3, 2022 02:07
Show Gist options
  • Select an option

  • Save Fabiocke/4eda55ba4439bb31857e5a910a9e0670 to your computer and use it in GitHub Desktop.

Select an option

Save Fabiocke/4eda55ba4439bb31857e5a910a9e0670 to your computer and use it in GitHub Desktop.
from scipy.stats import norm
import numpy as np
def d1(S, K, r, sigma, T):
return (np.log(S/K) + (r + sigma ** 2 / 2) * T) / (sigma * np.sqrt(T))
def d2(S, K, r, sigma, T):
return (np.log(S/K) + (r - sigma ** 2 / 2) * T) / (sigma * np.sqrt(T))
def bsm_call(S, K, r, sigma, T):
return (S * norm.cdf(d1(S, K, r, sigma, T)) - (K * np.exp(-r * T) * norm.cdf(d2(S, K, r, sigma, T))))
def bsm_put(S, K, r, sigma, T):
return - (S * norm.cdf(-d1(S, K, r, sigma, T))) + (K * np.exp(-r * T) * norm.cdf(-d2(S, K, r, sigma, T)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment