Introducción

En este anÔlisis se estudia el comportamiento de una opción tipo call sobre una acción del mercado, evaluando cómo cambia su valor ante variaciones en el precio del activo subyacente. Se hace uso del modelo de Black-Scholes y se analizan las principales griegas financieras.

if(!require(quantmod)) install.packages("quantmod")
if(!require(ggplot2)) install.packages("ggplot2")

library(quantmod)
getSymbols("MSFT", src = "yahoo", from = "2025-01-01")
## [1] "MSFT"
S0 <- as.numeric(last(Cl(MSFT)))
K <- round(S0*1.02)   # leve diferencia en strike
r <- 0.045
sigma <- 0.30
T <- 1

S_seq <- seq(S0*0.75, S0*1.25, by = 2)

S0
## [1] 422.79
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(color="blue", size=1.2) +
  geom_point(color="red") +
  ggtitle("Convexidad de la opción - MSFT") +
  theme_minimal()

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))
}

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)
}

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))
vega  <- sapply(S_seq, function(x) vega_fun(x,K,r,sigma,T))

df_greeks <- data.frame(S_seq, delta, gamma, vega)
ggplot(df_greeks, aes(x=S_seq, y=delta)) +
  geom_line(color="darkgreen", size=1) +
  ggtitle("Delta") +
  theme_light()

ggplot(df_greeks, aes(x=S_seq, y=gamma)) +
  geom_line(color="purple", size=1) +
  ggtitle("Gamma") +
  theme_light()

ggplot(df_greeks, aes(x=S_seq, y=vega)) +
  geom_line(color="orange", size=1) +
  ggtitle("Vega") +
  theme_light()

library(ggplot2)