I'm a student and I want to solve a textbook exercise which is implementing Newton-Raphson Algorithm in R Programming.
This is the exercise:
#Inputs:
s0 <- 2.36
E <- 2.36
r <- 0.01
t <- 1
c <- 0.1875
#Initial values
sigma <-0.10
sig <- rep(0,10)
sig[1] <- sigma
#Newton-Raphson method:
for(i in 2:100){
d1 <- (log(s0/E)+(r+sigma^2/2)*t)/(sigma*sqrt(t))
d2 <- d1-sigma*sqrt(t)
f <- s0*pnorm(d1)-E*exp(r*t)*pnorm(d2)-c
#Derivative of d1 w.r.t. sigma:
d11 <- (sigma^2*t*sqrt(t)-(log(s0/E)+(r+sigma^2/2)*t)*sqrt(t))/(sigma^2*t)
#Derivative of d2 w.r.t. sigma:
d22 <- d11-sqrt(t)
#Derivative of f(sigma):
f1 <- s0*dnorm(d1)*d11-E*exp(-r*t)*dnorm(d2)*d22
#Update sigma:
sigma <- sigma - f/f1
sig[i] <- sigma
if(abs(sig[i]-sig[i-1]) < 0.00000001){sig <- sig[1:i]; break}}sig
The result for sig is [1] 0.1000000 0.2140636 0.2117527 0.2117864 0.2117859 0.2117859
But the answer in my textbook is: [1] 0.1000000 0.1877024 0.1876218 0.1876218
Can some one tell me where I've gone wrong?