Created
September 8, 2020 07:15
-
-
Save yytyd/56165bb93ab6eac448111034ffa66706 to your computer and use it in GitHub Desktop.
Black Scholes Model implementation example written in Python
This file contains 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.stats import norm | |
from math import exp, log, sqrt | |
def BS_Call(S0, sigma, r, q, T, K): | |
d1 = (log(S0 / K) + (r - q) * T) / (sigma * sqrt(T)) + sigma * sqrt(T) / 2 | |
d2 = (log(S0 / K) + (r - q) * T) / (sigma * sqrt(T)) - sigma * sqrt(T) / 2 | |
call = S0 * exp(-q * T) * norm.cdf(x=d1, loc=0, scale=1) - K * exp(-r * T) * norm.cdf(x=d2, loc=0, scale=1) | |
return call | |
def BS_Put(S0, sigma, r, q, T, K): | |
d1 = (log(S0 / K) + (r - q + sigma ** 2 / 2) * T) / (sigma * sqrt(T)) | |
d2 = d1 - sigma * sqrt(T) | |
put = K * exp(-r * T) * norm.cdf(x=-d2, loc=0, scale=1) - S0 * exp(-q * T) * norm.cdf(x=-d1, loc=0, scale=1) | |
return put | |
def put_call_parity(call, put): | |
parity = call + K * exp(-r * T) - put -S0 * exp(-q * T) | |
print(parity) | |
S0=100 | |
sigma=30/100 | |
r=5/100 | |
q=0/100 | |
T=1 | |
K=100 | |
call_ans = BS_Call(S0, sigma, r, q, T, K) | |
print(call_ans) | |
put_ans = BS_Put(S0, sigma, r, q, T, K) | |
print(put_ans) | |
put_call_parity(call_ans, put_ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment