Skip to content

Instantly share code, notes, and snippets.

@dirkschumacher
Created August 2, 2019 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirkschumacher/ae677f4b7d64ae17c0dc19a65f883d85 to your computer and use it in GitHub Desktop.
Save dirkschumacher/ae677f4b7d64ae17c0dc19a65f883d85 to your computer and use it in GitHub Desktop.
library(armacmp)

# taken from https://gallery.rcpp.org/articles/black-scholes-three-ways/
put_option_pricer_arma <- armacmp(function(s = type_colvec(),
                                           k = type_scalar_numeric(),
                                           r = type_scalar_numeric(),
                                           y = type_scalar_numeric(),
                                           t = type_scalar_numeric(),
                                           sigma = type_scalar_numeric()) {
  d1 <- (log(s / k) + (r - y + sigma^2.0 / 2.0) * t) / (sigma * sqrt(t))
  d2 <- d1 - sigma * sqrt(t)
  
  V <- pnorm(-d2) %*% k %*% exp(-r * t) - s %*% exp(-y * t) * pnorm(-d1)
  
  return(V, type = type_colvec())
})

put_option_pricer_arma(s = 55, 60, .01, .02, 1, .05)
#>          [,1]
#> [1,] 5.520212

Created on 2019-08-02 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment