AdamElKaroui
AdamElKaroui

Reputation: 81

Numerical integration in R

I am trying to compute this integral :

enter image description here

"A" and "Beta" are constants, "PHI" capital is the marginal distribution function of the Normal Law N(0,1), and "phi" is the density of the Normal Law N(0,1) and P(tau <= t) = 1/2

Here is my implementation :

integral <- function(A, beta) {

f <- function(x) {

# We have P(tau <= t) = 1/2

pnorm(qnorm(1/2,0,1) - beta*x / (sqrt(1-(beta^2))), 0, 1)*(1/sqrt(2*pi)*exp(-x^2 / 2)    

}


integrate(f,lower=-Inf, upper = A)$value

}

I am not really sure about the qnorm function.. Is there a better way to do the computation?

Upvotes: 3

Views: 1705

Answers (1)

M.F
M.F

Reputation: 109

not that The "/" operator is superior to "-".means in this line

pnorm(qnorm(1/2,0,1) - beta*x / (sqrt(1-(beta^2))), 0, 1)

you made a mistake.correct is

(qnorm(1/2,0,1) - beta*x)
 ###not pnorm(qnorm(1/2,0,1)- beta*x.... =>pnorm((qnorm(1/2,0,1) - 
 ###beta*x)....

I use this code and I got answer

integral <- function(A, beta) {
f <- function(x) {
temp<-(qnorm(1/2,0,1) - beta*x) / (sqrt(1-(beta^2)))
pnorm(temp,0,1)*dnorm(x,0,1)    
}
integrate(f,lower=-Inf, upper = A)$value
}
integral(0,0)  ##.25
integral(10,.9) ##.5

also if you want another way to calculate any complicated integrate you can use monte carlo methods or .....

Upvotes: 2

Related Questions