Skip to content

Instantly share code, notes, and snippets.

@ksdme
Created March 20, 2020 18:48
Show Gist options
  • Save ksdme/910d593aae11e19f49c24e052edb60ac to your computer and use it in GitHub Desktop.
Save ksdme/910d593aae11e19f49c24e052edb60ac to your computer and use it in GitHub Desktop.
from scipy import stats
import math
def black_scholes (s, k, t, v, rf, div, cp):
""" Price an option using the Black-Scholes model.
s: initial stock price
k: strike price
t: expiration time
v: volatility
rf: risk-free rate
div: dividend
cp: +1/-1 for call/put
"""
d1 = (math.log(s/k)+(rf-div+0.5*math.pow(v,2))*t)/(v*math.sqrt(t))
d2 = d1 - v*math.sqrt(t)
optprice = (cp*s*math.exp(-div*t)*stats.norm.cdf(cp*d1)) - (cp*k*math.exp(-rf*t)*stats.norm.cdf(cp*d2))
return optprice
print(black_scholes(100, 100, 1, 0.3, 0.03, 0.0, -1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment