function v=putopt(u,S0,ex,r,sigma,T)
% value of the integrand for a put option with exercise price ex, r=annual interest 
% rate, sigma=annual vol, S0=current stock price. u=uniform (0,1) input to 
%generate normal variate by inverse transform. T=term
%For Black-Scholes, integrate (0,1).
x=S0*exp(norminv(u,r*T-sigma^2*T/2,sigma*sqrt(T))); 
v=exp(-r*T)*max((x-ex),0); %value of call option
v=S0*exp(-r*T)+v-S0;   % value of put