Last active
January 2, 2020 14:48
-
-
Save Nick3523/589356325c5933cb9781e921089f42c0 to your computer and use it in GitHub Desktop.
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
Le modèle Black-Scholes ou modèle Black-Scholes-Merton qui est un modèle mathématique du marché pour une action, | |
dans lequel le prix de l'action est un processus stochastique en temps continu; par opposition au | |
"modèle Cox Ross-Rubinstein" qui suit un processus stochastique en temps discret. | |
######################################## | |
Les inputs : | |
S: spot price | |
K: strike price | |
T: time to maturity | |
r: interest rate | |
sigma: volatility of underlying asset | |
######################################## | |
import numpy as np | |
import scipy.stats as si | |
import sympy as sy | |
import sympy.stats as systats | |
def euro_vanilla_call(S, K, T, r, sigma): | |
d1 = (np.log(S / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T)) | |
d2 = (np.log(S / K) + (r - 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T)) | |
call = (S * si.norm.cdf(d1, 0.0, 1.0) - K * np.exp(-r * T) * si.norm.cdf(d2, 0.0, 1.0)) | |
return call | |
def euro_vanilla_put(S, K, T, r, sigma): | |
d1 = (np.log(S / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T)) | |
d2 = (np.log(S / K) + (r - 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T)) | |
put = (-S * si.norm.cdf(-d1, 0.0, 1.0) + K * np.exp(-r * T) * si.norm.cdf(-d2, 0.0, 1.0)) | |
return put | |
#################################################################################################### | |
Le modèle précédent ne prenait pas en compte les dividendes versées sur l'action, celui ci le fait : | |
Les dividendes sont représentées par un taux nommé q | |
voir : https://www.wikiwand.com/fr/Modèle_Black-Scholes#/Extensions_du_modèle | |
#################################################################################################### | |
def euro_vanilla_call_dividendes(S, K, T, r, q, sigma): | |
d1 = (np.log(S / K) + (r - q + 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T)) | |
d2 = (np.log(S / K) + (r - q - 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T)) | |
call = (S * np.exp(-q * T) * si.norm.cdf(d1, 0.0, 1.0) - K * np.exp(-r * T) * si.norm.cdf(d2, 0.0, 1.0)) | |
return call | |
def euro_vanilla_put_dividendes(S, K, T, r, q, sigma): | |
d1 = (np.log(S / K) + (r - q + 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T)) | |
d2 = (np.log(S / K) + (r - q - 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T)) | |
put = (-S * np.exp(-q * T) * si.norm.cdf(-d1, 0.0, 1.0) + K * np.exp(-r * T) * si.norm.cdf(-d2, 0.0, 1.0)) | |
return put | |
#################################################################################################### | |
Pour tester : | |
#Sans dividendes | |
euro_vanilla_call(50, 100, 1, 0.05, 0.25) | |
euro_vanilla_put(50, 100, 1, 0.05, 0.25) | |
#Avec dividendes | |
euro_vanilla_call_dividendes(100, 150, 1, 0.05, 2, 0.25) | |
euro_vanilla_put_dividendes(100, 150, 1, 0.05, 2, 0.25) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment