Quantitative finance collector
C++ Matlab VBA/Excel Java Mathematica R/Splus Net Code Site Other
Nov 27

Pricing Parisian Options

Posted by abiao at 17:11 | Code » Matlab | Comments(1) | Reads(10794)
A parisian option pricer was shared at the post before at http://www.mathfinance.cn/parisian-option-pricer/, where the authors Haber, Schoenbucher, and Wilmott values Parisian and Parasian options via explicit finite difference method. (Parisian option is a barrier option but becomes activated only after stock prices have spent a certain continuous, pre-decided time, called a window, above or below the barrier.)

Unfortunately, the authors don't release their codes for us to study, I tried to program according to that paper with theta scheme finite difference, where theta =0, 0.5, 1 refer to explicit, Crank-Nicolson, and implicit finite difference, respectively. Below is a runnable naive Matlab code, please correct me if you find errors, cheers & have a nice weekend.
% set parameter
N = 201; M = 200; s = 10; T = 1;
Tau = 0.1; %barrier window 20 days
sigma = 0.2; r = 0.05; K = 10;
Bar = 12; %barrier
bar = log(Bar);
% time-space grid
R = 3;
h = 2*R/(N+1);
k = T/M;
NoTau = floor(Tau/k);
x = linspace(-R,R,N+2)';

% compute finite difference matrix A
e = ones(N,1);
alphap = -sigma^2/2/h^2 +(sigma^2/2-r)/2/h;
alpham = -sigma^2/2/h^2 -(sigma^2/2-r)/2/h;
beta = sigma^2/h^2+r;
A = spdiags([alpham*e, beta*e, alphap*e], -1:1, N, N);
% compute matrices for the theta scheme
theta = 0.5;
B = speye(N,N) + theta*k*A;
C = speye(N,N) - (1-theta)*k*A;
% compute initial data
u = max(exp(x)-K,0);
u = repmat(u,1,NoTau+1);
inx = find(x>bar,1,'first');
u(:,1) = 0; %up and out when j=tau
f = zeros(N,1);
% start timestepping
for m = 1:M
    lastu = u;
    % compute right hand side
    for j = 2:NoTau+1
        f = C*[lastu(2:inx-2,NoTau+1);lastu(inx-1:end-1,j-1)]; %below using tau=0, above using tau=tau+1;
        u(:,j) = zeros(N+2,1);
        % solve the linear system
        u(2:N+1,j) = B\f;
    u(inx-1,2:NoTau) = u(inx-1,NoTau+1);%reset value at barrier point for parisian
    lastu = u;

Plots of the Parisian option and its delta W.R.T stock prices and barrier Tau.
Open in new window
Open in new window

Can you please add the code to plot the two graphs?
Pages: 1/1 First page 1 Final page
Add a comment
Enable HTML
Enable UBB
Enable Emots
Nickname   Password   Optional
Site URI   Email   [Register]