필터 지우기
필터 지우기

Spectral Methods in Matlab

조회 수: 7 (최근 30일)
A Basu
A Basu 2017년 11월 2일
Hi, I am trying to implement the spectral analysis on European Put Options. My code is designed to change the number of nodes(basis functions) accordingly but the boundary condition and thus the range of the plots are dependent on the number of nodes used in the program. I am trying to have the same range and the boundary conditions independent of the N (nodes). Below is a current implementation of my code. Please suggest me how should I make the boundary conditions independent of the N.
K=40; % Strike price
v=0.02; % volatility
r=0.03; % rate
T=1; % time to maturity
nt=15; % time intervals
N=30; % number of nodes
M=3; % number of derivatives required
b=1; % scaling parameter in Laguerre differentiation
% The function [x, DM] = lagdif(N, M, b) computes the
% differentiation matrices D1, D2, ..., DM on Laguerre points.
%
[x, DM] = laguerredif(N, M, b);
D1=DM(:,:,1); % 1-st derivative matrix
D2=DM(:,:,2); % 2-nd derivative matrix
i=2:N-1;
I=speye(N); % unit matrix
X=spdiags(x,0,N,N); % matrix with x values
X2=X.^2; % x^2 matrix
H=r*I-r*X*D1-0.5*v*X2*D2; % H operator from Black-Shcholes equation
A=H(i,i);
xi=x(i); % price values
yi=max(K-xi,0); % Put for European
h=-T/nt; % time step
t=T:h:0; % backward scheme for time (from T to 0)
b=H(i,N)*K; % Boundary condition
[l,u]=lu(I(i,i)-0.5*h*A); % LU decomposition
for it=2:length(t)
% solving Matrix equation using LU decomposition
% on every time step
b1=H(i,1)*K*exp(-r*(T-t(it)));
yi=u\(l\(yi+0.5*h*(A*yi+b+b1)));
b=b1;
end
plot(xi,yi,'-o');

답변 (0개)

카테고리

Help CenterFile Exchange에서 Financial Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by