Skip to content

Instantly share code, notes, and snippets.

@Nick3523
Last active January 2, 2020 14:48
Show Gist options
  • Save Nick3523/2bc7d6e1b83b56da68c5c947dbfcd5dc to your computer and use it in GitHub Desktop.
Save Nick3523/2bc7d6e1b83b56da68c5c947dbfcd5dc to your computer and use it in GitHub Desktop.
Implémentation du Modèle binomial pour pricer les options européennes.
import numpy as np
import math as m
### Les différents input ###
S = 100
k = 100
r = .05 #le taux sans risque
v = .3
T = 20/36
n = 17
########################
def bop(n,t,S,v):
dt = t/n
u = m.exp(v*m.sqrt(dt))
d = 1/u
priceMatrix = np.zeros((n+1, n+1))
for j in range(n+1):
for i in range(j+1):
priceMatrix[i,j] = S*m.pow(d,i) * m.pow(u,j-i)
return priceMatrix
def OptionsVal(n, S, K, r, v, T, priceMatrix):
dt = T/n
u = m.exp(v*m.sqrt(dt))
d = 1/u
p = (m.exp(r*dt)-d)/(u-d)
putMatrix = np.zeros((n+1, n+1))
callMatrix = np.zeros((n+1, n+1))
for j in range(n+1, 0, -1):
for i in range(j):
if(j == n+1):
putMatrix[i,j-1] = max(K-priceMatrix[i,j-1], 0)
callMatrix[i,j-1] = max(priceMatrix[i,j-1]-K, 0)
else:
putMatrix[i,j-1] = m.exp(-r*dt) * (p*putMatrix[i,j] + (1-p)*putMatrix[i+1,j])
callMatrix[i,j-1] = m.exp(-r*dt) * (p*callMatrix[i,j] + (1-p)*callMatrix[i+1,j])
return [putMatrix,callMatrix]
priceMatrix = bop(n,T,S,v)
print("Affichage de l'arbre CRR, montrant l'évolution du prix du sous-jacent : \n \n",np.matrix(priceMatrix.astype(int)))
putM,callM = OptionsVal(n,S,k,r,v,T,priceMatrix)
print("Prix de l'option Call à chaque niveau de l'arbre Option:\n \n ",np.matrix(callM.astype(int)))
print("\nPrix de l'option Put à chaque niveau de l'arbre Option:\n \n ",np.matrix(putM.astype(int)))
print("Selon le modèle CRR, le prix du put devrait être = ",putM[0][0].astype(int))
print("Selon le modèle CRR, le prix du call devrait être = ",callM[0][0].astype(int))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment