EssaysForStudent.com - Free Essays, Term Papers & Book Notes
Search

Matlab Code

Page 1 of 2

Set up a Matlab Code to value European call or put options with 10 periods. (You will need 11 columns, since today is time 0, and your model should end at time 10.) Allow each “period” to be one-tenth of a user-input time to maturity for the option.

To test your model, confirm the following values for call and put options with the given parameters.

Please attach your Matlab code in the homework as well.

Here are two solutions.

Solution 1

>> % M-file, bioption.m

S0 = input('Stock Price At Time Zero=');

X = input('Exercise Price=');

r = input('Risk Free Rate=');

Std = input('Volatility=');

T= input('Total length of time=');

Periods= input('Number of time steps to calculate=');

dt=T/Periods;

u=(1+Std*sqrt(dt))/(1-dt);

d=1/u;

p=(1+r-d)./(u-d);

NodeNum=Periods+1;

PriceTree=NaN(NodeNum,NodeNum);

PriceTree(1,1)=S0;

for idx=2:NodeNum

PriceTree(idx,idx)=PriceTree(idx-1,idx-1)*d;

PriceTree(1:idx-1,idx)=PriceTree(1:(idx-1),idx-1)*u;

end

CallValueTree= NaN(NodeNum,NodeNum);

PutValueTree= NaN(NodeNum,NodeNum);

        CallValueTree(:,:) = max(PriceTree(:,:)-X,0);

            PutValueTree(:,:) = max(X-PriceTree(:,:),0);

DiscCallValueTree= NaN(NodeNum,NodeNum);

DiscPutValueTree= NaN(NodeNum,NodeNum);

for idx=Periods:-1:1;

    DiscCallValueTree(1:idx,idx)= ((1+r)^(-dt*idx))*...

        (p*CallValueTree(1:idx,idx+1)+...

        (1-p)*CallValueTree(2:idx+1,idx+1));

    end

for idx=Periods:-1:1;

    DiscPutValueTree(1:idx,idx)=((1+r)^(-(dt*idx)))*...

        (p*PutValueTree(1:idx,idx+1)+...

        (1-p)*PutValueTree(2:idx+1,idx+1));

    end

CallOptionPrice=CallValueTree(1,1);

PutOptionPrice=PutValueTree(1,1);

Solution2

S0=50;K=50;r=0.1;T=5/12;sigma=0.4;N=2;

deltaT = T/N;

u=exp(sigma * sqrt(deltaT));

d=1/u;

p=(exp(r*deltaT) - d)/(u-d);

lattice = zeros(N+1,N+1);

for i=0:N

   lattice(i+1,N+1)=max(0 , S0*(u^i)*(d^(N-i)) - K);

end

for j=N-1:-1:0

   for i=0:j

      lattice(i+1,j+1) = exp(-r*deltaT) * ...

         (p * lattice(i+2,j+2) + (1-p) * lattice(i+1,j+2));

   end  

end

price = lattice(1,1);

If it is the American call

S0=100;K=100;r=0.06;T=1;sigma=0.25;N=10;

deltaT = T/N;

u=exp(sigma * sqrt(deltaT));

Download as (for upgraded members)
txt
pdf