I need help to change this code

Hello; Could anyone help me to change this code from American to European? This code for " Front -Tracking Algorithm for American call simulation"
% Runge-Kutta for free boundary and value
%define parameters
r=0.1; % Interest rate
sigma=0.4; % Volatility of the underlying
d=0.08; % Continuous dividend yield
M=150; % Number of time points
N=20; % Number of share price points
Smax=23; % Maximum share price considered
Smin=1; % Minimum share price considered
T=0.5; % Maturation (expiry)of contract
E=10; % Exercise price of the underlying
ds=(Smax-Smin)/N; % Price step
dt=(T/M);
% Initialize
vam(1:N,1:M) = 0.0;
% initial boundary condition
vam(1:N,1)=max((Smin+(0:N-1)*ds-E),zeros(size(1:N)))';
% Boundary conditions
vam(1,2:M)=zeros(M-1,1)';
vam(N,2:M)=((N-1)*ds+Smin)*exp(-d*(1:M-1)*dt)-E*exp(-r*(1:M-1)*dt);
vv = vam;
% Determining the matrix coeficients of the explicit algorithm
k1=0.5*dt*(sigma*sigma*(1:N-2).*(1:N-2)-(r-d)*(1:N-2))';
k2=1-dt*(sigma*sigma*(1:N-2).*(1:N-2)+r)';
k3=0.5*dt*(sigma*sigma*(1:N-2).*(1:N-2)+(r-d)*(1:N-2))';
% Implementing the explicit algorithm
for i=2:M
k11(i) = dt*(vv(i));
k22(i) = dt*(vv(i) + 0.5*k11(i));
k33(i) = dt*(vv(i) + 0.5*k22(i));
k44(i) = dt*(vv(i) + k33(i));
% size( vv(2:N-1,i))
vv(2:N-1,i)= max(vv(i) + (1/6)*(k11(i) + 2*k22(i) + 2*k33(i) + k44(i)));
% Checks if early exercise is better for the American Option
vam(2:N-1,i)=max(k2.*vam(2:N-1,i-1)+k3.*vam(3:N,i-1)+k1.*vam(1:N-2,i-1),vam(2:N-1,1));
end
vam=fliplr(vam);
aa = vam(1:(N-1),1);
aa(2:16)
plot(Smin+ds*(0:(N-2)),vam(1:(N-1),1)','r-');
xlabel('stock price');
ylabel('V(C)');
title('4Order Runge-Kutta for boundary ');

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangePrice and Analyze Financial Instruments についてさらに検索

タグ

質問済み:

2016 年 2 月 5 日

編集済み:

2016 年 2 月 5 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by