《欧式期权二叉树定价MATLAB代码.docx》由会员分享,可在线阅读,更多相关《欧式期权二叉树定价MATLAB代码.docx(2页珍藏版)》请在三一办公上搜索。
1、欧式期权二叉树定价MATLAB代码调用函数代码 function Price=EuroOption(S0,K,T,r,M,type,sigma) dt = T/M; u=exp(sqrt(dt)*sigma); d=1/u; p = (exp(r*dt)-d)/(u-d); S=zeros(M+1,M+1); S(1,1)=S0; for j=1:M for i=0:j S(i+1,j+1)= S0*u(j-i)*di; end end V=zeros(M+1,M+1); for i=0:M switch type casecall V(i+1,M+1)=max(S(i+1,M+1)-K,0)
2、; caseput V(i+1,M+1)=max(K-S(i+1,M+1),0); casestra V(i+1,M+1)=max(S(i+1,M+1)-K,0)+max(K-S(i+1,M+1),0); casebino V(i+1,M+1) =(S(i+1,M+1)K); end end for j=M-1:-1:0 for i=0:j V(i+1,j+1)=exp(-r*dt)*(p*V(i+1,j+2)+(1-p)*V(i+2,j+2); end end Price=V(1,1); 数据作图S0 = 6; K = 5; T = 1; r = 0.05; sigma = 0.20; fo
3、r M=1:100 type=call; Price=EuroOption(S0,K,T,r,M,type,sigma); Vec(M)=Price; end for M=1:100 type=put; Price=EuroOption(S0,K,T,r,M,type,sigma); Vep(M)=Price; end for M=1:100 type=call; Price=AmOption(S0,K,T,r,M,type,sigma); Vac(M)=Price; end for M=1:100 type= put; Price=AmOption(S0,K,T,r,M,type,sigma); Vap(M)=Price; end figure(1) plot(Vec,b); holdon plot(Vac,r); holdoff legend (Eurocall,Amcall); figure(2) plot(Vep,b); holdon plot(Vap,r); legend (Europut,Amput);