% Script for Monte Carlo calculation of Asian option.
% Values for r, sigma, T, s, N, and M must be prescribed.
dt=T/M;
W=sqrt(dt)*cumsum([zeros(1,N);randn(M,N)]);
S=s*exp((r-sigma^2/2)*linspace(0,T,M+1)'*ones(1,N)+sigma*W);
ST=S(M+1,:); YT=trapz(S)*dt;
%
VT=ST-r*YT; %v(6)(s,y,T) for demonstration
MCanl(exp(-r*T)*VT)
exp(-r*T)*s %known true value = v(6)(s,0,0)