function Value = Binomial(u,d,R,n,S0) % Value = Binomial(u,d,R,n,S0) % % Returns the value of an European simple option with payoff Phi(S_T) % when the stock price follows a Binomial model on t=0,1,...,n, and % the money-market has interest rate R per period. % The program uses the Binomial algorithm (or Backward Induction)/ % Input Parameters: % u = Upward factor % d = Downward factor % R = Risk-free interest rate per unit time % n = Number of time steps % S0 = Initial option price % Payoff = function that returns the payoff at maturity (which is % assumed to be a function of S_n). This function should be coded % below. Now is coded to return the value of a European Call Option. % Output: % The value of the Option at time t=0. % % Additional information: % 1. You need to save this code with the name Binomial.m in some % folder % 2. Open the MATLAB and using the command cd foldername, move to the % folder where the program is saved % 3. from the command line, juts type Binomial(u,d,R,n,S0). % 4. You can check if the code is working by typing % Binomial(1.5,.5,0,3,80), which should return 27.5 (Example in % class). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Vectors of option value Vt = zeros(1,n+1); Vt_1 = zeros(1,n+1); %Computation of the risk-neutral probabilities qu = (1+R-d)/(u-d); qd = (u-(1+R))/(u-d); % Initialization for k=1:n+1 % k-1 = # of upward movements. Vt(k)=Payoff(S0*u^(k-1)*d^(n-(k-1))); end % Backward induction for j=1:n for k=1:n-j+1 Vt_1(k) = (qu*Vt(k+1)+qd*Vt(k))/(1+R); end Vt= Vt_1; end Value = Vt(1); end function P = Payoff(s) % This function returns the value of the payoff. % Right now is code to return the payoff of a European call option. K = 80; % Strike if s>K P = s-K; else P=0; end end