Created
December 18, 2017 18:31
-
-
Save memonkey01/5a5c4dc7928446f1c6addee0d24a7a3b 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
# -*- coding: utf-8 -*- | |
""" | |
Volatilidad Implicita - Vega - Metodo de Newton | |
Autor: Guillermo Izquierdo | |
Este código es para fines educativos exclusivamente | |
""" | |
#Importamos librerias | |
from math import log,exp,sqrt | |
from scipy import stats | |
#Definimos nuestra funcion acumulativa | |
N = stats.norm.cdf | |
#Definimos la formula de Black Scholes para una opción Call | |
def BS(S0,K,T,r,sigma): | |
S0 = float(S0) | |
d1 = (log(S0/K)+(r + 0.5 * sigma**2)*T)/(sigma*sqrt(T)) | |
d2 = (log(S0/K)+(r - 0.5*sigma**2)*T)/(sigma*sqrt(T)) | |
value = (S0*N(d1)-K*exp(-r*T)*N(d2)) | |
return value | |
#Definimos Vega que es la derivada con respecto de sigma | |
def Vega(S0,K,T,r,sigma): | |
S0 = float(S0) | |
d1 = (log(S0/K)+(r + 0.5 * sigma**2)*T)/(sigma*sqrt(T)) | |
vega = S0 * N(d1)*sqrt(T) | |
return vega | |
#Definimos la volatilidad implicita usando BS y Vega, usamos el metodo de Newton para resolver | |
def ImpliedVol(S0, K, T, r, C0, sigma_est, it=100): | |
for i in range(it): | |
sigma_est -= ((BS(S0,K,T,r, sigma_est)-C0)/Vega(S0,K,T,r,sigma_est)) | |
return sigma_est | |
#Calculamos de Acuerdo a los parametros | |
S0 = 34 | |
K = 34 | |
T = 1 | |
r = 0.0001 | |
C0 = 2.7240 | |
Sigma_init = 0.5 | |
print(ImpliedVol(S0,K,T,r,C0,Sigma_init)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment