Created
October 17, 2020 21:39
-
-
Save addiversitas/72b3e8634686faaaae9a1ec5015315e8 to your computer and use it in GitHub Desktop.
generalized black scholes merton implementation
This file contains hidden or 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
gBSM <- function(S, X, sigma, r, q, ttm, type){ | |
#S = stock price | |
#X = strike price | |
#sigma = volatility | |
#r = risk free interest rate | |
#q = dividend yield | |
#ttm = time to maturity in days | |
#type = option type | |
b <- r - q | |
t <- ttm/365.25 | |
d1 <- (log(S / X) + (b + sigma ^ 2 / 2) * t) / (sigma * sqrt(t)) | |
d2 <- d1 - sigma * sqrt(t) | |
if(type == "call"){ | |
price <- S * exp((b - r) * t) * pnorm(d1) - X * exp(-r * t) * pnorm(d2) | |
}else if (type == "put"){ | |
price <- (X * exp(-r * t) * pnorm(-d2) - S * exp((b - r) * t) * pnorm(-d1)) | |
} | |
return(price) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment