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. Any suggestion on 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=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
xi=x(i);             % spot price values
yi=max(K-xi,0);      %  Put value 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
plot(xi,yi,'-o');    % plot for option values vs spot price

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.