Created
March 20, 2020 18:48
-
-
Save ksdme/910d593aae11e19f49c24e052edb60ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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