function z=plotlogn(S0,r,sigma,T, K)
% outputs the discounted simulated return on expiry  of a call option (per dollar pv of stock).
% Expiry =T days from now, 
% current stock price=$S0. 
% r = annual spot interest rate
% sigma=annual vol.     K= strike price. 
N=250 ;  % N  is the assumed number of periods in a year.
s = sigma/sqrt(N);   %s  is volatility per period
mn = r/N - s^2/2;  % mean of the normal increments per period
y=exp(cumsum(normrnd(mn,s,T,1)));
y=S0*[1 y'];
x = (0:T)/N;
plot(x,y);
hold on
plot(x,K*ones(1,T+1),'g')
if (y(T+1)>K)
 plot([x(T+1) x(T+1)],[K y(T+1)],'g')
end
%plot(x,y,'-',x,K*ones(1,T+1),'y')
xlabel('time (in years)')
ylabel('value of stock')
title('SIMULATED RETURN FROM CALL OPTION')
z = exp(-r*T/N)*max(y(T+1)-K, 0);   % discounted to present payoff from option.