Presentation is loading. Please wait.

Presentation is loading. Please wait.

4/20 Matlab 作業 103071470 石磊. Oil bond function [price,lattice]=oilbond(P0,r,T,sigma,N) deltaT=T/N; u=exp(sigma*sqrt(deltaT)); d=1/u; p=(exp(r*deltaT)-d)/(u-d);

Similar presentations


Presentation on theme: "4/20 Matlab 作業 103071470 石磊. Oil bond function [price,lattice]=oilbond(P0,r,T,sigma,N) deltaT=T/N; u=exp(sigma*sqrt(deltaT)); d=1/u; p=(exp(r*deltaT)-d)/(u-d);"— Presentation transcript:

1 4/20 Matlab 作業 103071470 石磊

2 Oil bond function [price,lattice]=oilbond(P0,r,T,sigma,N) deltaT=T/N; u=exp(sigma*sqrt(deltaT)); d=1/u; p=(exp(r*deltaT)-d)/(u-d); lattice=zeros(N+1,N+1); for j=0:N if P0*(u^j)*(d^(N-j))>40; lattice(N+1,j+1)=1000+(40-25)*170; elseif P0*(u^j)*(d^(N-j))<25; lattice(N+1,j+1)=1000; else P0*(u^j)*(d^(N-j))>=25 & P0*(u^j)*(d^(N-j))<=40; lattice(N+1,j+1)=1000+(P0*(u^j)*(d^(N-j))-25)*170; end for i=N-1:-1:0 for j=0:i lattice(i+1,j+1)=exp(-r*deltaT)*… (p*lattice(i+2,j+2)+(1-p)*lattice(i+2,j+1)); end price=lattice(1,1);

3 Oil bond >> sigma=0.2; r=0.02; P0=30; N=10; T=1; >> [price,lattice]=oilbond(P0,r,T,sigma,N) price = 1.9464e+03

4 Oil bond lattice = 1.0e+03 * 1.9464 0 0 0 0 0 0 0 0 0 0 1.7034 2.1972 0 0 0 0 0 0 0 0 0 1.4794 1.9342 2.4689 0 0 0 0 0 0 0 0 1.2902 1.6745 2.2016 2.7462 0 0 0 0 0 0 0 1.1471 1.4385 1.9173 2.4948 3.0086 0 0 0 0 0 0 1.0541 1.2446 1.6381 2.2041 2.7954 3.2337 0 0 0 0 0 1.0072 1.1053 1.3890 1.8939 2.5230 3.0790 3.4014 0 0 0 0 0.9940 1.0243 1.1906 1.5929 2.2024 2.8538 3.3165 3.4999 0 0 0 0.9960 0.9960 1.0568 1.3292 1.8630 2.5507 3.1683 3.4781 3.5358 0 0 0.9980 0.9980 0.9980 1.1198 1.5439 2.1895 2.9220 3.4272 3.5429 3.5429 0 1.0000 1.0000 1.0000 1.0000 1.2440 1.8500 2.5377 3.3181 3.5500 3.5500 3.5500

5 Index Currency Option Notes function [price,lattice]=LatticeCurrencyOptionNotes(P0,r,T,sigma,N) deltaT=T/N; u=exp(sigma*sqrt(deltaT)); d=1/u; p=(exp(r*deltaT)-d)/(u-d); lattice=zeros(N+1,N+1); for j=0:N if P0*(u^j)*(d^(N-j))>=169; lattice(N+1,j+1)=1000; end if P0*(u^j)*(d^(N-j))<=84.5; lattice(N+1,j+1)=0; end if P0*(u^j)*(d^(N-j))>84.5 & P0*(u^j)*(d^(N-j))<169; lattice(N+1,j+1)=1000-(1000/(P0*(u^j)*(d^(N-j))-1)); end for i=N-1:-1:0 for j=0:i lattice(i+1,N+1-j)=exp(-r*deltaT)*... (p*lattice(i+2,N+1-j)+(1-p)*lattice(i+2,N-j)); end price=lattice(1,N+1);

