Code covered by the BSD License  

Highlights from
Approaches to implementing Monte Carlo methods in MATLAB

image thumbnail

Approaches to implementing Monte Carlo methods in MATLAB

by

 

28 Sep 2011 (Updated )

Code for the article in the September 2011 article http://www.wilmott.com/magazine.cfm

PriceArithmeticAsianOption(S0,X,r,T,sigma,NSteps,NPaths)
% Function to compute Arithmetic Asian Option price ; Using Loops
%
% See article "Approaches to implementing Monte Carlo methods in MATLAB"
% by Sri Krishnamurthy,CFA and Jorge Paloschi,PHD
% in the September 2011 article of Wimott Magazine or at
% http://www.wilmott.com/magazine.cfm 
%
% Copyright 2011 MathWorks, Inc.
function [Price] = PriceArithmeticAsianOption(S0,X,r,T,sigma,NSteps,NPaths)
dt=T/NSteps;
nuT = (r - 0.5*sigma^2)*dt;
siT = sigma * sqrt(dt);

for i=1:NPaths
    Path(i,1)= S0; %MATLAB warns here about preallocation for speed 
    for j=1:NSteps
        Path(i,j+1) = Path(i,j)*exp(nuT+siT*randn); %here as well
    end
   DiscPayoff(i) = exp(-r*T) * max(mean(Path(i,2:end)) - X,0); %and here
end
Price = mean(DiscPayoff);

Contact us