En este trabajo se analiza una opción tipo call para evaluar su convexidad y el comportamiento de sus principales griegas frente a cambios en el precio del activo.
# Librerías
library(quantmod)
library(ggplot2)
# Descargar datos de Apple
getSymbols("AAPL", src = "yahoo", from = "2025-01-01")
## [1] "AAPL"
S0 <- as.numeric(last(Cl(AAPL))) # precio actual
K <- round(S0) # strike cercano
r <- 0.05 # tasa
sigma <- 0.25 # volatilidad
T <- 1 # 1 año
S_seq <- seq(S0*0.8, S0*1.2, by = 2)
S0
## [1] 270.23
BS_call <- function(S,K,r,sigma,T){
d1 <- (log(S/K)+(r+0.5*sigma^2)*T)/(sigma*sqrt(T))
d2 <- d1 - sigma*sqrt(T)
S*pnorm(d1) - K*exp(-r*T)*pnorm(d2)
}
precios <- sapply(S_seq, function(x) BS_call(x,K,r,sigma,T))
df <- data.frame(S = S_seq, Precio = precios)
ggplot(df, aes(x=S, y=Precio)) +
geom_line() +
ggtitle("Convexidad de la opción Call") +
xlab("Precio del activo") +
ylab("Precio de la opción")
delta_fun <- function(S,K,r,sigma,T){
d1 <- (log(S/K)+(r+0.5*sigma^2)*T)/(sigma*sqrt(T))
pnorm(d1)
}
gamma_fun <- function(S,K,r,sigma,T){
d1 <- (log(S/K)+(r+0.5*sigma^2)*T)/(sigma*sqrt(T))
dnorm(d1)/(S*sigma*sqrt(T))
}
theta_fun <- function(S,K,r,sigma,T){
d1 <- (log(S/K)+(r+0.5*sigma^2)*T)/(sigma*sqrt(T))
d2 <- d1 - sigma*sqrt(T)
(-S*dnorm(d1)*sigma/(2*sqrt(T))) - r*K*exp(-r*T)*pnorm(d2)
}
vega_fun <- function(S,K,r,sigma,T){
d1 <- (log(S/K)+(r+0.5*sigma^2)*T)/(sigma*sqrt(T))
S*dnorm(d1)*sqrt(T)
}
rho_fun <- function(S,K,r,sigma,T){
d2 <- (log(S/K)+(r-0.5*sigma^2)*T)/(sigma*sqrt(T))
K*T*exp(-r*T)*pnorm(d2)
}
delta <- sapply(S_seq, function(x) delta_fun(x,K,r,sigma,T))
gamma <- sapply(S_seq, function(x) gamma_fun(x,K,r,sigma,T))
theta <- sapply(S_seq, function(x) theta_fun(x,K,r,sigma,T))
vega <- sapply(S_seq, function(x) vega_fun(x,K,r,sigma,T))
rho <- sapply(S_seq, function(x) rho_fun(x,K,r,sigma,T))
df_greeks <- data.frame(S_seq, delta, gamma, theta, vega, rho)
ggplot(df_greeks, aes(x=S_seq, y=delta)) + geom_line() + ggtitle("Delta")
ggplot(df_greeks, aes(x=S_seq, y=gamma)) + geom_line() + ggtitle("Gamma")
ggplot(df_greeks, aes(x=S_seq, y=theta)) + geom_line() + ggtitle("Theta")
ggplot(df_greeks, aes(x=S_seq, y=vega)) + geom_line() + ggtitle("Vega")
ggplot(df_greeks, aes(x=S_seq, y=rho)) + geom_line() + ggtitle("Rho")