% price a call option on the average price of two shares 
% plot result as a function of the correlation coefficient 

S10 = 15;
S20 = 30; 
r = 0.05;
sigma1 = 0.1 ;
sigma2 = 0.08; 
rho = -1:0.02:1; 
T = 1;
K = 24; 

M = 50000; 

Z = randn(M,2);

g4 = zeros(size(rho)); 
g5 = zeros(size(rho)); 

for i=1:length(rho) 

   V2 = rho(i) * Z(:,1) +  sqrt(1-rho(i)^2) * Z(:,2) ; 
   S1 = S10 * exp( (r-sigma1^2/2)*T + sigma1 * sqrt(T) * Z(:,1) );
   S2 = S20 * exp( (r-sigma2^2/2)*T + sigma2 * sqrt(T) * V2 ); 
   A = (S1+S2)/2 ;
   P = exp(-r*T)*(A-K).*(A>K); 
   g4(i) = mean(P); 
   g5(i) = std(P)/sqrt(M); 
   
end

figure(1)
plot(rho,g4) 
title('Option price as function of correlation')
xlabel('\rho')
ylabel('Price') 

figure(2)
plot(rho,g5) 
title('Stochastic error as function of correlation')
xlabel('\rho')
ylabel('Stochastic error') 
