I was hoping to get some help integrating a function that is based on a random variable. The function is to get an expected value of a continuous distribution.
Here is the code that I have so far.
montecarlo <- function(r,v,t,x,k) {
y <- rnorm(1)
e <- (y*(x*exp((-v*sqrt(t)*y)+((r-(.5*v^2))*t))-k))
MCOP <- exp(-r*t)*integrate(e, lower = -Inf, upper = Inf)
if((x*exp((-v*sqrt(t)*y)+((r-(.5*v^2))*t))-k) > 0) {
return(MCOP)
} else {
return(0)
}
}
If I type in for instance: montecarlo(.03, .65, 3, 34, 30)
I get an error message that reads:
Error in get(as.character(FUN), mode = "function", envir = envir) :
object 'e' of mode 'function' was not found