《欧式期权二叉树定价MATLAB代码(3页).doc》由会员分享,可在线阅读,更多相关《欧式期权二叉树定价MATLAB代码(3页).doc(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-调用函数代码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 case call V(i+1,M+1)=max(S(i+1,M+1)-K,0); case put V(i+1,M
2、+1)=max(K-S(i+1,M+1),0); case stra V(i+1,M+1)=max(S(i+1,M+1)-K,0)+max(K-S(i+1,M+1),0); case bino V(i+1,M+1) =(S(i+1,M+1)K); endend for j=M-1:-1:0 for i=0:jV(i+1,j+1)=exp(-r*dt)*(p*V(i+1,j+2)+(1-p)*V(i+2,j+2); endendPrice=V(1,1);数据作图S0 = 6; K = 5; T = 1; r = 0.05; sigma = 0.20;for M=1:100 type=call;P
3、rice=EuroOption(S0,K,T,r,M,type,sigma); Vec(M)=Price;endfor M=1:100 type=put;Price=EuroOption(S0,K,T,r,M,type,sigma); Vep(M)=Price;endfor M=1:100 type=call;Price=AmOption(S0,K,T,r,M,type,sigma); Vac(M)=Price;endfor M=1:100 type= put;Price=AmOption(S0,K,T,r,M,type,sigma); Vap(M)=Price;end figure(1)plot(Vec,b);hold onplot(Vac,r);hold offlegend (Eurocall,Amcall);figure(2)plot(Vep,b);hold on plot(Vap,r);legend (Europut,Amput);-第 3 页-