Skip to content

Commit

Permalink
make sure NA is returned for Greeks that not implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
hudde committed Sep 4, 2023
1 parent 724b3e8 commit f2c1da7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion R/BS_European_Greeks.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ BS_European_Greeks <-
"lambda", "gamma", "vanna", "charm", "vomma", "veta",
"speed")) {

result <- vector(mode = "numeric", length = length(greek))
result <- vector(mode = "numeric", length = length(greek)) * NA

names(result) <- greek

Expand Down
2 changes: 1 addition & 1 deletion R/BS_Geometric_Asian_Greeks.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ BS_Geometric_Asian_Greeks <- function(
payoff = "call",
greek = c("fair_value", "delta", "rho", "vega", "theta", "gamma")) {

result <- numeric(length(greek))
result <- numeric(length(greek)) * NA

names(result) = greek

Expand Down
2 changes: 1 addition & 1 deletion R/BS_Malliavin_Asian_Greeks.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ BS_Malliavin_Asian_Greeks <- function(
result <-
matrix(ncol = length(greek),
nrow = length(vectorized_param),
dimnames = list(NULL, greek))
dimnames = list(NULL, greek)) * NA

## the payoff function ##

Expand Down
2 changes: 1 addition & 1 deletion R/Malliavin_European_Greeks.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Malliavin_European_Greeks <-
seed = 1,
antithetic = FALSE) {

result <- vector(mode = "numeric", length = length(greek))
result <- vector(mode = "numeric", length = length(greek)) * NA

names(result) <- greek

Expand Down
15 changes: 7 additions & 8 deletions R/Malliavin_Geometric_Asian_Greeks.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ Malliavin_Geometric_Asian_Greeks <- function(
result <-
matrix(ncol = length(greek),
nrow = length(vectorized_param),
dimnames = list(NULL, greek))
dimnames = list(NULL, greek)) * NA

## the payoff function ##

## kommentieren??
## TODO: comment
payoff_name <- payoff

if (inherits(payoff, "function")) {
Expand Down Expand Up @@ -136,8 +136,7 @@ Malliavin_Geometric_Asian_Greeks <- function(
tXW <- calc_tXW(X, W, steps, paths, dt)
}

#rm(W)
#?????? kommentieren
# TODO: comment
I_W <- calc_I(W, steps, dt)

### the calculation of I_{(n)}, the integral \int_0^T t^n X_t dt ###
Expand Down Expand Up @@ -180,7 +179,7 @@ Malliavin_Geometric_Asian_Greeks <- function(
dpayoff(initial_price * I_0/time_to_maturity, exercise_price) * weight)
}

# hier was erklären ??
# TODO: comment
I_0_geom <-
exp(calc_I(log(initial_price * X), steps, dt) / time_to_maturity)

Expand Down Expand Up @@ -226,7 +225,7 @@ Malliavin_Geometric_Asian_Greeks <- function(
model <- lm(rho ~ cont)

result[i, "rho"] <- model$coefficients["(Intercept)"]
}
} #rho

if ("theta" %in% greek) {
result[i, "theta"] <-
Expand All @@ -235,7 +234,7 @@ Malliavin_Geometric_Asian_Greeks <- function(
(1/volatility) * X_T * W_T + time_to_maturity * X_T) / I_1 +
(1/time_to_maturity * I_0 * I_2 - I_2 * X_T) / (I_1^2)) %>%
E()
}
} #theta

if ("vega" %in% greek) {
result[i, "vega"] <-
Expand All @@ -259,7 +258,7 @@ Malliavin_Geometric_Asian_Greeks <- function(
+ volatility * (3*W_T*I_2 - volatility*I_3)*I_0^2/I_1^3
+ 3*volatility^2*I_0^2*I_2^2/I_1^4)) %>%
E()
}# gamma
} #gamma

}

Expand Down

0 comments on commit f2c1da7

Please sign in to comment.