time | Calls | line |
---|
| | 7 | function [mt_ev_condi_z_max, mt_ev_condi_z_max_idx, mt_ev_condi_z_max_kp, mt_ev_condi_z_max_bp] = ff_ipwkbz_evf(varargin)
|
| | 8 | %% FF_IPWKBZ_EVF solves the k' vs b' problem given aggregate savings
|
| | 9 | % This function follows the structure set up here:
|
| | 10 | % <https://fanwangecon.github.io/CodeDynaAsset/m_akz/solve/html/ff_wkz_evf.html
|
| | 11 | % ff_wkz_evf> but now we solve the second stage with percentage choice grid
|
| | 12 | %
|
| | 13 | % We solve along a vector of w_n vector, that is an interpolation vector,
|
| | 14 | % not a vector of actual w choices picked in the first stage. k' choices
|
| | 15 | % are in terms of percentages. Compared to ff_wkz_evf where we only had an
|
| | 16 | % upper triangle of choices, now we have a full matrix of percentage
|
| | 17 | % choices.
|
| | 18 | %
|
| | 19 | % @param mt_val matrix state_n I^2 by shock_n. This is the value
|
| | 20 | % matrix each row is a feasible reachable state given the choice
|
| | 21 | % vectors/matrix and each column is a shock state.
|
| | 22 | %
|
| | 23 | % @param param_map container parameter container
|
| | 24 | %
|
| | 25 | % @param support_map container support container
|
| | 26 | %
|
| | 27 | % @param armt_map container container with states, choices and shocks
|
| | 28 | % grids that are inputs for grid based solution algorithm
|
| | 29 | %
|
| | 30 | % @return mt_ev_condi_z_max matrix choice_w_n by shock_n
|
| | 31 | % max_{k'}(E(V(coh(k',b'=w-k'),z'|z,w)) conditional on z and w, at the
|
| | 32 | % optimal k' choice (w=k'+b') what is the expected utility? This is the
|
| | 33 | % value result from the 2nd stage problem. Note the result integrates over
|
| | 34 | % z'.
|
| | 35 | %
|
| | 36 | % @return mt_ev_condi_z_max_idx matrix choice_w_n by shock_n this is the
|
| | 37 | % argmax from max_{k'}(E(V(coh(k',b'=w-k'),z'|z,w)). Given the vector of k'
|
| | 38 | % choices, which index maximized conditional on z and w integrating over
|
| | 39 | % z'/
|
| | 40 | %
|
| | 41 | % @return mt_ev_condi_z_max_kp matrix choice_w_level_n by shock_n the k'
|
| | 42 | % choice at max_{k'}(E(V(coh(k',b'=w-k'),z'|z,w))
|
| | 43 | %
|
| | 44 | % @return mt_ev_condi_z_max_bp matrix choice_w_n by shock_n the b'=w-k'
|
| | 45 | % choice at max_{k'}(E(V(coh(k',b'=w-k'),z'|z,w))
|
| | 46 | %
|
| | 47 | % @example
|
| | 48 | %
|
| | 49 | % @include
|
| | 50 | %
|
| | 51 | % * <https://github.com/FanWangEcon/CodeDynaAsset/blob/master/m_ipwkbz/paramfunc/ffs_ipwkbz_set_default_param.m ffs_ipwkbz_set_default_param>
|
| | 52 | % * <https://github.com/FanWangEcon/CodeDynaAsset/blob/master/m_ipwkbz/paramfunc/ffs_ipwkbz_get_funcgrid.m ffs_ipwkbz_get_funcgrid>
|
| | 53 | %
|
| | 54 |
|
| | 55 | %% Default
|
| | 56 |
|
< 0.001 | 129 | 57 | params_len = length(varargin);
|
< 0.001 | 129 | 58 | bl_input_override = 0;
|
< 0.001 | 129 | 59 | if (params_len == 5)
|
< 0.001 | 129 | 60 | bl_input_override = varargin{5};
|
< 0.001 | 129 | 61 | end
|
< 0.001 | 129 | 62 | if (bl_input_override)
|
| | 63 | % override when called from outside
|
0.003 | 129 | 64 | [mt_val, param_map, support_map, armt_map, ~] = varargin{:};
|
| | 65 | else
|
| | 66 | clear all;
|
| | 67 | close all;
|
| | 68 |
|
| | 69 | % Not default parameters, but parameters that generate defaults
|
| | 70 | [param_map, support_map] = ffs_ipwkbz_set_default_param();
|
| | 71 |
|
| | 72 | support_map('bl_graph_evf') = true;
|
| | 73 | bl_display_evf = true;
|
| | 74 | support_map('bl_display_evf') = bl_display_evf;
|
| | 75 |
|
| | 76 | param_map('it_ak_perc_n') = 250;
|
| | 77 | param_map('fl_w_interp_grid_gap') = (param_map('fl_w_max')-param_map('fl_b_bd'))/param_map('it_ak_perc_n');
|
| | 78 |
|
| | 79 | [armt_map, func_map] = ffs_ipwkbz_get_funcgrid(param_map, support_map); % 1 for override
|
| | 80 |
|
| | 81 | % Generating Defaults
|
| | 82 | params_group = values(armt_map, {'ar_a_meshk', 'ar_k_mesha', 'ar_z'});
|
| | 83 | [ar_a_meshk, ar_k_mesha, ar_z] = params_group{:};
|
| | 84 | params_group = values(func_map, {'f_util_standin', 'f_coh'});
|
| | 85 | [f_util_standin, f_coh] = params_group{:};
|
| | 86 | mt_val = f_util_standin(ar_z, ar_a_meshk, ar_k_mesha);
|
| | 87 | mt_coh = f_coh(ar_z, ar_a_meshk, ar_k_mesha);
|
| | 88 |
|
< 0.001 | 129 | 89 | end
|
| | 90 |
|
| | 91 | %% Parse Parameters
|
0.003 | 129 | 92 | params_group = values(armt_map, {'mt_z_trans', 'ar_z',...
|
| | 93 | 'ar_w_level', 'ar_k_mesha', 'ar_a_meshk', 'mt_k'});
|
0.002 | 129 | 94 | [mt_z_trans, ar_z, ar_w_level, ...
|
| 129 | 95 | ar_k_mesha, ar_a_meshk, mt_k] = params_group{:};
|
0.002 | 129 | 96 | params_group = values(param_map, {'it_z_n', 'fl_nan_replace', 'fl_b_bd'});
|
0.001 | 129 | 97 | [it_z_n, fl_nan_replace, fl_b_bd] = params_group{:};
|
0.002 | 129 | 98 | params_group = values(support_map, {'bl_graph_onebyones','bl_display_evf', 'bl_graph_evf'});
|
0.001 | 129 | 99 | [bl_graph_onebyones, bl_display_evf, bl_graph_evf] = params_group{:};
|
0.002 | 129 | 100 | params_group = values(support_map, {'bl_img_save', 'st_img_path', 'st_img_prefix', 'st_img_name_main', 'st_img_suffix'});
|
0.002 | 129 | 101 | [bl_img_save, st_img_path, st_img_prefix, st_img_name_main, st_img_suffix] = params_group{:};
|
0.002 | 129 | 102 | params_group = values(support_map, {'it_display_summmat_rowmax', 'it_display_summmat_colmax'});
|
0.001 | 129 | 103 | [it_display_summmat_rowmax, it_display_summmat_colmax] = params_group{:};
|
| | 104 |
|
| | 105 | % append function name
|
< 0.001 | 129 | 106 | st_func_name = 'ff_ipwkbz_evf';
|
0.001 | 129 | 107 | st_img_name_main = [st_func_name st_img_name_main];
|
| | 108 |
|
| | 109 | %% Integrate *E(V(coh(k',b'), z')|z, w)*
|
| | 110 | % Each column for a different state z, each value *E(V(coh,z')|z)* integrated already
|
| | 111 | % Here, each column is a current z, more to right higher EV
|
| | 112 | % dim(mt_ev_condi_z): *Q by M*
|
| | 113 | % Note that: mt_ev_condi_z = mt_val*mt_z_trans' is a mistake, that would be
|
| | 114 | % what we do in the
|
| | 115 | % <https://fanwangecon.github.io/CodeDynaAsset/m_ipwkbz/paramfunc/html/ffs_ipwkbz_set_functions.html
|
| | 116 | % ffs_ipwkbz_set_functions> code where we loop over current z, and for each
|
| | 117 | % current z, grab out a particular row from the mt_z_trans that corresponds
|
| | 118 | % to a current shock's transition into all future states.
|
| | 119 | %
|
| | 120 | % here, each column of mt_val corresponds to a state z, think of that as
|
| | 121 | % future state z. The input mt_val is *V(coh, z)*, we need to integrate to
|
| | 122 | % get *E(V(coh,z')|z)*.
|
| | 123 | %
|
| | 124 |
|
0.136 | 129 | 125 | mt_ev_condi_z = mt_val*mt_z_trans';
|
< 0.001 | 129 | 126 | if(bl_display_evf)
|
| | 127 | disp('----------------------------------------');
|
| | 128 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 129 | disp('mt_ev_condi_z: Q by M');
|
| | 130 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 131 | disp(size(mt_ev_condi_z));
|
| | 132 | disp(head(array2table(mt_ev_condi_z), 20));
|
| | 133 | disp(tail(array2table(mt_ev_condi_z), 20));
|
| | 134 | end
|
| | 135 |
|
| | 136 | %% Reshape *E(V(coh,z'|z,w))* to allow for maxing
|
| | 137 | % dim(mt_ev_condi_z): *IxJ by M*
|
| | 138 |
|
0.002 | 129 | 139 | [it_mt_bp_rown, it_mt_bp_coln] = size(mt_k);
|
< 0.001 | 129 | 140 | mt_ev_condi_z_full = reshape(mt_ev_condi_z, [it_mt_bp_rown, it_mt_bp_coln*it_z_n]);
|
| | 141 |
|
| | 142 | %% Maximize *max_{k'}(E(V(coh(k',b'=w-k'),z'|z,w))* optimal value and index
|
| | 143 | % Maximization, find optimal k'/b' combination given z and w=k'+b'
|
| | 144 |
|
0.032 | 129 | 145 | [ar_ev_condi_z_max, ar_ev_condi_z_max_idx] = max(mt_ev_condi_z_full);
|
< 0.001 | 129 | 146 | mt_ev_condi_z_max = reshape(ar_ev_condi_z_max, [it_mt_bp_coln, it_z_n]);
|
< 0.001 | 129 | 147 | mt_ev_condi_z_max_idx = reshape(ar_ev_condi_z_max_idx, [it_mt_bp_coln, it_z_n]);
|
| | 148 |
|
< 0.001 | 129 | 149 | if(bl_display_evf)
|
| | 150 |
|
| | 151 | disp('----------------------------------------');
|
| | 152 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 153 | disp('mt_ev_condi_z_full: J by IxM');
|
| | 154 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 155 | disp(size(mt_ev_condi_z_full));
|
| | 156 | % disp(head(array2table(mt_ev_condi_z_full), 20));
|
| | 157 | % disp(tail(array2table(mt_ev_condi_z_full), 20));
|
| | 158 |
|
| | 159 | disp('----------------------------------------');
|
| | 160 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 161 | disp('mt_ev_condi_z_max: I by M');
|
| | 162 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 163 | disp(size(mt_ev_condi_z_max));
|
| | 164 | disp(head(array2table(mt_ev_condi_z_max), 20));
|
| | 165 | disp(tail(array2table(mt_ev_condi_z_max), 20));
|
| | 166 |
|
| | 167 |
|
| | 168 | disp('----------------------------------------');
|
| | 169 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 170 | disp('mt_ev_condi_z_max_idx: I by M');
|
| | 171 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 172 | disp(size(mt_ev_condi_z_max_idx));
|
| | 173 | disp(head(array2table(mt_ev_condi_z_max_idx), 20));
|
| | 174 | disp(tail(array2table(mt_ev_condi_z_max_idx), 20));
|
| | 175 |
|
| | 176 | end
|
| | 177 |
|
| | 178 | %% Reindex K' and B' Choices for each State at the Optimal *w'=k'+b'* choice
|
| | 179 | % The K' and B' Optimal Choices Associated with EV opti
|
| | 180 | % dim(mt_ev_condi_z_max_kp): *I by M*
|
0.006 | 129 | 181 | ar_add_grid = linspace(0, it_mt_bp_rown*(it_mt_bp_coln-1), it_mt_bp_coln);
|
0.008 | 129 | 182 | mt_ev_condi_z_max_idx = mt_ev_condi_z_max_idx + ar_add_grid';
|
| | 183 |
|
< 0.001 | 129 | 184 | if(bl_display_evf)
|
| | 185 | disp('----------------------------------------');
|
| | 186 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 187 | disp('mt_ev_condi_z_max_idx: I by M');
|
| | 188 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 189 | disp(size(mt_ev_condi_z_max_idx));
|
| | 190 | disp(head(array2table(mt_ev_condi_z_max_idx), 20));
|
| | 191 | disp(tail(array2table(mt_ev_condi_z_max_idx), 20));
|
| | 192 | end
|
| | 193 |
|
0.021 | 129 | 194 | mt_ev_condi_z_max_kp = reshape(ar_k_mesha(mt_ev_condi_z_max_idx), [it_mt_bp_coln, it_z_n]);
|
0.019 | 129 | 195 | mt_ev_condi_z_max_bp = reshape(ar_a_meshk(mt_ev_condi_z_max_idx), [it_mt_bp_coln, it_z_n]);
|
| | 196 |
|
< 0.001 | 129 | 197 | if(bl_display_evf)
|
| | 198 | disp('----------------------------------------');
|
| | 199 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 200 | disp('mt_ev_condi_z_max_kp: I by M');
|
| | 201 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 202 | disp(size(mt_ev_condi_z_max_kp));
|
| | 203 | disp(head(array2table(mt_ev_condi_z_max_kp), 20));
|
| | 204 | disp(tail(array2table(mt_ev_condi_z_max_kp), 20));
|
| | 205 |
|
| | 206 | disp('----------------------------------------');
|
| | 207 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 208 | disp('mt_ev_condi_z_max_bp: I by M');
|
| | 209 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 210 | disp(size(mt_ev_condi_z_max_bp));
|
| | 211 | disp(head(array2table(mt_ev_condi_z_max_bp), 20));
|
| | 212 | disp(tail(array2table(mt_ev_condi_z_max_bp), 20));
|
| | 213 | end
|
| | 214 |
|
| | 215 | %% Graph
|
| | 216 |
|
< 0.001 | 129 | 217 | if (bl_graph_evf)
|
| | 218 |
|
| | 219 | %% Graph 1, V and EV
|
| | 220 | if (~bl_graph_onebyones)
|
| | 221 | figure('PaperPosition', [0 0 14 4]);
|
| | 222 | hold on;
|
| | 223 | end
|
| | 224 |
|
| | 225 |
|
| | 226 | for subplot_j=1:1:2
|
| | 227 |
|
| | 228 | if (~bl_graph_onebyones)
|
| | 229 | hAxis(subplot_j) = subplot(1,2,subplot_j);
|
| | 230 | else
|
| | 231 | figure('PaperPosition', [0 0 7 4]);
|
| | 232 | end
|
| | 233 |
|
| | 234 | if (subplot_j==1)
|
| | 235 | chart = plot(mt_val);
|
| | 236 | end
|
| | 237 | if (subplot_j==2)
|
| | 238 | chart = plot(mt_ev_condi_z);
|
| | 239 | end
|
| | 240 |
|
| | 241 | clr = jet(numel(chart));
|
| | 242 | for m = 1:numel(chart)
|
| | 243 | set(chart(m),'Color',clr(m,:))
|
| | 244 | end
|
| | 245 |
|
| | 246 | legend2plot = fliplr([1 round(numel(chart)/3) round((2*numel(chart))/3) numel(chart)]);
|
| | 247 | legendCell = cellstr(num2str(ar_z', 'shock=%3.2f'));
|
| | 248 | legend(chart(legend2plot), legendCell(legend2plot), 'Location','southeast');
|
| | 249 |
|
| | 250 | if (subplot_j==1)
|
| | 251 | title('V(coh,zp); w(k+b),k,z');
|
| | 252 | end
|
| | 253 | if (subplot_j==2)
|
| | 254 | title('E_z(V(coh,zp|z))');
|
| | 255 | end
|
| | 256 |
|
| | 257 | ylabel('Next Period Value');
|
| | 258 | xlabel({'Index of Cash-on-Hand Discrete Point'...
|
| | 259 | 'Each Segment is a w=k+b; within segment increasing k'...
|
| | 260 | 'EV and V identical if shock is fully persistent'});
|
| | 261 | grid on;
|
| | 262 | grid minor;
|
| | 263 | end
|
| | 264 |
|
| | 265 | % Share y axis
|
| | 266 | if (~bl_graph_onebyones)
|
| | 267 | linkaxes(hAxis,'y');
|
| | 268 | end
|
| | 269 |
|
| | 270 | % save file
|
| | 271 | if (bl_img_save)
|
| | 272 | mkdir(support_map('st_img_path'));
|
| | 273 | st_file_name = [st_img_prefix st_img_name_main '_vev' st_img_suffix];
|
| | 274 | saveas(gcf, strcat(st_img_path, st_file_name));
|
| | 275 | end
|
| | 276 |
|
| | 277 | %% Graph 2, max(EV)
|
| | 278 |
|
| | 279 | if(~bl_graph_onebyones)
|
| | 280 | figure('PaperPosition', [0 0 7 4]);
|
| | 281 | end
|
| | 282 |
|
| | 283 | for sub_j=1:1:1
|
| | 284 |
|
| | 285 | if(sub_j==1)
|
| | 286 | mt_outcome = mt_ev_condi_z_max;
|
| | 287 | st_y_label = 'max_{k''}(E(V(coh(k'',b''=w-k''),z''|z,w))';
|
| | 288 | end
|
| | 289 |
|
| | 290 | if(~bl_graph_onebyones)
|
| | 291 | subplot(1,1,sub_j)
|
| | 292 | else
|
| | 293 | figure('PaperPosition', [0 0 7 4]);
|
| | 294 | end
|
| | 295 | hold on;
|
| | 296 |
|
| | 297 | ar_it_z_graph = ([1 round((it_z_n)/4) round(2*((it_z_n)/4)) round(3*((it_z_n)/4)) (it_z_n)]);
|
| | 298 | clr = jet(length(ar_it_z_graph));
|
| | 299 | i_ctr = 0;
|
| | 300 | for i = ar_it_z_graph
|
| | 301 | i_ctr = i_ctr + 1;
|
| | 302 | ar_x = ar_w_level;
|
| | 303 | ar_y = mt_outcome(:, i);
|
| | 304 | scatter(ar_x, ar_y, 5, ...
|
| | 305 | 'MarkerEdgeColor', clr(i_ctr,:), ...
|
| | 306 | 'MarkerFaceColor', clr(i_ctr,:));
|
| | 307 | end
|
| | 308 |
|
| | 309 | grid on;
|
| | 310 | grid minor;
|
| | 311 | title(['2nd Stage Exp Value at Optimal K given W=K''+B'''])
|
| | 312 | ylabel(st_y_label)
|
| | 313 | xlabel({'Aggregate Savings'})
|
| | 314 |
|
| | 315 | legendCell = cellstr(num2str(ar_z', 'shock=%3.2f'));
|
| | 316 | legendCell{length(legendCell) + 1} = 'max-agg-save';
|
| | 317 | legend(legendCell([ar_it_z_graph length(legendCell)]), 'Location','southeast');
|
| | 318 |
|
| | 319 | xline0 = xline(0);
|
| | 320 | xline0.HandleVisibility = 'off';
|
| | 321 | yline0 = yline(0);
|
| | 322 | yline0.HandleVisibility = 'off';
|
| | 323 |
|
| | 324 | end
|
| | 325 |
|
| | 326 | % save file
|
| | 327 | if (bl_img_save)
|
| | 328 | mkdir(support_map('st_img_path'));
|
| | 329 | st_file_name = [st_img_prefix st_img_name_main '_maxev' st_img_suffix];
|
| | 330 | saveas(gcf, strcat(st_img_path, st_file_name));
|
| | 331 | end
|
| | 332 |
|
| | 333 | %% Graph 3, at max(EV) optimal choice category, color regions, borrow save
|
| | 334 |
|
| | 335 | % Borrow Vs Save
|
| | 336 | [ar_z_mw, ar_w_mz] = meshgrid(ar_z, ar_w_level);
|
| | 337 | mt_it_borr_idx = (mt_ev_condi_z_max_bp < 0);
|
| | 338 | mt_it_riskyhalf_idx = ((mt_ev_condi_z_max_kp./mt_ev_condi_z_max_bp) > 0.5);
|
| | 339 | mt_it_kzero_idx = (mt_ev_condi_z_max_kp == 0);
|
| | 340 | mt_it_isnan_idx = (isnan(mt_ev_condi_z_max_kp));
|
| | 341 |
|
| | 342 | figure('PaperPosition', [0 0 7 4]);
|
| | 343 | % States: ar_w, ar_z
|
| | 344 | % Choices: mt_ev_condi_z_max_kp, mt_ev_condi_z_max_bp
|
| | 345 | hold on;
|
| | 346 | it_sca_size = 10;
|
| | 347 | chart_br = scatter(ar_w_mz(mt_it_borr_idx),...
|
| | 348 | ar_z_mw(mt_it_borr_idx),...
|
| | 349 | it_sca_size, 'blue', 'filled');
|
| | 350 | % legend([chart_br], {'Borrow'}, 'Location','northeast');
|
| | 351 | chart_khalf = scatter(ar_w_mz(~mt_it_borr_idx & mt_it_riskyhalf_idx),...
|
| | 352 | ar_z_mw(~mt_it_borr_idx & mt_it_riskyhalf_idx),...
|
| | 353 | it_sca_size, 'black', 'filled');
|
| | 354 | % legend([chart_khalf], {'Save >0.5 K'}, 'Location','northeast');
|
| | 355 | chart_sv = scatter(ar_w_mz(~mt_it_borr_idx & ~mt_it_riskyhalf_idx),...
|
| | 356 | ar_z_mw(~mt_it_borr_idx & ~mt_it_riskyhalf_idx),...
|
| | 357 | it_sca_size, 'red', 'filled');
|
| | 358 | % legend([chart_sv], {'Save <0.5 K'}, 'Location','northeast');
|
| | 359 | chart_invalid = scatter(ar_w_mz(mt_it_kzero_idx | mt_it_isnan_idx),...
|
| | 360 | ar_z_mw(mt_it_kzero_idx | mt_it_isnan_idx),...
|
| | 361 | it_sca_size, 'yellow', 'filled');
|
| | 362 | legend([chart_br, chart_khalf, chart_sv, chart_invalid], ...
|
| | 363 | {'Borrow','Save >0.5 K','Save <0.5 K', 'k=0 or k=nan'}, 'Location','northeast');
|
| | 364 | title('Borrow and Save Regions')
|
| | 365 | ylabel('Shocks')
|
| | 366 | xlabel({'Total Savings w=k+b'})
|
| | 367 | grid on;
|
| | 368 |
|
| | 369 | % save file
|
| | 370 | if (bl_img_save)
|
| | 371 | mkdir(support_map('st_img_path'));
|
| | 372 | st_file_name = [st_img_prefix st_img_name_main '_maxbrsv' st_img_suffix];
|
| | 373 | saveas(gcf, strcat(st_img_path, st_file_name));
|
| | 374 | end
|
| | 375 |
|
| | 376 | %% Graph 4, Optimal K' and B' Levels
|
| | 377 |
|
| | 378 | [~, ar_w_mz] = meshgrid(ar_z, ar_w_level);
|
| | 379 | for sub_j=1:1:4
|
| | 380 |
|
| | 381 | if (bl_graph_onebyones)
|
| | 382 | figure('PaperPosition', [0 0 7 4]);
|
| | 383 | end
|
| | 384 |
|
| | 385 | if (sub_j==1)
|
| | 386 | if(~bl_graph_onebyones)
|
| | 387 | figure('PaperPosition', [0 0 14 4]);
|
| | 388 | subplot(1,2,sub_j);
|
| | 389 | end
|
| | 390 | mt_y = mt_ev_condi_z_max_bp;
|
| | 391 | end
|
| | 392 | if (sub_j==2)
|
| | 393 | if(~bl_graph_onebyones)
|
| | 394 | subplot(1,2,sub_j);
|
| | 395 | end
|
| | 396 |
|
| | 397 | mt_y = mt_ev_condi_z_max_kp;
|
| | 398 | end
|
| | 399 | if (sub_j==3)
|
| | 400 | if(~bl_graph_onebyones)
|
| | 401 | figure('PaperPosition', [0 0 14 4]);
|
| | 402 | subplot(1,2,sub_j-2);
|
| | 403 | end
|
| | 404 | mt_y = zeros(size(mt_ev_condi_z_max_bp));
|
| | 405 | mt_it_borr_idx = (mt_ev_condi_z_max_bp < 0);
|
| | 406 | mt_y(mt_it_borr_idx) = -mt_ev_condi_z_max_bp(mt_it_borr_idx)/fl_b_bd;
|
| | 407 | mt_y(~mt_it_borr_idx) = mt_ev_condi_z_max_bp(~mt_it_borr_idx)./ar_w_mz(~mt_it_borr_idx);
|
| | 408 | end
|
| | 409 | if (sub_j==4)
|
| | 410 | if(~bl_graph_onebyones)
|
| | 411 | subplot(1,2,sub_j-2);
|
| | 412 | end
|
| | 413 | mt_y = mt_ev_condi_z_max_kp./(ar_w_level'-fl_b_bd);
|
| | 414 | end
|
| | 415 |
|
| | 416 | hold on;
|
| | 417 | chart = plot(ar_w_level, mt_y);
|
| | 418 | clr = jet(numel(chart));
|
| | 419 |
|
| | 420 | if (length(ar_w_level) <= 100)
|
| | 421 | scatter(ar_w_mz(:), mt_y(:), 3, 'filled', 'MarkerEdgeColor', 'b', 'MarkerFaceColor', 'b');
|
| | 422 | end
|
| | 423 |
|
| | 424 | for m = 1:numel(chart)
|
| | 425 | set(chart(m),'Color',clr(m,:))
|
| | 426 | end
|
| | 427 | legend2plot = fliplr([1 round(numel(chart)/3) round((2*numel(chart))/3) numel(chart)]);
|
| | 428 | legendCell = cellstr(num2str(ar_z', 'shock=%3.2f'));
|
| | 429 |
|
| | 430 | xline0 = xline(0);
|
| | 431 | xline0.HandleVisibility = 'off';
|
| | 432 | yline0 = yline(0);
|
| | 433 | yline0.HandleVisibility = 'off';
|
| | 434 | grid on;
|
| | 435 | if (sub_j<=2)
|
| | 436 | hline = refline([1 0]);
|
| | 437 | hline.Color = 'k';
|
| | 438 | hline.LineStyle = ':';
|
| | 439 | hline.HandleVisibility = 'off';
|
| | 440 | end
|
| | 441 |
|
| | 442 | if (sub_j==1)
|
| | 443 | title('B Choices of W');
|
| | 444 | ylabel('B Choices');
|
| | 445 | xlabel({'Total Savings w=k+b'});
|
| | 446 | legend(chart(legend2plot), legendCell(legend2plot), 'Location','northwest');
|
| | 447 | end
|
| | 448 | if (sub_j==2)
|
| | 449 | title('K Choices of W');
|
| | 450 | ylabel('K Choices');
|
| | 451 | xlabel({'Total Savings w=k+b'});
|
| | 452 | legend(chart(legend2plot), legendCell(legend2plot), 'Location','northwest');
|
| | 453 | end
|
| | 454 |
|
| | 455 | if (sub_j==3)
|
| | 456 | title('B Fraction of Borrow Max and Save');
|
| | 457 | ylabel('B/bar(B) if br or B/W if sv');
|
| | 458 | xlabel({'Total Savings w=k+b'});
|
| | 459 | % set(gca, 'YScale', 'log');
|
| | 460 | ylim([-1.1 1.1]);
|
| | 461 | legend(chart(legend2plot), legendCell(legend2plot), 'Location','northwest');
|
| | 462 | end
|
| | 463 | if (sub_j==4)
|
| | 464 | title('K Fraction Choices of Total K Possible');
|
| | 465 | ylabel('K/(W-bar(b)) ');
|
| | 466 | xlabel({'Total Savings w=k+b'});
|
| | 467 | % set(gca, 'YScale', 'log');
|
| | 468 | ylim([0 1.1]);
|
| | 469 | legend(chart(legend2plot), legendCell(legend2plot), 'Location','northeast');
|
| | 470 | end
|
| | 471 |
|
| | 472 | end
|
| | 473 |
|
| | 474 | % save file
|
| | 475 | if (bl_img_save)
|
| | 476 | mkdir(support_map('st_img_path'));
|
| | 477 | st_file_name = [st_img_prefix st_img_name_main '_wkbopti' st_img_suffix];
|
| | 478 | saveas(gcf, strcat(st_img_path, st_file_name));
|
| | 479 | end
|
| | 480 |
|
| | 481 | end
|
| | 482 |
|
| | 483 | %% Display Various Containers
|
| | 484 |
|
< 0.001 | 129 | 485 | if (bl_display_evf)
|
| | 486 |
|
| | 487 | %% Display 1 support_map
|
| | 488 | fft_container_map_display(support_map, it_display_summmat_rowmax, it_display_summmat_colmax);
|
| | 489 |
|
| | 490 | %% Display 2 armt_map
|
| | 491 | fft_container_map_display(armt_map, it_display_summmat_rowmax, it_display_summmat_colmax);
|
| | 492 |
|
| | 493 | %% Display 3 param_map
|
| | 494 | fft_container_map_display(param_map, it_display_summmat_rowmax, it_display_summmat_colmax);
|
| | 495 |
|
| | 496 | %% Display 4 func_map
|
| | 497 | fft_container_map_display(func_map, it_display_summmat_rowmax, it_display_summmat_colmax);
|
| | 498 | end
|
| | 499 |
|
0.077 | 129 | 500 | end
|
Other subfunctions in this file are not included in this listing.