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)