1 / 22

HW14

HW14. 100071021. Range Forward. function [ K2,price ] = blsranfow ( F,K1,price,r,rf,T,sigma ) [temp,f1] = blsprice (F,K1,r,T,sigma,rf); price = max(price,0); f2 = price + f1; tryK = K1; found = 0; while 1 Vec = tryK-K1:0.0001:tryK; tryV = blsprice ( F,Vec,r,T,sigma,rf );.

Download Presentation

HW14

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. HW14 100071021

  2. Range Forward function [ K2,price ] = blsranfow( F,K1,price,r,rf,T,sigma ) [temp,f1] = blsprice(F,K1,r,T,sigma,rf); price = max(price,0); f2 = price + f1; tryK = K1; found = 0; while 1 Vec = tryK-K1:0.0001:tryK; tryV = blsprice(F,Vec,r,T,sigma,rf); if( min( find( tryV<=f2 ) ) ) found = min(find(tryV<=f2)); K2lb = Vec(found); ubprice = tryV(found); break; else tryK = tryK+K1; end end lbprice = blsprice(F,K2lb-0.0001,r,T,sigma,rf); K2 = K2lb + (f2-lbprice)/(ubprice-lbprice)*0.0001; end

  3. Demo Code %demo for range forward F = 27; K1 = 26.7; sigma = 0.0311; rf = 0.0304; r = 0.0565; T = 3/12; priceV= linspace(0,5); for i = 1:length(priceV) K2(i) = blsranfow( F,K1,priceV(i),r,rf,T,sigma ); end plot(priceV,K2); title('Price vs K2'); xlabel('price'); ylabel('K2');

  4. Sallie Mae function [ price, lattice ] = SallieMae( F, K, r, T, sigma, N ) deltaT = T/N; u = exp( sigma * sqrt(deltaT) ); d = 1/u; p = ( exp( r * deltaT ) - d ) / ( u - d ); P = ones(1,N+1) * 6.25; lattice(1:N+1,N+1) = P; for i = N : -1 : 1 for j = 0 : i-1 P(j+1) = exp(-r*deltaT) * ( P(j+1)*p + P(j+2)*(1-p) ); now_f = F * u^(i-1-j) * d^(j) ; early = 50 * ( now_f - K( ceil(i*length(K)/N) ) ) / now_f; P(j+1) = max( P(j+1) , early ); end lattice(1:i,i) = P(1:i); end price = P(1); end

  5. Demo Code F = 131.75; K = [131.75,129.50,127.00,124.50]; r = 0.1; T = 4; sigma = 0.1; N = 4; [ price, lattice ] = SallieMae( F, K, r, T, sigma, N ) price = 11.1103 lattice =

  6. Demo Code figure; timeV= linspace(0.01,10); for i = 1:length(timeV) P(i) = SallieMae( F, K, r, timeV(i), sigma, N ); end plot(timeV,P); title('Maturity vs Price'); xlabel('Time to Maturity'); ylabel('Price'); figure; for i = 1:200 L(i) = SallieMae( F, K, r, T, sigma, i ); end plot(1:200,L); title('N vs Price'); xlabel('N'); ylabel('Price');

  7. Finite Difference Explicit Method function [ call,put,cmatval,pmatval,vecS,vecT ] = blsFDEP( S,K,r,T,sigma,Smax,dS,dt) M = round(Smax/dS); dS = Smax/M; N = round(T/dt); dt = T/N; cmatval = zeros(M+1,N+1); pmatval = zeros(M+1,N+1); vecS = linspace(0,Smax,M+1); vecT = linspace(0,T,N+1);

  8. cmatval(:,N+1) = max(vecS - K, 0 ); pmatval(:,N+1) = max(K - vecS, 0 ); cmatval(M+1,:) = (Smax - K) * exp( -r*dt*(N:-1:0) ); pmatval(1,:) = K * exp( -r*dt*(N:-1:0) ); a = 0.5 * dt * (sigma^2*(0:M) - r) .* (0:M) ; b = 1 - dt * (sigma^2 * ((0:M).^2) + r) ; c = 0.5 * dt * (sigma^2*(0:M) + r) .* (0:M) ; for j = N:-1:1 for i = 2:M cmatval(i,j) = a(i)*cmatval(i-1,j+1) + b(i)*cmatval(i,j+1) + c(i)*cmatval(i+1,j+1); pmatval(i,j) = a(i)*pmatval(i-1,j+1) + b(i)*pmatval(i,j+1) + c(i)*pmatval(i+1,j+1); end end

  9. idown= floor(S/dS); iup = ceil(S/dS); if idown == iup call = cmatval(idown+1,1); put = pmatval(idown+1,1); else call = cmatval(idown+1,1) + (cmatval(idown+2,1)-cmatval(idown+1,1)) * (S - idown*dS)/dS ; put = pmatval(idown+1,1) + (pmatval(idown+2,1)-pmatval(idown+1,1)) * (S - idown*dS)/dS ; end end

  10. Demo Code S=50; K=50; r=0.1; T=5/12; sigma=0.3; Smax=100; dS=2; dt=5/1200; [ call,put,cmatval,pmatval,vecS,vecT ] = blsFDEP( S,K,r,T,sigma,Smax,dS,dt); call = 4.8695 put = 2.8288

  11. Demo Code figure; mesh(vecT,vecS,cmatval); xlabel('Stock Price'); ylabel('Time'); zlabel('Call Payoff'); figure; mesh(vecT,vecS,pmatval); xlabel('Stock Price'); ylabel('Time'); zlabel('Put Payoff');

  12. Demo Code figure; dSv = linspace(0.5,5); for i = 1 : length(dSv) C(i) = blsFDEP( S,K,r,T,sigma,Smax,dSv(i),dt); end plot(dSv,C);

  13. Demo Code figure; dtv = linspace(5/120000,5/12); for i = 1 : length(dtv) Q(i) = blsFDEP( S,K,r,T,sigma,Smax,dS,dtv(i)); end plot(dtv,Q);

More Related