Download code

Jump to: navigation, search

Back to Asian_Option_Pricing_(MATLAB)

Download for Windows: zip

Download for UNIX: zip, tar.gz, tar.bz2

asiancontinuous.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Asian_Option_Pricing_(MATLAB)?oldid=7915
14 
15 function [price, pde_sol] = asiancontinuous(S0,K,r,vol,T)
16 % ASIANCONTINUOUS - implementation of Vecer's PDE Method for Asion Option
17 % Pricing, minor modifications by Charles-Albert Lehalle.
18 % use:
19 % [price, pde_sol] = asiancontinuous(100, 110, .04, .12, .5)
20 % pde_sol.plot()
21 
22 %Implementation of Vecer's PDE Method
23 %Vecer, J. (2002): "Unified Asian Pricing",  Risk, Vol. 15, No. 6, 113-116 
24 
25 N = 200;       %number of subintervals in space 
26 M = 200;       %number of subintervals in time
27 
28 %more points -> higher precision, but slower
29 
30 %Xmesh  x
31 xmin = -1;
32 xmax = 1;
33 x = linspace(xmin, xmax, N+1);
34 
35 %Tspan
36 t = linspace(0, T, M+1);
37 
38 m = 0;
39 sol = pdepe(m, @pdef, @pdeic, @pdebc, x, t);
40 pde_sol = struct('x', x, 't', t, 'u', sol(:,:,1), 'plot', @plot_sol);
41 
42 %Output of the value of the option
43 X_0 = (1-exp(-r*T))*S0/r/T - exp(-r*T)*K;
44 x0 = X_0/S0;
45 
46 uout = pdeval(m,x,sol(M+1,:),x0);
47 price = uout*S0;
48 
49 fprintf( '\n\nPrice of Asian Option is %8.6f\n\n', price);
50 
51 function [c, f, s] = pdef(x, t, u, DuDx)
52 c = 1;
53 
54     f = 0.5*vol^2*( (1-exp(-r*t))/(r*T) - x )^2*DuDx;
55     s = vol^2*((1-exp(-r*t))/(r*T) - x)*DuDx;
56 
57 end
58 
59 function u0 = pdeic(x)
60 u0 = max(x, 0);
61 end
62 
63 function [pl, ql, pr, qr] = pdebc(xl, ul, xr, ur, t)
64 pl = ul;
65 ql = 0;
66 pr = ur - xr;
67 qr = 0;
68 end
69 
70 function h = plot_sol
71 figure('Color',[0.9412 0.9412 0.9412 ]);
72 surf(pde_sol.x, pde_sol.t, pde_sol.u, 'edgecolor', 'none');
73 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))]);
74 xlabel('X');ylabel('t');
75 end
76 
77 end


hijacker
hijacker
hijacker
hijacker

test_asiancontinuous.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Asian_Option_Pricing_(MATLAB)?oldid=7915
14 
15 [price, pde_sol] = asiancontinuous(100, 110, .04, .12, .5)
16 pde_sol.plot()
17 


hijacker
hijacker
hijacker
hijacker