Asian Option Pricing (MATLAB)
From LiteratePrograms
(Redirected from Asian Option Pricing (Matlab))
Contents |
Here is the MATLAB implementation of the pricing of Asian options from the paper Unified Asian Pricing by Jan Vecer (2002), Risk, Vol. 15, No. 6, 113-116 (some minor changes have been made by Charles-Albert Lehalle).
Use of the pricing function
This function is easy to use, it returns the price of the option and the way to plot some internal results.
<<test_asiancontinuous.m>>= [price, pde_sol] = asiancontinuous(100, 110, .04, .12, .5) pde_sol.plot()
The result of the last line is quite simple (see figure).
MATLAB function for pricing
Main function
<<asiancontinuous.m>>= function [price, pde_sol] = asiancontinuous(S0,K,r,vol,T) % ASIANCONTINUOUS - implementation of Vecer's PDE Method for Asion Option % Pricing, minor modifications by Charles-Albert Lehalle. % use: % [price, pde_sol] = asiancontinuous(100, 110, .04, .12, .5) % pde_sol.plot() %Implementation of Vecer's PDE Method %Vecer, J. (2002): "Unified Asian Pricing", Risk, Vol. 15, No. 6, 113-116 mesh building solve pde price value fprintf( '\n\nPrice of Asian Option is %8.6f\n\n', price); description of PDE initial condition boundary condition plot function end
PDE Solving with MATLAB
The MATLAB pdepe function is used to solve parabolic-elliptic initial-boundary value problems.
<<solve pde>>= m = 0; sol = pdepe(m, @pdef, @pdeic, @pdebc, x, t); pde_sol = struct('x', x, 't', t, 'u', sol(:,:,1), 'plot', @plot_sol);
Mesh building
<<mesh building>>= N = 200; %number of subintervals in space M = 200; %number of subintervals in time %more points -> higher precision, but slower %Xmesh x xmin = -1; xmax = 1; x = linspace(xmin, xmax, N+1); %Tspan t = linspace(0, T, M+1);
Description of PDE
<<description of PDE>>= function [c, f, s] = pdef(x, t, u, DuDx) c = 1; f = 0.5*vol^2*( (1-exp(-r*t))/(r*T) - x )^2*DuDx; s = vol^2*((1-exp(-r*t))/(r*T) - x)*DuDx; end
Initial Condition
<<initial condition>>= function u0 = pdeic(x) u0 = max(x, 0); end
Boundary Condition
<<boundary condition>>= function [pl, ql, pr, qr] = pdebc(xl, ul, xr, ur, t) pl = ul; ql = 0; pr = ur - xr; qr = 0; end
Compute price value
The MATLAB pdeval function is used here.
<<price value>>= %Output of the value of the option X_0 = (1-exp(-r*T))*S0/r/T - exp(-r*T)*K; x0 = X_0/S0; uout = pdeval(m,x,sol(M+1,:),x0); price = uout*S0;
Plot function
You can see here how MATLAB embedded functions can be used to implicitly create some internal variables (here the |pde_sol| variable become implicitly stored into the results of the |asiancontinuous.m| function).
<<plot function>>= function h = plot_sol figure('Color',[0.9412 0.9412 0.9412 ]); surf(pde_sol.x, pde_sol.t, pde_sol.u, 'edgecolor', 'none'); axis([min(pde_sol.x) max(pde_sol.x) min(pde_sol.t) max(pde_sol.t) min(min(pde_sol.u)) max(max(pde_sol.u))]); xlabel('X');ylabel('t'); end