% European Asian option.  Uses geometric or arithmetic average.
% Euler and Milstein discretization for Black-Scholes.
% By Fabrice Douglas Rouah

clc; clear;

% Option features.
S0  = 100;        % Spot price
K   = 100;        % Strike price
r   = 0.05;       % Risk free rate
q   = 0.0;        % Dividend yield
v   = 0.2;        % Volatility
mat = 0.25;       % Time to maturity
PutCall = 'C';    % 'P'ut or 'C'all
Averaging = 'G';  % 'A'rithmetic or 'G'eometric

% Simulation settings.
N = 50000;        % Number of simulations.
T = 100;         % Nuber of time steps.
dt = mat/T;      % Time increment

% Initialize the terminal stock price matrices 
% for the Euler and Milstein discretization schemes.
S = zeros(N,T);
S(:,1) = S0;

% Simulate the stock price under the Euler and Milstein schemes.
% Take average of terminal stock price.
for n=1:N
	for t=2:T
		dW = randn(1)*sqrt(dt);
		S(n,t) = S(n,t-1) + (r-q-v^2/2)*S(n,t-1)*dt + v*S(n,t-1)*dW...
  			    + 0.5*v^2*S(n,t-1)*dW^2;
	end
	if strcmp(Averaging,'A')
		A(n) = mean(S(n,:));
	elseif strcmp(Averaging,'G')
		A(n) = exp(mean(log(S(n,:))));
	end
end

% Define the payoff
if strcmp(PutCall,'C')
	Payoff = max(A - K, 0);
elseif strcmp(PutCall,'P')
	Payoff = max(K - A, 0);
end

% Calculate the price of the Asian option.
AsianPrice = exp(-r*mat)*mean(Payoff)
	
