function [v,vn]=fn_b(nsim) % for option on midterm, 2003 %u=vector of uniform (0,1) input to generate %normal variate by inverse randn('state',0) s0=10 ;K=10; sigma=.2 ; dt=1; s=[]; v=[]; r=0.045 for i=1:nsim s1=s0+r*s0*dt+sigma*(s0^.5)*sqrt(dt)*randn; s2=s1+r*s1*dt+sigma*(s1^.5)*sqrt(dt)*randn; s=[s s2]; % s is value of stock v=[v (s2>=8).*(s2-10).*(s2<=12)]; % v is the value of the option end v=(s>=8).*(s-10).*(s<=12); %discount option values to present v=exp(-2*r)*v; randn('state',0) s0=10 ;K=10; sigma=.2 ; dt=1; s=[]; vn=[]; r=0.055 for i=1:nsim s1=s0+r*s0*dt+sigma*(s0^.5)*sqrt(dt)*randn; s2=s1+r*s1*dt+sigma*(s1^.5)*sqrt(dt)*randn; s=[s s2]; % s is value of stock end vn=(s>=8).*(s-10).*(s<=12); % v is the value of the option vn=exp(-2*r)*vn; % discounted value of options, new r. c=cov([v',vn']); % covariance estimator