44# ' @param price Price
55# ' @param spot current stock price
66# ' @param forward forward stock price
7- # ' @param t.exp time to expiry
8- # ' @param r interest rate
9- # ' @param div dividend rate
7+ # ' @param texp time to expiry
8+ # ' @param intr interest rate
9+ # ' @param divr dividend rate
1010# ' @param sigma volatility
1111# ' @return option price
1212# ' @examples
1313# ' spot <- 100
1414# ' strike <- seq(80,125,5)
15- # ' t.exp <- 1.2
15+ # ' texp <- 1.2
1616# ' sigma <- 0.2
17- # ' r <- 0.05
18- # ' price <- FER::BachelierPrice(spot=spot, t.exp = t.exp , sigma=sigma, strike=strike, r=r )
17+ # ' intr <- 0.05
18+ # ' price <- FER::BachelierPrice(spot=spot, texp = texp , sigma=sigma, strike=strike, intr=intr )
1919# ' @export
2020BachelierPrice <- function (
21- type = " call" , spot , forward = spot * exp((r - div ) * t.exp ),
22- strike = forward , t.exp = 1 , r = 0 , div = 0 , sigma
21+ type = " call" , spot , forward = spot * exp((intr - divr ) * texp ),
22+ strike = forward , texp = 1 , intr = 0 , divr = 0 , sigma
2323){
2424
2525 # ------------------------------------------------
@@ -39,48 +39,48 @@ BachelierPrice <- function(
3939 # ------------------------------------------------
4040 # ------------------------------------------------
4141
42- stdev <- sigma * sqrt(t.exp )
42+ stdev <- sigma * sqrt(texp )
4343 d1 <- (forward - strike ) / stdev
4444 pnorm.d1 <- pnorm(d1 ) # normal CDF
4545 dnorm.d1 <- dnorm(d1 ) # normal PDF =exp(-d1*d1/2)/sqrt(2*pi)
46- disc.factor <- exp(- r * t.exp )
46+ disc.factor <- exp(- intr * texp )
4747
4848 if (type == " call" ){
4949 # Option Price
5050 price <- (forward - strike )* pnorm.d1 + stdev * dnorm.d1
5151 # Greeks
5252 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
53+ gamma <- 1 / (sigma * texp )/ sqrt(2 * pi )* exp(- d1 ^ 2 / 2 )# Gamma
54+ vega <- sqrt(texp )/ sqrt(2 * pi )* exp(- d1 ^ 2 / 2 )# Vega
5555
5656 }else if (type == " put" ){
5757 # Option Price
5858 price <- (strike - forward )* (1 - pnorm.d1 ) + stdev * dnorm.d1
5959 # Greeks
6060 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
61+ gamma <- 1 / (sigma * texp )/ sqrt(2 * pi )* exp(- d1 ^ 2 / 2 )# Gamma
62+ vega <- sqrt(texp )/ sqrt(2 * pi )* exp(- d1 ^ 2 / 2 )# Vega
6363
6464 } else if (type == " straddle" ){
6565 # Straddle price
6666 price <- (forward - strike )* (2 * pnorm.d1 - 1 ) + 2 * stdev * dnorm.d1
6767 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
68+ gamma <- 2 / (sigma * texp )/ sqrt(2 * pi )* exp(- d1 ^ 2 / 2 )
69+ vega <- 2 * sqrt(texp )/ sqrt(2 * pi )* exp(- d1 ^ 2 / 2 )# Vega
7070
7171 } else if (type == " digital call" ){
7272 # Digital call price
7373 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 ))
74+ delta <- 1 / sqrt(2 * pi )* exp(- d1 ^ 2 / 2 )/ (sigma * sqrt(texp ))
75+ gamma <- 1 / sqrt(2 * pi )* exp(- d1 ^ 2 / 2 )/ (sigma ^ 2 * texp )
76+ vega <- - 1 / sqrt(2 * pi )* exp(- d1 ^ 2 / 2 )* (spot - strike )/ (sigma ^ 2 * sqrt(texp ))
7777
7878 } else if (type == " digital put" ){
7979 # Digital put price
8080 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 ))
81+ delta <- - 1 / sqrt(2 * pi )* exp(- d1 ^ 2 / 2 )/ (sigma * sqrt(texp ))
82+ gamma <- 1 / sqrt(2 * pi )* exp(- d1 ^ 2 / 2 )/ (sigma ^ 2 * texp )
83+ vega <- - 1 / sqrt(2 * pi )* exp(- d1 ^ 2 / 2 )* (spot - strike )/ (sigma ^ 2 * sqrt(texp ))
8484 } else {
8585 cat(" Error! Please input: call/put/straddle/digital call/digital put" )
8686 }
0 commit comments