rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
eop_beta.m
Go to the documentation of this file.
1 function [model, beta_build] = eop_beta(model)
2 %[model, beta_build] = eop_beta(model)
3 %
4 % function computing the inf-sup constant of the PG-BLF-Matrix of the
5 % european_option_pricing_model for each mu in a training set. Output is
6 % the minimum of those inf-sup constants - the empirical inf-sup constant.
7 % Uses the huge sparse matrix and therefor needs a lot of RAM. Could also
8 % be done with AFUN for eigs but this approach was sufficient for one run
9 % to get an empirical constant.
10 
11 % Dominik Garmatter 17.07.2012
12 
13 model_data = gen_model_data(model);
14 K = model.get_inner_product_matrix(model_data);
15 % get the components
16 model.decomp_mode = 1;
17 [L_I_comp, L_E_comp] = model.operators_ptr(model, model_data);
18 % M*H is the size of the PG-BLF-Matrix
19 H = size(L_I_comp{1},1);
20 M = model.nt+1;
21 % build Mtrain as a first parameter and many more random parameters
22 build1 = zeros(size(model.mu_ranges,2),1);
23 build2 = zeros(size(model.mu_ranges,2),1);
24 for i = 1:size(model.mu_ranges,2)
25  build1(i,1) = model.mu_ranges{i}(1);
26  build2(i,1) = model.mu_ranges{i}(2);
27 end
28 Mtrain1 = [0.05,0.4,2,0.5]';
29 Mtrain2 = unifrnd(repmat(build1,1,50),repmat(build2,1,50));
30 Mtrain = [Mtrain1, Mtrain2];
31 
32 beta_build = zeros(size(Mtrain,2),1);
33 beta_build2 = zeros(size(Mtrain,2),1);
34 
35 kron_1 = sparse(diag([1;zeros(model.nt,1)]));
36 kron_2 = sparse(diag([0;ones(model.nt,1)]));
37 kron_3 = sparse(diag(-ones(model.nt,1),-1));
38 
39 for k = 1:size(Mtrain,2)
40  disp(k);
41  model = model.set_mu(model,Mtrain(:,k));
42  % compute the current coefficients
43  old_decomp_mode = model.decomp_mode;
44  model.decomp_mode = 2;
45  [L_I_coeffs, L_E_coeffs] = model.operators_ptr(model);
46  model.decomp_mode = old_decomp_mode;
47  % and assemble the matrices
48  L_I = lincomb_sequence(L_I_comp, L_I_coeffs);
49  L_E = lincomb_sequence(L_E_comp, L_E_coeffs);
50  % compute the smallest eigenvalue of B'*K*B and take the sqareroot of it
51  Matrix = kron(kron_1, speye(H)) + kron(kron_2, L_I) + kron(kron_3, L_E);
52  try %first try to solve the EWP with default tolerance eps
53  beta_build(k) = sqrt(eigs(Matrix'*kron(speye(M),K)*Matrix,1,'SM'));
54  catch err %if no eigenvalues to sufficient accuracy was found reduce the tolerance and try it again
55  if (strcmp(err.identifier,'MATLAB:eigs:ARPACKroutineErrorMinus14'))
56  opts.tol = 1e-14;
57  no_solution = 1;
58  while no_solution
59  disp(['I reduced the tolerance of an eigenvalueproblem to ' mat2str(opts.tol)]);
60  try
61  beta_build2(k) = sqrt(eigs(Matrix'*kron(speye(M),K)*Matrix,1,'SM',opts));
62  no_solution = 0; %end when there is no error
63  catch err2 %when it still fails reduce the tolerance and try again!
64  no_solution = 1;
65  if (strcmp(err2.identifier,'MATLAB:eigs:ARPACKroutineErrorMinus14'))
66  opts.tol = 100 * opts.tol;
67  end
68  if opts.tol > 1e-3 %if the tolerance is reduced until a certain value, give an error since the tolerance is too soft!
69  error(['I reduced the tolerance to ' mat2str(opts.tol) ' but I still could not find a solution. Reconsider your Problem']);
70  end
71  end
72  end
73  else %if there is another error rethrow
74  rethrow(err)
75  end
76  end
77 end
78 
79 model.beta_LB = min(beta_build); % take the minimum
function model = european_option_pricing_model(params)
model = european_option_pricing_model(params)
function [ model , beta_build ] = eop_beta(model)
[model, beta_build] = eop_beta(model)
Definition: eop_beta.m:17