4 %
this function computes detailed simulations on a coarse grid and on a
5 % fine grid with h_new = 1/2*h_old. Then the coarse simulation is projected
6 % on the fine grid an the error between both is computed.
8 % On the one side you want to see a convergence in that error and on the
9 % other side you can compute the EOC.
11 % required fields of params:
12 % params.number_of_refinementsteps - numer of refinement steps
13 % optional fields of params:
14 % params.S1bar - initial grid size in x-direction
15 % params.S2bar - initial grid size in y-direction
16 % params.h1 - initial gridrefinement in x-direction
17 % params.h2 - initial gridrefinement in y-direction
20 % grid_error: a sequence of the computed error in each refinement step
21 % h_sequence: the sequence of gridrefinement-levels
22 % EOC: the sequence of the EOC (exponential order of convergence)
24 % Dominik Garmatter 29.05 2012
27 if ~isfield(params,
'number_of_refinementsteps')
28 params.number_of_refinementsteps = 4;
30 if ~isfield(params,'S1bar')
31 params.S1bar = model.S1bar;
33 if ~isfield(params,'S2bar')
34 params.S1bar = model.S2bar;
36 if ~isfield(params,'h1')
37 params.S1bar = model.h1;
39 if ~isfield(params,'h2')
40 params.S1bar = model.h2;
43 %detailed_simulation on the coarse grid
44 sim_data = detailed_simulation(model, model_data);
45 sim_data = sim_data.U;
47 % set Z the number of refinement steps and initialise the error vector
48 Z = params.number_of_refinementsteps;
49 grid_error = zeros(1,Z);
51 h1_sequence = zeros(1,Z+1);
52 h1_sequence(1) = model.h1;
53 h2_sequence = zeros(1,Z+1);
54 h2_sequence(1) = model.h2;
58 % refinement of h1, h2 via h_new = 1/2*h_old
59 params.h1 = 1/2*params.h1;
60 params.h2 = 1/2*params.h2;
61 % refined model and model_data
63 refined_model_data = gen_model_data(refined_model);
64 % refined detailed_simulation
65 refined_sim_data = detailed_simulation(refined_model, refined_model_data);
66 refined_sim_data = refined_sim_data.U;
67 projected_sim_data = zeros(size(refined_sim_data));
69 %% Projection of the old data on the refined grid: ( o known values on the coarse grid; . being the arithmetic average of o on the refined grid)
70 % step 1 step 2 step 3
71 % o o o o o o o . o o . o o . o
72 % ----> ----> ----> . . .
73 % o o o o o o o . o o . o o . o
76 for column = 1:size(projected_sim_data,2)
78 % projection of the known values on the refined grid, i.e. step 1
79 projected_sim_data(2*(k-1)*refined_model.N1+1:2:(2*k-1)*refined_model.N1,column) = ...
80 sim_data((k-1)*model.N1+1:k*model.N1,column);
81 % step 2: computing the arithemtic average in the new gridpoints with the projected data
82 projected_sim_data(2*(k-1)*refined_model.N1+2:2:(2*k-1)*refined_model.N1-1,column) = ...
83 1/2*(projected_sim_data(2*(k-1)*refined_model.N1+1:2:(2*k-1)*refined_model.N1-2,column) + projected_sim_data(2*(k-1)*refined_model.N1+3:2:(2*k-1)*refined_model.N1,column));
86 for i = 1:refined_model.N1
87 projected_sim_data(i+refined_model.N1:2*refined_model.N1:refined_model.N1*(refined_model.N2-1),column) = ...
88 1/2*(projected_sim_data(i:2*refined_model.N1:refined_model.N1*(refined_model.N2-2),column) +...
89 projected_sim_data(i+2*refined_model.N1:2*refined_model.N1:refined_model.N1*refined_model.N2,column));
93 % computing the error using the discrete L2-norm
94 grid_error_build =
eop_fd_norm(projected_sim_data, refined_sim_data, refined_model_data.grid);
95 grid_error(1,count) = max(grid_error_build);
97 h1_sequence(count+1) = params.h1;
98 h2_sequence(count+1) = params.h2;
100 % set the old fine model as the new coarse model
101 model = refined_model;
102 % and the old refined data become the new coarse data
103 sim_data = refined_sim_data;
107 % build the h-sequence
108 h_sequence = [h1_sequence, h2_sequence];
112 EOC_unrounded = (log(grid_error(i))-log(grid_error(i+1)))/log(2);
113 EOC(i) = round(EOC_unrounded*1000)/1000;
function model = european_option_pricing_model(params)
model = european_option_pricing_model(params)
function norm = eop_fd_norm(fd_function1, fd_function2,gridbase grid, unused1)
norm = eop_fd_norm(fd_function1, fd_function2, grid, ~)
function [ grid_error , h_sequence , EOC ] = eop_gridconvergence(model, model_data, params)
[error, h_sequence, EOC] = eop_gridconvergence(model, model_data, params)