0% found this document useful (0 votes)
21 views3 pages

All All: If End

1. The document describes using three different numerical methods - explicit, leap frog, and Du Fort-Frankel - to solve a partial differential equation modeling the price of a European option. 2. The explicit method uses nested for loops to calculate the option price C_m at each time step moving backwards in time. 3. The leap frog method also uses nested for loops but calculates C_m at each alternate time step to improve stability. 4. The Du Fort-Frankel method explicitly calculates C_m at each time step as a function of neighboring values, avoiding instability issues.

Uploaded by

pv007rocks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

All All: If End

1. The document describes using three different numerical methods - explicit, leap frog, and Du Fort-Frankel - to solve a partial differential equation modeling the price of a European option. 2. The explicit method uses nested for loops to calculate the option price C_m at each time step moving backwards in time. 3. The leap frog method also uses nested for loops but calculates C_m at each alternate time step to improve stability. 4. The Du Fort-Frankel method explicitly calculates C_m at each time step as a function of neighboring values, avoiding instability issues.

Uploaded by

pv007rocks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Clear all

clear all
vals=[100:-2:0];
dt=(5/1200);
time=[0:dt:(5/12)];
C_m=nan(length(vals),length(time));
max=max(vals);
trial =(.4^2*max^2*dt)/(2^2)
if (trial>1)
disp('change the step size or max')
end
C_m(:,length(time))=max(vals-50*ones(1,length(vals)),0);
C_m(1,:)=(100-50*exp(-.1*((5/12)-time)));
C_m(length(vals),:)=0;
l=length(time)
for i=length(time)-1:-1:1
for j=2:(length(vals)-1)
C_m(j,i)=C_m(j,i+1) + dt*(.5*((.4*vals(j))/2)^2* (C_m(j+1,i+1)+C_m(j1,i+1)-2*C_m(j,i+1)) + .5*.1*(vals(j)/2) * (-C_m(j+1,i+1)+ C_m(j-1,i+1)) .1*C_m(j,i+1));
end
end
C_m
St_Pr = nan(length(time),length(time));
St_Pr(1,1) = 50;
for t = 2:length(time)
St_Pr(1:t-1,t) = St_Pr(1:t-1,t-1)*exp((0.1-0.5*(0.4^2))*dt +
(0.4*sqrt(dt)));
St_Pr(t,t) = St_Pr(t-1,t-1)*exp((0.1-0.5*(0.4^2))*dt - (0.4*sqrt(dt)));
end
Euro_C = nan(length(time),length(time));
Euro_C(:,end) = max(St_Pr(:,end)- 50 , 0 );
for t = (length(time)-1):-1:1
Euro_C(1:t,t) = exp(-(.1)*Delta)*(.5* Euro_C(1:t,t+1) + .5*
Euro_C(2:t+1,t+1));
end
Euro_C(1,1)

Ans = 6.1171

Leap Frog Method


clear all
vals=[100:-2:0];
dt=(5/1200);
time=[0:dt:5/12];
C_m(:,length(time))=max(vals-50*ones(1,length(vals)),0);
C_m(1,:)=(100-50*exp(-.1*((5/12)-time)));
C_m(length(vals),:)=0;
l=length(time)
for j=2:(length(vals)-1)
C_m(j,l-1)=C_m(j,l) + dt*(.5*((.4*vals(j))/2)^2* (C_m(j+1,l)+C_m(j-1,l)2*C_m(j,l)) +.5*.1 * (vals(j)/2) * (-C_m(j+1,l)+C_m(j-1,l)) - .1 * C_m(j,l));
end
for i=(length(time)-2):-1:1
for j=2:(length(vals)-1)
C_m(j,i)=C_m(j,i+2) + 2*dt*(.5*((.4*vals(j))/2)^2* (C_m(j+1,i+1)+C_m(j1,i+1)-2*C_m(j,i+1))+.5*.1* (vals(j)/2) * (-C_m(j+1,i+1)+C_m(j-1,i+1)) - .1 *
C_m(j,i+1));
end
end
C_m

Du Fort Frankel Method


clear all
vals=[100:-2:0];
dt=(5/1200);
time=[0:dt:5/12];
C_m(:,length(time))=max(vals-50*ones(1,length(vals)),0);
C_m(1,:)=(100-50*exp(-.1*((5/12)-time)));
C_m(length(vals),:)=0;
l=length(time)
for j=2:(length(vals)-1)
C_m(j,l-1)=C_m(j,l) + dt*(.5*((.4*vals(j))/2)^2* (C_m(j+1,l)+C_m(j-1,l)2*C_m(j,l)) +.5*.1 * (vals(j)/2) * (-C_m(j+1,l)+C_m(j-1,l)) - .1 * C_m(j,l));
end
for i=(length(time)-2):-1:1
for j=2:(length(vals)-1)
C_m(j,i)=(C_m(j,i+2)+power((.4*vals(j))/2,2)*dt*(C_m(j+1,i+1)C_m(j,i+2)+C_m(j-1,i+1))+vals(j)*.1*(dt/2)*(-C_m(j+1,i+1)...
+C_m(j-1,i+1))-2*dt*.1*C_m(j,i+1))/(1+dt*power((.4*vals(j))/2,2));
end
end
C_m

You might also like