# R program to compute and also estimate the Black-Scholes price # of a European Call Option M = 1000 # stock parameters: a = 100 r = 0.03 T = 10 q = 105 sigma = 0.1 # the Black-Scholes formula: trueprice = a * pnorm( 1/sigma/sqrt(T) * ( log(a/q) + T*(r+sigma^2/2) ) ) - q * exp(-r*T) * pnorm( 1/sigma/sqrt(T) * ( log(a/q) + T*(r-sigma^2/2) ) ) # Monte Carlo estimate: h = 0.05 num = round(T/h) vallist = rep(0,M) for (j in 1:M) { X = rep(0,num+1) X[1] = a for (i in 1:num) X[i+1] = rnorm(1, mean = X[i] + r*X[i]*h, sd = sigma*X[i]*sqrt(h)) vallist[j] = exp(-r*T) * max(0, X[num+1]-q) } estmean = mean(vallist) se = sd(vallist) / sqrt(M) # Output results: cat("European option, a=", a, " r=", r, " T=", T, " q=", q, "\n", sep="") cat("Black-Scholes formula for price:", trueprice, "\n") cat("Monte Carlo estimated price:", estmean, "+-", se, "\n") cat("95% confidence interval: (", estmean-1.96*se, ",", estmean+1.96*se, ")\n") # Plot the final simulation: thetimes = (0 : (T/h)) plot(thetimes, X, type='l')