Created
September 3, 2022 02:07
-
-
Save Fabiocke/4eda55ba4439bb31857e5a910a9e0670 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.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