|
| 1 | +#' Calculate normal model option price |
| 2 | +#' |
| 3 | +#' @param type option type either "call" or "put" |
| 4 | +#' @param price Price |
| 5 | +#' @param spot current stock price |
| 6 | +#' @param forward forward stock price |
| 7 | +#' @param t.exp time to expiry |
| 8 | +#' @param r interest rate |
| 9 | +#' @param div dividend rate |
| 10 | +#' @param sigma volatility |
| 11 | +#' @return option price |
| 12 | +#' @examples |
| 13 | +#' spot <- 100 |
| 14 | +#' strike <- seq(80,125,5) |
| 15 | +#' t.exp <- 1.2 |
| 16 | +#' sigma <- 0.2 |
| 17 | +#' r <- 0.05 |
| 18 | +#' price <- FER::BachelierPrice(spot=spot, t.exp = t.exp, sigma=sigma, strike=strike, r=r) |
| 19 | +#' @export |
| 20 | +BachelierPrice <- function( |
| 21 | + type = "call", spot, forward = spot*exp((r-div)*t.exp), |
| 22 | + strike = forward, t.exp = 1, r = 0, div = 0, sigma |
| 23 | +){ |
| 24 | + |
| 25 | + #------------------------------------------------ |
| 26 | + #------------------------------------------------ |
| 27 | + #Inputs: |
| 28 | + # type: "call","put","straddle","digital" |
| 29 | + # s: spot price of the underlying asset |
| 30 | + # k: strike price |
| 31 | + # t: time to maturity |
| 32 | + # r: risk-free rate |
| 33 | + # sigma: volatility |
| 34 | + #Outputs: |
| 35 | + # price: option price |
| 36 | + # delta: option delta |
| 37 | + # gamma: option gamma |
| 38 | + # vega: option vega |
| 39 | + #------------------------------------------------ |
| 40 | + #------------------------------------------------ |
| 41 | + |
| 42 | + stdev <- sigma*sqrt(t.exp) |
| 43 | + d1 <- (forward-strike) / stdev |
| 44 | + pnorm.d1 <- pnorm(d1) # normal CDF |
| 45 | + dnorm.d1 <- dnorm(d1) # normal PDF =exp(-d1*d1/2)/sqrt(2*pi) |
| 46 | + disc.factor <- exp(-r*t.exp) |
| 47 | + |
| 48 | + if(type=="call"){ |
| 49 | + #Option Price |
| 50 | + price <- (forward-strike)*pnorm.d1 + stdev*dnorm.d1 |
| 51 | + #Greeks |
| 52 | + delta <- pnorm.d1 #Delta |
| 53 | + gamma <- 1 / (sigma*t.exp)/sqrt(2*pi)*exp(-d1^2/2)#Gamma |
| 54 | + vega <- sqrt(t.exp)/sqrt(2*pi)*exp(-d1^2/2)#Vega |
| 55 | + |
| 56 | + }else if (type=="put"){ |
| 57 | + #Option Price |
| 58 | + price <- (strike-forward)*(1-pnorm.d1) + stdev*dnorm.d1 |
| 59 | + #Greeks |
| 60 | + delta <- pnorm.d1 - 1 #Delta |
| 61 | + gamma <- 1 / (sigma*t.exp)/sqrt(2*pi)*exp(-d1^2/2)#Gamma |
| 62 | + vega <- sqrt(t.exp)/sqrt(2*pi)*exp(-d1^2/2)#Vega |
| 63 | + |
| 64 | + } else if (type=="straddle"){ |
| 65 | + #Straddle price |
| 66 | + price <- (forward-strike)*(2*pnorm.d1-1) + 2*stdev*dnorm.d1 |
| 67 | + delta <- 2*pnorm.d1 - 1 |
| 68 | + gamma <- 2 / (sigma*t.exp)/sqrt(2*pi)*exp(-d1^2/2) |
| 69 | + vega <- 2 * sqrt(t.exp)/sqrt(2*pi)*exp(-d1^2/2)#Vega |
| 70 | + |
| 71 | + } else if (type== "digital call"){ |
| 72 | + #Digital call price |
| 73 | + price <- pnorm(d1) |
| 74 | + delta <- 1 / sqrt(2*pi)*exp(-d1^2/2)/(sigma*sqrt(t)) |
| 75 | + gamma <- 1 / sqrt(2*pi)*exp(-d1^2/2)/(sigma^2*t) |
| 76 | + vega <- -1 / sqrt(2*pi)*exp(-d1^2/2)*(spot-strike)/(sigma^2*sqrt(t)) |
| 77 | + |
| 78 | + } else if (type== "digital put"){ |
| 79 | + #Digital put price |
| 80 | + price <- pnorm(-d1) |
| 81 | + delta <- -1 / sqrt(2*pi)*exp(-d1^2/2)/(sigma*sqrt(t)) |
| 82 | + gamma <- 1 / sqrt(2*pi)*exp(-d1^2/2)/(sigma^2*t) |
| 83 | + vega <- -1 / sqrt(2*pi)*exp(-d1^2/2)*(spot-strike)/(sigma^2*sqrt(t)) |
| 84 | + } else { |
| 85 | + cat("Error! Please input: call/put/straddle/digital call/digital put") |
| 86 | + } |
| 87 | + return( disc.factor * price ) |
| 88 | +} |
| 89 | + |
0 commit comments