Professional Documents
Culture Documents
hw7 101071010
hw7 101071010
101071010
CompIntegration.m
rand('seed',0);
k=2;
N=1000;
meanexp=zeros(1,N);
for i=1:N
meanexp(i)=k*mean(exp(k*rand(1,i)));
end
exp=exp(2)-1
exp10=meanexp(10)
exp100=meanexp(100)
exp1000=meanexp(1000)
plot(1:N,meanexp);
100
200
300
400
500
600
700
800
900
6.3891
1000
GetHalton.m
IrwinHall.m
function d=IrwinHall(n)
x=rand(1,n);
c=0;
for i=0:n-12
for j=1:12
c=c+x(i+j);
end
d(i+1)=c-6;
c=0;
end
CompIrwinHall.m
d=IrwinHall (100000);
a=mean(d)
b=std(d)
hist(d)
3
x 10
2.5
1.5
0.5
0
-4
-3
-2
-1
%Draw histogram
subplot(3,2,1);
hist(H1);
title('BM Halton by cos');
subplot(3,2,2);
hist(H2);
title('BM Halton by sin');
subplot(3,2,3);
hist(R1);
title('BM Rand by cos');
subplot(3,2,4);
hist(R2);
title('BM Rand by sin');
subplot(3,2,5);
hist(d);
title('IrwinHall');
subplot(3,2,6);
hist(a);
title('Normal Distribution');
10000
BM Halton by cos
BM Halton by sin
4000
3000
3000
2000
2000
1000
1000
0
-5
-4
-3
-2
-1
0
-4
-3
-2
-1
BM Rand by cos
BM Rand by sin
3000
4000
3000
2000
2000
1000
0
-4
1000
-3
-2
-1
0
-5
-4
-3
-2
IrwinHall
3000
2000
2000
1000
1000
-3
-2
-1
Normal Distribution
3000
0
-4
-1
0
-4
-3
-2
-1
HaltonEurPut.m
function Price = HaltonEurPut(S0,X,r,T,sigma,Npoints,Base1,Base2)
nuT=(r-0.5*sigma^2)*T;
siT=sigma*sqrt(T);
%Halton
H1=GetHalton(ceil(Npoints/2),Base1);
H2=GetHalton(ceil(Npoints/2),Base2);
%Box Muller
Vlog=sqrt(-2*log(H1));
Norm1=Vlog.*cos(2*pi*H2);
Norm2=Vlog.*sin(2*pi*H2);
Norm=[Norm1;Norm2];
DiscPayoff=exp(-r*T)*max(0,X-S0*exp(nuT+siT*Norm));
Price=mean(DiscPayoff);
CompHaltonEurPut.m
BlsP
Halton27
Halton117
Halton24