Skip to content

Commit

Permalink
Added put-vomma, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hudde committed Sep 1, 2023
1 parent d847499 commit 89f3ce6
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions R/BS_Geometric_Asian_Greeks.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#' Computes the Greeks of an Geometric Asian Option with classical Call- and
#' Put-Payoff
#'
#' TODO: epsilon
#'
#' @export
#'
#' @import "stats"
Expand All @@ -15,7 +17,8 @@
#' @param volatility - volatility of the underlying asset
#' @param dividend_yield - dividend yield
#' @param payoff - the payoff function, either a string in ("call", "put")
#' @param greek - the Greek to be calculated
#' @param greek - the Greeks to be calculated in c("fair_value", "delta",
#' "vega", "theta", "rho", "gamma", "vomma")
#'
#' @return Named vector containing the values of the Greeks specified in the
#' parameter \code{greek}.
Expand Down Expand Up @@ -155,21 +158,15 @@ BS_Geometric_Asian_Greeks <- function(
}

if("vomma" %in% greek) {
d_vega <-
-sqrt(3 * time_to_maturity) *
(0.25 +
(log(initial_price/exercise_price) / (volatility^2 * time_to_maturity)) +
((r - dividend_yield) / (2 * volatility^2)))

result["vomma"] <-
eval(D(expression(initial_price * exp(-(time_to_maturity/2) *
((r - dividend_yield) + (volatility**2)/6)) *
((-volatility * time_to_maturity/6) *
pnorm(d_geom + volatility * sqrt(time_to_maturity/3)) +
dnorm(d_geom + volatility * sqrt(time_to_maturity/3)) *
(d_vega + sqrt(time_to_maturity/3))) -
exp(-(r - dividend_yield)*time_to_maturity) * exercise_price *
dnorm(d_geom) * d_vega), "volatility"))
((r - dividend_yield) + (volatility**2)/6)) *
((-volatility * time_to_maturity/6) *
pnorm(d_geom + volatility * sqrt(time_to_maturity/3)) +
dnorm(d_geom + volatility * sqrt(time_to_maturity/3)) *
(d_vega + sqrt(time_to_maturity/3))) -
exp(-(r - dividend_yield)*time_to_maturity) * exercise_price *
dnorm(d_geom) * d_vega), "volatility"))
}

} #payoff=="call"
Expand Down Expand Up @@ -231,7 +228,7 @@ BS_Geometric_Asian_Greeks <- function(

result["theta"] <-
initial_price * exp(-time_to_maturity/2 *
((r - dividend_yield) + (volatility**2)/6)) *
((r - dividend_yield) + (volatility**2)/6)) *
(-0.5 * ((r - dividend_yield) + (volatility**2)/6) *
pnorm(-d_geom - volatility * sqrt(time_to_maturity/3)) -
dnorm(-d_geom - volatility * sqrt(time_to_maturity/3)) *
Expand All @@ -254,6 +251,19 @@ BS_Geometric_Asian_Greeks <- function(
dnorm(-d_geom) * (d_geom * d_delta**2 - d_gamma))
}

if("vomma" %in% greek) {
result["vomma"] <-
eval(D(expression(
-initial_price * exp(-(time_to_maturity/2) *
((r - dividend_yield) + (volatility**2)/6)) *
((-volatility * time_to_maturity/6) *
pnorm(-d_geom - volatility * sqrt(time_to_maturity/3)) -
dnorm(-d_geom - volatility * sqrt(time_to_maturity/3)) *
(d_vega + sqrt(time_to_maturity/3))) -
exp(-(r - dividend_yield)*time_to_maturity) * exercise_price *
dnorm(-d_geom) * d_vega), "volatility"))
}

} #payoff=="put"

return(result)
Expand Down

0 comments on commit 89f3ce6

Please sign in to comment.