function pricepath(imax)

tic
Sinit = 100;    % stock price 
X = 100;        % strike price 
B = 120;        % barrier 
r = 0.055;      % risk free rate 
q = 0.025;      % dividend yield 

Vinit = 0.04;   % inital volatility of the underlying 
sigma = 0.2;  % volatility of volatility 
k = 1.5;         % rate of volatility return to long term mean 
theta = 0.04;  % long term volatility 
rho = -0.5;     % correlation between the wiener processes 

dt = 0.01;      % time step 
T = 1;           % maturity 

i = 0;              % start of stock price paths 
%imax = 1000;     % number of stock price paths 
nmax = T/dt;   % number of time steps 
path = zeros(imax,nmax); 

while i < imax 
    i = i + 1; 

    S = 0; 
    V = 0; 
    p = 0; 

    path(i,1) = Sinit; 
    R = normrnd(0,1,3,nmax); 
    S(1) = Sinit; V(1) = Vinit; 

    while p < nmax-1 
        p = p + 1; 

        V(p+1) = V(p) + k*(theta - V(p))*dt + sigma*sqrt(V(p))* ... 
            (rho*R(1,p) + sqrt(1- rho^2)*R(2,p))*sqrt(dt); 

        S(p+1) = S(p) + (r-q)*S(p)*dt + S(p)*sqrt(V(p))*R(3,p)*sqrt(dt); 

        path(i,p+1) = S(p+1); 
     end 

    if S(nmax) > X 
        c = (S(nmax) - X) / exp(r*T); 
    else 
        c = 0; 
    end 

    if max(S) > B 
        c = 0;     % call equal to zero if the barrier is hit 
    else 
    end 
    option(i) = c; 
end 

Truevalue = mean(option) 
whos path
toc
end