% Copyright (c) 2001-2009 by Ales Cerny %************************************************************************% % chapter5sect3.m - supplementary program to % % Ales Cerny (2009) Mathematical Techniques in Finance (2nd ed.) % % Princeton University Press http://press.princeton.edu/titles/9079.html % %************************************************************************% % This code is provided 'as-is', without any express or implied warranty. % % Permission is granted to anyone to use this code for any purpose, % subject to the following restrictions: % % 1. The origin of this code must not be misrepresented; you must not % claim that you wrote the original code. % 2. Modified code versions must be plainly marked as such, and must not % be misrepresented as being the original code. % 3. This notice may not be removed from any source distribution. % NOTICE TO STUDENTS: To avoid accusations of plagiarism, if you use this % code or its modifications in assessed work you should prepend it with a % note stating: % "This is the original/modified version of the code chapter5sect3.m by % Ales Cerny (2009), Mathematical Techniques in Finance (2nd ed.), % Princeton University Press. The original version is available from % http://www.martingales.info/mtfweb2". % A similar acknowledgement should appear prominently inside your written % report. % This program implements binomial option pricing model clear; % clear the workspace clc; % clear screen %************************% % market % %************************% S0 = 5100; % initial stock price strike = 5355; Rsafe = 1.0033; % monthly safe return R = [1.053 0.965]; % monthly stock return %************************% % Risk-neutral % % probabilities % %************************% QDistr=[Rsafe-R(2) R(1)-Rsafe]./(R(1)-R(2)); %************************% % grid indexation % %************************% Tidx=4; % number of trading dates dlnS=log(R(1))-log(R(2)); % increment on log price grid highlnR=log(R(1)); % the highest return over one period % there are tt live cells at time tt, highest stock price at the top % log price at cell 1 at time tt is ln(S0)+(tt-1)*highlnR % log price at cell ii at time tt is ln(S0)+(tt-1)*highlnR-(ii-1)*dlnS C = zeros(Tidx,Tidx); % initialize the grid for call option price stock = zeros(Tidx,Tidx); % initialize the grid for stock price delta = zeros(Tidx,Tidx); % initialize the grid for option delta %************************% % option payoff % %************************% S_T = log(S0)+(Tidx-1)*highlnR-(0:(Tidx-1))*dlnS; % log of stock price at maturity S_T=exp(S_T'); % stock price at maturity C_T=max([(S_T-strike)';zeros(1,length(S_T))]); % option payoff at maturity stock(:,Tidx)=S_T; % stock price grid at maturity C(:,Tidx)= C_T'; % option price =option payoff at T %************************% % main loop % %************************% for tt = Tidx-1 : -1 : 1 for ii = 1 : 1 : tt stock(ii,tt)=S0*exp((tt-1)*highlnR-(ii-1)*dlnS); C(ii,tt)=(QDistr*C(ii:ii+1,tt+1))/Rsafe; % risk-neutral pricing delta(ii,tt)=(C(ii,tt+1)-C(ii+1,tt+1))... /(R(1)-R(2))/stock(ii,tt); end end %*********************% % output % %*********************% disp( '__________________________________________'); disp(' stock price '); disp(' '); disp(num2str(stock,'%12.1f')); disp( '__________________________________________'); disp(' '); disp(' '); disp( '__________________________________________'); disp(' option price '); disp(' '); disp(num2str(C,'%12.2f')); disp( '__________________________________________'); disp(' '); disp(' '); disp( '__________________________________________'); disp(' dynamic delta '); disp(' '); disp(num2str(delta,'%12.3f')); disp( '__________________________________________'); disp(' '); disp(' '); disp( '__________________________________________'); disp(' bank account '); disp(' '); disp(num2str(C-delta.*stock,'%11.1f')); disp( '__________________________________________'); disp(' '); disp(' ');