140 likes | 296 Views
HW 11. 100071021. Close Form. function [ cdi, cdo , pdi , pdo ] = BOD_cf ( S0,K,r,q,T,sigma,Sb ) ssqT = sigma* sqrt (T); lamda = ( r-q+0.5*sigma^2 ) / sigma^2 ; y = ( log( Sb^2 / (S0*K) ) / ssqT ) + lamda*ssqT; x1 = ( log(S0/Sb) / ssqT ) + lamda * ssqT ;
E N D
HW11 100071021
Close Form function [ cdi, cdo, pdi, pdo ] = BOD_cf ( S0,K,r,q,T,sigma,Sb ) ssqT = sigma*sqrt(T); lamda = ( r-q+0.5*sigma^2 ) / sigma^2 ; y = ( log( Sb^2 / (S0*K) ) / ssqT ) + lamda*ssqT; x1 = ( log(S0/Sb) / ssqT ) + lamda*ssqT; y1 = ( log(Sb/S0) / ssqT ) + lamda*ssqT; [c , p] = blsprice(S0,K,r,T,sigma,q);
if Sb <= K cdi = S0*exp(-q*T)*( (Sb/S0)^(2*lamda) )*normcdf(y) - K*exp(-r*T)*( (Sb/S0)^(2*lamda-2) )*normcdf(y-ssqT); cdo = c - cdi; pdi = -S0*exp(-q*T)*normcdf(-x1) + K*exp(-r*T)*normcdf(-x1+ssqT) + S0*exp(-q*T)*( (Sb/S0)^(2*lamda) )*( normcdf(y) - normcdf(y1) ) - K*exp(-r*T)*( (Sb/S0)^(2*lamda-2) )*( normcdf(y-ssqT) - normcdf(y1-ssqT) ); pdo = p - pdi; else cdo = S0*exp(-q*T)*normcdf(x1) - K*exp(-r*T)*normcdf(x1-ssqT) - S0*exp(-q*T)*( (Sb/S0)^(2*lamda) )*normcdf(y1) + K*exp(-r*T)*( (Sb/S0)^(2*lamda-2) )*normcdf(y1-ssqT); cdi = c - cdo; pdo = 0; pdi = p; end end
Close Form adjust to discrete function [ cdi, cdo, pdi, pdo ] = BOD_cf_d ( S0,K,r,q,T,sigma,Sb,m ) Sb = Sb*exp(-0.5826*sigma*sqrt(T/m)); ……
Monte Carlo function [ c , p ] = BO_MC ( S0,K,r,T,sigma,Sb,ud,io,NRepl,NStep,rmode ) % rmode : 0(default)=>randn 1=>Halton % ud : 0=>up 1=>down % io : 0=>in 1=>out fori = 1 : NRepl MCS = AssetPaths(S0,r,sigma,T,NStep,1,rmode); crossed_u = any(MCS >= Sb); crossed_d = any(MCS <= Sb); pc(i) = max( 0, MCS(NStep+1) - K ); pp(i) = max( 0, K - MCS(NStep+1) );
if ( (ud==0 && io==0) && crossed_u==0 ) || ( (ud==0 && io==1) && crossed_u==1 ) || ( (ud==1 && io==0) && crossed_d==0 ) || ( (ud==1 && io==1) && crossed_d==1 ) pc(i) = 0; pp(i) = 0; end end [c var ci] = normfit( exp(-r*T)*pc ); [p var ci] = normfit( exp(-r*T)*pp ); end
Demo S0 = 50; K = 50; r = 0.1; T = 2/12; sigma = 0.4; Sb = 40; NRepl = 50000; NStep = 60; [ cdi, cdo, pdi, pdo ] = BOD_cf ( S0,K,r,0,T,sigma,Sb ) CF = ones(1,1000) * pdi; rand('seed',0); randn('seed',0);
figure; for i = 1:600 [a, b, c, d] = BOD_cf_d ( S0,K,r,0,T,sigma,Sb,i ); Descrete(i) = c; end plot(1:600,Descrete,1:600,CF(1:600))
Up and In Call 1~10000 1~600
figure; MC_R = zeros(1,100); for i = 1:100 [a ,MC_R(i)] = BO_MC ( S0,K,r,T,sigma,Sb,1,0,i*100,NStep,0 ); x = i end plot(1:100,MC_R,1:100,CF(1:100)); title('MC with randn');
figure; for i = 1:600 [a, b, c, d] = BOD_cf_d ( S0,K,r,0,T,sigma,Sb,i ); Descrete(i) = c; end plot(1:600,Descrete,1:600,CF(1:600))