Skip to content

Instantly share code, notes, and snippets.

@raphaelsaunier
Created March 1, 2012 09:04
Show Gist options
  • Save raphaelsaunier/1948460 to your computer and use it in GitHub Desktop.
Save raphaelsaunier/1948460 to your computer and use it in GitHub Desktop.
# Black-Scholes Option Value
# Call value is returned in values[1], put in values[2]
blackscholes <- function(S, X, rf, T, sigma) {
values <- c(2)
d1 <- (log(S/X)+(rf+sigma^2/2)*T)/sigma*sqrt(T)
d2 <- d1 - sigma * sqrt(T)
values[1] <- S*pnorm(d1) - X*exp(-rf*T)*pnorm(d2)
values[2] <- X*exp(-rf*T) * pnorm(-d2) - S*pnorm(-d1)
values
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment