Results 1 to 2 of 2

Math Help - Help, MatLab - Binomial results

  1. #1
    Newbie
    Joined
    Feb 2009
    Posts
    1

    Help, MatLab - Binomial results

    Hi,

    I use a binomial model to price an European put option. The code is pretty simple.

    My problem is I want to test the answer for values of M from 1:100. However, the only answer that is kept in the workspace is for the latest value of the option, when M = 100.

    How could I create a table in the workspace that would keep trace of every value of the option for the given M [1:100]

    Thanks,

    Here is the code

    Code:
    % Binomial method for a European put.
    %
    % Uses explicit solution based on binomial expansion.
    % Vectorized and based on logs to avoid overflow.
    
    %%%%%%%%%% Problem and method parameters %%%%%%%%%%%%%
    
    for M = 1:100
    S = 5;E = 10;T = 1;r = 0.06;sigma = 0.3;
    dt = T/M;h = 1;
    u = exp(sigma*dt^0.5)+h*sigma^2*dt;d = 1/u;p = (exp(r*dt)-d)/(u-d);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    % Option values at time T
    W = max(E-S*d.^([M:-1:0]').*u.^([0:M]'),0);
    % log/cumsum version
    csl = cumsum(log([1;[1:M]']));
    tmp = csl(M+1) - csl - csl(M+1:-1:1) + log(p)*([0:M]') + log(1-p)*([M:-1:0]');
    value = exp(-r*T)*sum(exp(tmp).*W);
     
    disp('Option value is'), disp(value)
    
    end
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Code:
    % Binomial method for a European put.
    %
    % Uses explicit solution based on binomial expansion.
    % Vectorized and based on logs to avoid overflow.
    
    %%%%%%%%%% Problem and method parameters %%%%%%%%%%%%%
     
    SavedResults=[];  
    
    for M = 1:100
    S = 5;E = 10;T = 1;r = 0.06;sigma = 0.3;
    dt = T/M;h = 1;
    u = exp(sigma*dt^0.5)+h*sigma^2*dt;d = 1/u;p = (exp(r*dt)-d)/(u-d);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    % Option values at time T
    W = max(E-S*d.^([M:-1:0]').*u.^([0:M]'),0);
    % log/cumsum version
    csl = cumsum(log([1;[1:M]']));
    tmp = csl(M+1) - csl - csl(M+1:-1:1) + log(p)*([0:M]') + log(1-p)*([M:-1:0]');
    value = exp(-r*T)*sum(exp(tmp).*W);
     
    disp('Option value is'), disp(value)
     
    SavedResults=[SavedResults,value];
    
    end
    and the array SavedResults should contain all the results.

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. different results
    Posted in the Calculus Forum
    Replies: 5
    Last Post: October 20th 2011, 05:44 AM
  2. Matlab problem. Showing capital I and PI in results.
    Posted in the Math Software Forum
    Replies: 2
    Last Post: February 23rd 2010, 01:34 AM
  3. Need help plotting results from a circuit in Matlab
    Posted in the Math Software Forum
    Replies: 0
    Last Post: February 15th 2010, 02:53 PM
  4. [SOLVED] Increasing decimal places in Matlab results
    Posted in the Math Software Forum
    Replies: 1
    Last Post: July 30th 2009, 06:53 AM
  5. (A o r)(t) results too high
    Posted in the Pre-Calculus Forum
    Replies: 3
    Last Post: April 13th 2008, 02:34 PM

Search Tags


/mathhelpforum @mathhelpforum