6 Index Currency Option Notes >> sigma=0.5; r=0.02; P0=100; N=10; T=1; >> [price,lattice]=LatticeCurrencyOptionNotes(P0,r,T,sigma,N) price = 524.9573

7 Index Currency Option Notes lattice = 1.0e+03 * 0 0 0 0 0 0 0 0 0 0 0.5250 0 0 0 0 0 0 0 0 0 0.4083 0.6605 0 0 0 0 0 0 0 0 0.2864 0.5492 0.7904 0 0 0 0 0 0 0 0.1718 0.4184 0.7009 0.8960 0 0 0 0 0 0 0.0795 0.2779 0.5806 0.8413 0.9623 0 0 0 0 0 0.0217 0.1459 0.4299 0.7553 0.9431 0.9882 0 0 0 0 0 0.0467 0.2599 0.6258 0.9063 0.9892 0.9914 0 0 0 0 0 0.1001 0.4434 0.8368 0.9896 0.9929 0.9940 0 0 0 0 0 0.2149 0.7063 0.9895 0.9939 0.9960 0.9960 0 0 0 0 0 0.4612 0.9892 0.9941 0.9980 0.9980 0.9980 0 0 0 0 0 0.9899 0.9927 1.0000 1.0000 1.0000 1.0000

8 HW2 Binary option( 二元選擇權 ) function [Price,CI]=BinaryMC(S0,X,r,T,sigma,NRepl) nuT=(r-0.5*sigma^2)*T; siT=sigma*sqrt(T); Veps=randn(NRepl,1); Payoff1=S0*exp(nuT+siT*Veps); Payoff1(S0*exp(nuT+siT*Veps)<X)=0; DiscPayoff =exp(-r*T)*Payoff1; [Price,VarPrice,CI]=normfit(DiscPayoff);

9 HW2 Binary option( 二元選擇權 ) function [Price,CI]=BinaryMCAV(S0,X,r,T,sigma,NRepl) nuT=(r-0.5*sigma^2)*T; siT=sigma*sqrt(T); Veps=randn(NRepl,1); Payoff1=S0*exp(nuT+siT*Veps); Payoff2=S0*exp(nuT+siT*(-Veps)); Payoff1(S0*exp(nuT+siT*Veps)<X)=0; Payoff2(S0*exp(nuT+siT*(-Veps))<X)=0; DiscPayoff =exp(-r*T)*0.5*(Payoff1+Payoff2); [Price,VarPrice,CI]=normfit(DiscPayoff);

10 HW2 Binary option( 二元選擇權 ) S0=50; X=50; r=0.1; T=5/12; sigma=0.4; >> NRepl1=100000; NRepl2=200000; >> randn('seed',0); [MC200000,CI1]=BinaryMC(S0,X,r,T,sigma,NRepl2); randn('seed',0); [MCAV100000,CI2]=BinaryMCAV(S0,X,r,T,sigma,NRepl1);

11 HW2 Binary option( 二元選擇權 ) >> MC200000 MC200000 = 30.6772 >> CI1(2)-CI1(1) ans = 0.2701 >> MCAV100000 MCAV100000 = 30.7209 >> CI2(2)-CI2(1) ans = 0.0718

12 MCIntegration rand('seed',0); N=1000; k=2; 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);

13 MCIntegration exp = 6.3891 exp10 = 5.9957 exp100 = 6.3768 exp1000 = 6.3803

14 Calculate π >> rand('seed',0); N=1000; meanpi=zeros(1,N); for i=1:N meanpi(i)=4*mean(sqrt(1-rand(1,i).^2)); end pi meanpi10=meanpi(10) meanpi100=meanpi(100) meanpi1000=meanpi(1000) plot(1:N,meanpi);

15 Calculate π ans = 3.1416 meanpi10 = 3.2407 meanpi100 = 3.1447 meanpi1000 = 3.1432


Download ppt "4/20 Matlab 作業 103071470 石磊. Oil bond function [price,lattice]=oilbond(P0,r,T,sigma,N) deltaT=T/N; u=exp(sigma*sqrt(deltaT)); d=1/u; p=(exp(r*deltaT)-d)/(u-d);"

Similar presentations


Ads by Google