Download code
From LiteratePrograms
Back to Asian_Option_Pricing_(MATLAB)
Download for Windows: zip
Download for UNIX: zip, tar.gz, tar.bz2
asiancontinuous.m
1 % Copyright (c) 2008 the authors listed at the following URL, and/or 2 % the authors of referenced articles or incorporated external code: 3 % http://en.literateprograms.org/Asian_Option_Pricing_(MATLAB)?action=history&offset=20061105065258 4 % 5 % Permission is hereby granted, free of charge, to any person obtaining 6 % a copy of this software and associated documentation files (the 7 % "Software"), to deal in the Software without restriction, including 8 % without limitation the rights to use, copy, modify, merge, publish, 9 % distribute, sublicense, and/or sell copies of the Software, and to 10 % permit persons to whom the Software is furnished to do so, subject to 11 % the following conditions: 12 % 13 % The above copyright notice and this permission notice shall be 14 % included in all copies or substantial portions of the Software. 15 % 16 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 % 24 % Retrieved from: http://en.literateprograms.org/Asian_Option_Pricing_(MATLAB)?oldid=7915 25 26 function [price, pde_sol] = asiancontinuous(S0,K,r,vol,T) 27 % ASIANCONTINUOUS - implementation of Vecer's PDE Method for Asion Option 28 % Pricing, minor modifications by Charles-Albert Lehalle. 29 % use: 30 % [price, pde_sol] = asiancontinuous(100, 110, .04, .12, .5) 31 % pde_sol.plot() 32 33 %Implementation of Vecer's PDE Method 34 %Vecer, J. (2002): "Unified Asian Pricing", Risk, Vol. 15, No. 6, 113-116 35 36 N = 200; %number of subintervals in space 37 M = 200; %number of subintervals in time 38 39 %more points -> higher precision, but slower 40 41 %Xmesh x 42 xmin = -1; 43 xmax = 1; 44 x = linspace(xmin, xmax, N+1); 45 46 %Tspan 47 t = linspace(0, T, M+1); 48 49 50 m = 0; 51 sol = pdepe(m, @pdef, @pdeic, @pdebc, x, t); 52 pde_sol = struct('x', x, 't', t, 'u', sol(:,:,1), 'plot', @plot_sol); 53 54 55 %Output of the value of the option 56 X_0 = (1-exp(-r*T))*S0/r/T - exp(-r*T)*K; 57 x0 = X_0/S0; 58 59 uout = pdeval(m,x,sol(M+1,:),x0); 60 price = uout*S0; 61 62 63 fprintf( '\n\nPrice of Asian Option is %8.6f\n\n', price); 64 65 function [c, f, s] = pdef(x, t, u, DuDx) 66 c = 1; 67 68 f = 0.5*vol^2*( (1-exp(-r*t))/(r*T) - x )^2*DuDx; 69 s = vol^2*((1-exp(-r*t))/(r*T) - x)*DuDx; 70 71 end 72 73 74 function u0 = pdeic(x) 75 u0 = max(x, 0); 76 end 77 78 79 function [pl, ql, pr, qr] = pdebc(xl, ul, xr, ur, t) 80 pl = ul; 81 ql = 0; 82 pr = ur - xr; 83 qr = 0; 84 end 85 86 87 function h = plot_sol 88 figure('Color',[0.9412 0.9412 0.9412 ]); 89 surf(pde_sol.x, pde_sol.t, pde_sol.u, 'edgecolor', 'none'); 90 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))]); 91 xlabel('X');ylabel('t'); 92 end 93 94 95 end 96
test_asiancontinuous.m
1 % Copyright (c) 2008 the authors listed at the following URL, and/or 2 % the authors of referenced articles or incorporated external code: 3 % http://en.literateprograms.org/Asian_Option_Pricing_(MATLAB)?action=history&offset=20061105065258 4 % 5 % Permission is hereby granted, free of charge, to any person obtaining 6 % a copy of this software and associated documentation files (the 7 % "Software"), to deal in the Software without restriction, including 8 % without limitation the rights to use, copy, modify, merge, publish, 9 % distribute, sublicense, and/or sell copies of the Software, and to 10 % permit persons to whom the Software is furnished to do so, subject to 11 % the following conditions: 12 % 13 % The above copyright notice and this permission notice shall be 14 % included in all copies or substantial portions of the Software. 15 % 16 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 % 24 % Retrieved from: http://en.literateprograms.org/Asian_Option_Pricing_(MATLAB)?oldid=7915 25 26 [price, pde_sol] = asiancontinuous(100, 110, .04, .12, .5) 27 pde_sol.plot() 28
