clear xvalue = zeros(1,10000); %initialize matrix for w values obtained for each iteration at t=.5 meanxmatrix = zeros(1,10000); %initialize matrix for mean difference = zeros(1,10000); %initialize matrix for difference expectedcall = zeros(1,10000); %initialize matrix for expected value for j = 1:10000 %iterate through at least 10,000 repititions [t,w]=euler_maruyama([0,.5],12,100); xvalue(j) = w(101); %collect the w value at t=.5 for each iteration meanxmatrix(j) = 1; if xvalue(j)>15 difference(j) = xvalue(j)-15; else difference(j) = 0; end j = j+1; end meanxvalue = mean(difference); expectedcallvalue = exp(-.05*.5)*meanxvalue %compute the expected value of the call meanxmatrix = meanxmatrix*meanxvalue; %compute a matrix with the mean x value in every entry figure() %plot difference along with mean plot(difference) hold on plot(meanxmatrix,'ro') title('Plot of Call Values vs. Iteration Number') ylabel('max(X(t)-K,0) i.e. max(stock price - call price,0)') xlabel('Iteration Number') hold off