rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
european_option_pricing_model.m
Go to the documentation of this file.
1 function model = european_option_pricing_model(params)
2 %model = european_option_pricing_model(params)
3 %
4 % The model of my diploma thesis for the solution of the two-dimensional
5 % Black-Scholes-Equation.
6 %
7 % See Chapter 2.3 and 4.1 for a precise description of the problem.
8 %
9 % Dominik Garmatter 20.08 2012
10 
11 %% GENERAL SETTINGS
12 
13 model.rb_problem_type = 'lin_evol';
14 model.verbose = 5;
15 model.affinely_decomposed = true;
16 model.compute_output_functional = 0;
17 model.debug = 0;
18 
19 %% MU RELATED
20 
21 model.mu_names = {'r','rho','sigma1','sigma2'}; % r = the interest rate, roh the correlation coefficient, sigma 1 und 2 the volatilities
22 model.mu_ranges = {[1e-10 0.3],[-0.9 0.9],[1e-10 2],[1e-10 2]}; % the parameter space
23 % some initial values
24 model.r = 0.05;
25 model.rho = 0.4;
26 model.sigma1 = 0.5;
27 model.sigma2 = 0.5;
28 % functions to set or get a mu
29 model.set_mu = @set_mu_default;
30 model.get_mu = @get_mu_default;
31 
32 %% TIME RELATED
33 
34 model.T = 1; % date of maturity
35 model.nt = 20; % number of timeintervals
36 model.deltaT = model.T/model.nt;
37 model.data_const_in_time = 1;
38 model.set_time = @set_time_default;
39 
40 %% GRID RELATED SETTINGS
41 
42 model.gridtype = 'rectgrid';
43 
44 if nargin == 0
45  params = [];
46 end
47 
48 % grid construction by using a params-structure, which can be given as an
49 % input to the model. The structure contains the following fields:
50 %- S1bar -> size of the grid in S1-direction (x-direction)
51 %- S2bar -> size of the grid in S2-direction (y-direction)
52 %- h1 -> step-width in S1-direction
53 %- h2 -> step-width in S2-direction
54 %- K -> the Strike (not grid relevant and normally choosen as (params.S1bar + params.S2bar)/4)
55 
56 if ~isfield(params,'S1bar')
57  params.S1bar = 70;
58 end
59 params.xrange = [0,params.S1bar];
60 
61 if ~isfield(params,'S2bar')
62  params.S2bar = 70;
63 end
64 params.yrange = [0,params.S2bar];
65 
66 if ~isfield(params,'h1')
67  params.h1 = 0.5;
68 end
69 params.xnumintervals = params.S1bar/params.h1;
70 
71 if ~isfield(params,'h2')
72  params.h2 = 0.5;
73 end
74 params.ynumintervals = params.S2bar/params.h2;
75 
76 if ~isfield(params,'K')
77  params.K = (params.S1bar + params.S2bar)/4;
78 end
79 
80 model = structcpy(model,params);
81 model.N1 = model.xnumintervals + 1; % number of gridpoints in S1-direction
82 model.N2 = model.ynumintervals + 1; % number of gridpoints in S2-direction
83 
84 %% RB RELATED
85 
86 model.RB_generation_mode = 'greedy_uniform_fixed';
87 model.RB_extension_algorithm = @RB_extension_PCA_fixspace;
88 model.set_rb_in_detailed_data = @(detailed_data,RB) ...
89  setfield(detailed_data, 'RB', RB);
90 model.get_rb_from_detailed_data = @(detailed_data) detailed_data.RB;
91 model.get_rb_size = @get_rb_size_default;
92 model.get_dofs_from_sim_data = @(sim_data) sim_data.U;
93 model.rb_init_values = @rb_init_values_primal_dual; % includes primal/dual difference
94 model.rb_init_data_basis = @RB_init_data_basis;
95 model.RB_numintervals = 5*ones(length(model.mu_ranges),1); % fineness of Mtrain
96 
97 model.RB_error_indicator = 'estimator';
98 % fields required in case of model.RB_error_indicator = 'error'
99 model.error_algorithm = @eop_fd_norm; % discrete L2-norm
100 model.RB_detailed_train_savepath = 'detailed_sim_from_basisgen';
102 % fields required in case of model.RB_error_indicator = 'estimator'
103 model.error_norm = 'l2'; % optional 'energy'
104 model.get_estimator_from_sim_data = @(sim_data) sim_data.Delta(end);
105 
106 % RB stopping conditions
107 model.RB_stop_epsilon = eps;
108 model.RB_stop_Nmax = 100;
109 model.RB_stop_timeout = 3600*3600;
110 % stopping conditions for the dual RB
111 model.dual_RB_stop_epsilon = eps;
112 model.dual_RB_stop_Nmax = 100;
113 model.dual_RB_stop_timeout = 3600*3600;
114 
115 % detailed_data get saved every time - this specifies the filename they get saved in
116 model.detailedfname = 'eop_detailed_data';
117 
118 % following fields get removed temporary so filecaching during the basisgeneration works
119 model.filecache_ignore_fields_in_model = {'N','Nmax'};
120 model.filecache_ignore_fields_in_detailed_data = {'RB_info'};
121 
122 
123 %% VARIOUS
124 
125 model.gen_model_data = @lin_evol_gen_model_data; % generating the mass matrix and the grid
126 model.mass_matrix = @eop_mass_matrix;
127 model.inner_product = @(model, model_data, coeffvector1, coeffvector2)... % this is the discrete L2-inner-product:
128  coeffvector1'*model_data.W*coeffvector2; %<u,v> = 1/H \sum_{x\in G}{u(x)*v(x)}, with G being the grid and H = #G
129 model.get_inner_product_matrix = @(detailed_data) detailed_data.W;
130 model.detailed_simulation = @lin_evol_detailed_simulation_primal_dual; % includes primal/dual difference
131 model.gen_detailed_data = @lin_evol_gen_detailed_data;
132 model.orthonormalize = @model_orthonormalize_gram_schmidt;
133 model.gen_reduced_data = @lin_evol_gen_reduced_data_primal_dual; % includes primal/dual difference
134 model.rb_operators = @lin_evol_rb_operators_primal_dual; % includes primal/dual difference
135 model.rb_simulation = @lin_evol_rb_simulation_primal_dual; % includes primal/dual difference
136 model.rb_reconstruction = @rb_reconstruction_default;
137 model.reduced_data_subset = @lin_evol_reduced_data_subset;
138 
139 %% FD & Functionals
140 
141 model.init_values_algorithm = @eop_init_values; % includes 2 different functions
142 model.init_value_function = 'standard'; % see "eop_init_values"
143 model.operators_ptr = @eop_fd_operators; % these compute L_I,L_E and b
144 model.operators_output = @eop_fd_functionals; % includes various output functionals
145 model.name_output_functional = 'average price'; % see "eop_fd_functionals"
146 
147 % specify G_0 the subgrid on which the functionals are evaluated
148 model.functional_subset_S1 = model.xrange;
149 model.functional_subset_S2 = model.yrange;
150 
151 %% PLOT RELATED
152 
153 model.plot = @plot_vertex_data;
154 model.plot_sim_data = @lin_evol_plot_sim_data;
155 
156 %% NORM BOUNDS (for error estimators)
157 
158 % for the empiric constants use eop_C_L_I and eop_beta. For the SCM
159 % (model.use_scm = 1) see scm_offline and lin_evol_gen_reduced_data_primal_dual.
160 % But right now SCM is not working -> use the empiric constants.
161 model.L_I_inv_norm_bound = 1.000431891324076; % empiric constant for standard settings. Use eop_C_L_I to compute an empiric constant for other settings.
162 model.L_E_norm_bound = 1; % L_E = Id
163 model.constant_LB = 6.448207658122034e-005; % empiric LowerBound for standard settings. Use eop_beta to compute an empiric LowerBound for other settings.
164 
165 end
166 
167 
168 function W = eop_mass_matrix(~,grid,~)
169 % function generating the mass matrix to the discrete Basis
170 % \psi_i(x)= 1 , if x=x_i , 0 else
171 % and the discrete inner product <u,v> = 1/H \sum_{x\in G}{u(x)*v(x)},
172 % with G being the grid and H = #G.
173 
174 W = speye(grid.nvertices)*1/grid.nvertices;
175 end
176 
function [ RBext , dummy ] = RB_extension_PCA_fixspace(model, detailed_data)
function computing a RB basis extension for given parameters by the POD-Greedy algorithm.
function a0 = rb_init_values_primal_dual(model, detailed_data)
a0 = rb_init_values_primal_dual(model, detailed_data)
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, ~)
Definition: eop_fd_norm.m:17
function save_detailed_simulations(model, model_data, M, savepath)
perform loop over detailed simulations and save results or check consistency with existing saved resu...
function s1 = structcpy(s1, s2)
copies the fields of structure s2 into structure s1. If the field to be copied does not exist in s1 y...
Definition: structcpy.m:17