I am new to R and trying to figure out how to calculate the put option in the Black Scholes Options Price model. I have written the following code but it is not outputting the number I was expecting. Refer below. It is not pulling in the put calculation I was expecting.Thanks in advance for any insight!! This is my data I am trying to make a reusable function for
s0 = 100
K = 70
r = 0.05
sigma = 0.16
T = 1
P <- 70*exp(-0.05*1)*pnorm(-d2) - 100*pnorm(-d1)
I then made this function.
put <- function(s0, K, r, T, sigma) {
d1 <- (log(s0/K) + (r + sigma^2/2)*T) / (sigma*sqrt(T))
d2 <- d1 - sigma*sqrt(T)
p <- K*exp(-r*1)*pnorm(-d2) - 100*pnorm(-d1)
p
}
You are not using T and s0 in your put price calculation in the put function. You have a default value of 1 instead of T and a value of 100 instead of s0. See formula for put and call prices below. And a check on the put call parity. Do note that these are the black and scholes formula's, they don't take dividends into account. (And no error checks.)
s0 = 100
K = 70
r = 0.05
sigma = 0.16
T = .5
put_price <- function(s0, K, r, T, sigma) {
d1 <- (log(s0/K) + T*(r + sigma^2/2)) / (sigma*sqrt(T))
d2 <- d1 - sigma*sqrt(T)
p <- K*exp(-r*T)*pnorm(-d2) - s0*pnorm(-d1)
p
}
call_price <- function(s0, K, r, T, sigma) {
d1 <- (log(s0/K) + T*(r + sigma^2/2)) / (sigma*sqrt(T))
d2 <- d1 - sigma*sqrt(T)
c <- s0*pnorm(d1) - K*exp(-r*T)*pnorm(d2)
c
}
# put call parity
all.equal(put_price(s0, K, r, T, sigma), call_price(s0, K, r, T, sigma) + K * exp(-r*T) - s0)