Guest User

Untitled

a guest
Mar 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. %
  2. % Vectorized version, uses shifts via colon notation.
  3. %%%%%%%%%% Problem and method parameters %%%%%%%%%%%%%
  4. S = 5;E = 10;T = 1;r = 0.06;sigma = 0.3;M = 256;
  5. dt = T/M;A = 0.5*(exp(-r*dt)+exp((r+sigma^2)*dt));
  6. u=A+ sqrt(A^2-1);d = 1/u;p = (exp(r*dt)-d)/(u-d);
  7. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  8. % Option values at time T
  9. W = max(E-S*d.^([M:-1:0]').*u.^([0:M]'),0);
  10. histogram(W,50);
  11. title('Underlying Price at Maturity')
  12.  
  13. % Re-trace to get option value at time zero
  14. q = 1-p;
  15. for i = M:-1:1
  16. W = p*W(2:i+1) + q*W(1:i);
  17. end
  18. W = exp(-r*T)*W;
Add Comment
Please, Sign In to add comment