S0=100;
K=100;
T=1.0;
r=0.02;
sigma=0.25;

BSprice = BS_call(S0,K,T,r,sigma);

M=10^(1:6);

price = zeros(1,length(M));
rmse = zeros(1,length(M));

for i=1:length(M)
    [temp1, temp2]=BS_MC_call(S0,K,T,r,sigma,M(i));
    true(i)=BSprice
    price(i)=temp1
    rmse(i)=temp2
end

//Plots the Black-Scholes price,the MC estimate and the 95% and 99% confidence intervals as functions of the number of simulations M
plot(log(M),true,"k-",log(M),price,"b-",log(M),price-1.96*rmse,"r:",log(M),price-2.58*rmse,"g:",log(M),price+1.96*rmse,"r:",log(M),price+2.58*rmse,"g:")
xtitle("Convergence of Monte Carlo simulation")
hl=legend(['BS price';'MC price';'95% CI';'99%CI'])
xlabel("log(M)")
ylabel("Price")
