Skip to content

Commit 4240e2e

Browse files
committed
Changes
1 parent ca34649 commit 4240e2e

13 files changed

+111
-22
lines changed

pkg/NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ export(BachelierImpvol)
44
export(BachelierPrice)
55
export(BlackScholesImpvol)
66
export(BlackScholesPrice)
7+
export(CEV)
8+
export(SabrHagan2002)

pkg/R/bachelier_impvol.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Calculate normal model implied vol
1+
#' Calculate Bachelier model implied volatility
22
#'
33
#' @param type option type either 'call' or 'put'
44
#' @param price Price

pkg/R/bachelier_price.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Calculate normal model option price
1+
#' Calculate Bachelier model option price
22
#'
33
#' @param type option type either "call" or "put"
44
#' @param price Price

pkg/R/blackscholes_impvol.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Calculate Black-Scholes-Merton implied vol
1+
#' Calculate Black-Scholes implied volatility
22
#'
33
#' @param type option type either 'call' or 'put'
44
#' @param price Price

pkg/R/blackscholes_price.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Calculate Black-Scholes-Merton option price
1+
#' Calculate Black-Scholes option price
22
#'
33
#' @param type option type either 'call' or 'put'
44
#' @param spot current stock price

pkg/R/cev.R

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1+
#' Constant Elasticity Of Variance (CEV) model option price
2+
#'
3+
#' @param strike
4+
#' @param spot
5+
#' @param forward
6+
#' @param t.exp
7+
#' @param sigma
8+
#' @param beta
9+
#' @param r
10+
#' @param div
11+
#' @param type
12+
#'
13+
#' @return
14+
#' @export
15+
#'
16+
#' @examples
117
CEV <- function(
2-
strike, spot, t.exp=1, sigma=0.01, vov=0, rho=0, beta=0.5,
18+
strike, spot, forward = spot*exp((r-div)*t.exp),
19+
t.exp=1, sigma=0.01, beta=0.5,
320
r = 0, div = 0, type="call"
421
){
5-
forward = spot*exp((r-div)*t.exp)
6-
722
betac <- 1 - beta
823
scale <- (betac*sigma)^2*t.exp
924
strike_cov = strike^(2*betac) / scale # strike change of variable

pkg/R/sabr_hagan2002.R

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1+
#' Hagan approximation for the SABR model
2+
#'
3+
#' @param strike
4+
#' @param spot
5+
#' @param forward
6+
#' @param t.exp
7+
#' @param sigma
8+
#' @param vov
9+
#' @param rho
10+
#' @param beta
11+
#' @param r
12+
#' @param div
13+
#' @param type 'BlackScholes', 'call', 'put'
14+
#'
15+
#' @return Black-Scholes volatility (type="BlackScholes") or option price ("call" or "put")
16+
#' @export
17+
#'
18+
#' @examples
119
SabrHagan2002 <- function(
2-
strike, spot, t.exp=1, sigma=0.01, vov=0, rho=0, beta=1,
20+
strike, spot, forward = spot*exp((r-div)*t.exp),
21+
t.exp=1, sigma=0.01, vov=0, rho=0, beta=1,
322
r = 0, div = 0, type="BlackScholes"
423
){
5-
6-
forward = spot*exp((r-div)*t.exp)
724
betac <- 1 - beta
825
powFwdStrk <- (forward*strike)^(betac/2)
926
logFwdStrk <- log(forward/strike)
@@ -20,10 +37,9 @@ SabrHagan2002 <- function(
2037
zz <- powFwdStrk*logFwdStrk*vov/sigma # need to make sure sig > 0
2138
yy <- sqrt(1 + zz*(zz-2*rho))
2239

23-
xx_zz <- rep(0, length(strike))
40+
rho2 <- rho*rho
41+
xx_zz[I] = 1 + (zz/2)*(rho + zz*((rho2-1/3) + (5*rho2-3)/4*rho*zz))
2442

25-
I <- (abs(zz) < 1e-5)
26-
xx_zz[I] = 1 + (rho/2)*zz[I] + (1/2*rho^2-1/6)*zz[I]^2 + 1/8*(5*rho^2-3)*rho*zz[I]^3
2743
I <- (zz >= 1e-5)
2844
xx_zz[I] = log( (yy[I] + (zz[I]-rho))/(1-rho) ) / zz[I]
2945
I <- (zz <= -1e-5)
@@ -33,7 +49,7 @@ SabrHagan2002 <- function(
3349

3450
if(type=="BlackScholes"){
3551
return(volBlks)
36-
} else if(type=="call" || type=="put") {
52+
} else if(type=="call" | type=="put") {
3753
p <- BlackScholesPrice(
3854
type=type, spot=spot, strike=strike, t.exp=t.exp, sigma=volBlks,
3955
r=r, div=div

pkg/man/BachelierImpvol.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/man/BachelierPrice.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/man/BlackScholesImpvol.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)