160 likes | 262 Views
HW8. Oil Bond. Oil Bond - code. S = 30; r = 0.02; sigma = 0.06; T = 1; N = 10; deltaT = T/N; u = exp ( sigma * sqrt ( deltaT ) ); d = 1/u; p = ( exp( r * deltaT ) - d ) / ( u - d );. for i = 0 : N oilp(i+1) = S * u^(N-i) * d^(i); if oilp (i+1)<25 oilp (i+1) = 25;
E N D
Oil Bond - code S = 30; r = 0.02; sigma = 0.06; T = 1; N = 10; deltaT = T/N; u = exp( sigma * sqrt(deltaT) ); d = 1/u; p = ( exp( r * deltaT ) - d ) / ( u - d ); for i = 0 : N oilp(i+1) = S * u^(N-i) * d^(i); if oilp(i+1)<25 oilp(i+1) = 25; elseifoilp(i+1)>40 oilp(i+1) = 40; end oilp(i+1) = 1000+( oilp(i+1) -25)*170; end
Oil Bond – code (conti.) for i = N : -1 : 1 for j = 0 : i-1 oilp(j+1) = exp(-r*deltaT) * ( oilp(j+1)*p + oilp(j+2)*(1-p) ); end oillattice(1:i,i) = oilp(1:i); end format short g oilp(1,1) oillattice
Index Currency Option Notes - Code S = 102; r = 0.02; sigma = 0.102; T = 1; N = 10; deltaT = T/N; u = exp( sigma * sqrt(deltaT) ); d = 1/u; p = ( exp( r * deltaT ) - d ) / ( u - d ); for i = 0 : N currp(i+1) = S * u^(N-i) * d^(i); if currp(i+1)>169 currp(i+1) = 1000; elseifcurrp(i+1)<84.5 currp(i+1) = 0; else currp(i+1) = 1000-(1000*(169/currp(i+1)-1)) ; end end
Index Currency Option Notes - Code (Conti.) for i = N : -1 : 1 for j = 0 : i-1 currp(j+1) = exp(-r*deltaT) * ( currp(j+1)*p + currp(j+2)*(1-p) ); end currlattice(1:i,i) = currp(1:i); end format short g currp(1,1) currlattice
Monte Carlo Put Option function [ cp, pp, CIc, CIp] = blsMC( S, K, r, T, sigma, NRepl ) nuT = (r - 0.5*sigma^2) * T; siT = sigma * sqrt(T); c_payoffs = exp(-r*T) * max(0, S*exp(nuT + siT*randn(NRepl,1)) -K ); p_payoffs = exp(-r*T) * max(0, K - S*exp(nuT + siT*randn(NRepl,1)) ); [cp, varc, CIc] = normfit(c_payoffs); [pp, varp, CIp] = normfit(p_payoffs); end
Demo S = 50; K = 50; r = 0.1; T = 1; sigma = 0.2; lamda= 1.2; [blsout_c, blsout_p] = blsprice(S,K,r,T,sigma); bls = ones(100) * blsout_p; for i = 1:100 [bitc(i), bitp(i)] = bitprice(S,K,r,T,sigma,i,0); [tric(i), trip(i)] = triprice(S,K,r,T,sigma,lamda,i,0); [MCc(i), MCp(i), temp1,temp2] = blsMC(S,K,r,T,sigma,i*100); CId(i) = temp2(2)-temp2(1); end
Cash or Nothing function [ cp, pp ] = blsMC2( S, K, C, r, T, sigma, NRepl) nuT = (r - 0.5*sigma^2) * T; siT = sigma * sqrt(T); pvC = exp(-r*T) * C; Stock = S*exp(nuT + siT*randn(NRepl,1)); for i = 1:NRepl c_payoffs(i) = 0; p_payoffs(i) = 0; if Stock(i) > K c_payoffs(i) = pvC; elseif Stock(i) < K p_payoffs(i) = pvC; end end [cp, varc, CIc] = normfit(c_payoffs); [pp, varp, CIp] = normfit(p_payoffs); end
Demo S = 50; K = 50; C = 10; r = 0.1; T = 1; sigma = 0.2; NRpel= 10000; for TS = 1:100 [MC1c(TS), MC1p(TS)] = blsMC2(TS,K,C,r,T,sigma,NRpel); End figure; plot(MC1c); hold on; plot(MC1p,'color',[1 0 0.5]); title('Cash or Nothing');