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_fibs_evf(varargin)
|
| | 8 | %% FF_IPWKBZ_FIBS_EVF solves the k' vs b' problem given aggregate savings
|
| | 9 | % This file is based on
|
| | 10 | % <https://fanwangecon.github.io/CodeDynaAsset/m_ipwkbz/solve/html/ff_ipwkbz_evf.html
|
| | 11 | % ff_ipwkbz_evf>, see that file for more comments. Compare graphs side by
|
| | 12 | % side from this file and
|
| | 13 | % <https://fanwangecon.github.io/CodeDynaAsset/m_ipwkbz/solve/html/ff_ipwkbz_evf.html
|
| | 14 | % ff_ipwkbz_evf> to see visually the effect of introducing formal and
|
| | 15 | % informal choices with bridge loan.
|
| | 16 | %
|
| | 17 | % In contrast to ff_ipwkbz_evf.m, here, we need to deal with borrowing and
|
| | 18 | % savings formal and informal. These will change how the testing matrix is
|
| | 19 | % constructed. When bridge loan is allowed, we also need to construct the
|
| | 20 | % output matrixes differently. In ff_ipwkbz_evf.m, the assumption is that
|
| | 21 | % coh today does not matter, so to find optimal k* choice, we only need to
|
| | 22 | % know the aggregate savings level. But now, we need to know the coh level
|
| | 23 | % as well.
|
| | 24 | %
|
| | 25 | % Below two reachable coh matrixes are constructed, one for when aggregate
|
| | 26 | % savings choice w >= 0, and another for when aggregate savings <= 0. Then
|
| | 27 | % they are stacked together. And we still have the same outputs as
|
| | 28 | % ff_ipwkbz_evf.m. The difference is that while for savings where w >=0,
|
| | 29 | % each row are w levels for the output matrixes, but for w <=0, each row is
|
| | 30 | % for w level + coh percentage combinations.
|
| | 31 | %
|
| | 32 | % @param mt_val matrix state_n I^2 by shock_n. This is the value
|
| | 33 | % matrix each row is a feasible reachable state given the choice
|
| | 34 | % vectors/matrix and each column is a shock state.
|
| | 35 | %
|
| | 36 | % @param param_map container parameter container
|
| | 37 | %
|
| | 38 | % @param support_map container support container
|
| | 39 | %
|
| | 40 | % @param armt_map container container with states, choices and shocks
|
| | 41 | % grids that are inputs for grid based solution algorithm
|
| | 42 | %
|
| | 43 | % @return mt_ev_condi_z_max matrix *(choice_w_pos_n + choice_w_neg_n x
|
| | 44 | % coh_perc_n)* by *shock_n* max_{k'}(E(V(coh(k',b'=w-k'),z'|z,w)) conditional
|
| | 45 | % on z and w, at the optimal k' choice (w=k'+b') what is the expected
|
| | 46 | % utility? This is the value result from the 2nd stage problem. Note the
|
| | 47 | % result integrates over z'.
|
| | 48 | %
|
| | 49 | % @return mt_ev_condi_z_max_idx matrix *(choice_w_pos_n + choice_w_neg_n x
|
| | 50 | % coh_perc_n)* by *(shock_n)* this is the argmax from
|
| | 51 | % max_{k'}(E(V(coh(k',b'=w-k'),z'|z,w)). Given the vector of k' choices,
|
| | 52 | % which index maximized conditional on z and w integrating over z'.
|
| | 53 | %
|
| | 54 | % @return mt_ev_condi_z_max_kp matrix *(choice_w_pos_n + choice_w_neg_n x
|
| | 55 | % coh_perc_n)* by *(shock_n)* the k' choice at
|
| | 56 | % max_{k'}(E(V(coh(k',b'=w-k'),z'|z,w))
|
| | 57 | %
|
| | 58 | % @return mt_ev_condi_z_max_bp matrix *(choice_w_pos_n + choice_w_neg_n x
|
| | 59 | % coh_perc_n)* by *(shock_n)* the b'=w-k' choice at
|
| | 60 | % max_{k'}(E(V(coh(k',b'=w-k'),z'|z,w))
|
| | 61 | %
|
| | 62 | % @example
|
| | 63 | %
|
| | 64 | % @include
|
| | 65 | %
|
| | 66 | % * <https://github.com/FanWangEcon/CodeDynaAsset/blob/master/m_fibs/m_ipwkbz_paramfunc/ffs_ipwkbz_fibs_set_default_param.m ffs_ipwkbz_fibs_set_default_param>
|
| | 67 | % * <https://github.com/FanWangEcon/CodeDynaAsset/blob/master/m_fibs/m_ipwkbz_paramfunc/ffs_ipwkbz_fibs_get_funcgrid.m ffs_ipwkbz_fibs_get_funcgrid>
|
| | 68 | %
|
| | 69 |
|
| | 70 | %% Default
|
| | 71 | % If comparing with
|
| | 72 | % <https://fanwangecon.github.io/CodeDynaAsset/m_ipwkbz/solve/html/ff_ipwkbz_evf.html
|
| | 73 | % ff_ipwkbz_evf>, note that the borrowing and savings interest rates are
|
| | 74 | % the same there. Run st_param_which = 'default' to replicate identical
|
| | 75 | % result as ff_ipwkbz_evf.m.
|
| | 76 | %
|
| | 77 |
|
< 0.001 | 135 | 78 | if (~isempty(varargin))
|
| | 79 |
|
| | 80 | % override when called from outside
|
0.004 | 135 | 81 | [mt_val, param_map, support_map, armt_map] = varargin{:};
|
| | 82 |
|
| | 83 | else
|
| | 84 | clear all;
|
| | 85 | close all;
|
| | 86 |
|
| | 87 | % Not default parameters, but parameters that generate defaults
|
| | 88 | it_param_set = 4;
|
| | 89 | bl_input_override = true;
|
| | 90 | [param_map, support_map] = ffs_ipwkbz_fibs_set_default_param(it_param_set);
|
| | 91 |
|
| | 92 | support_map('bl_graph_evf') = true;
|
| | 93 | support_map('bl_display_evf') = true;
|
| | 94 |
|
| | 95 | st_param_which = 'default';
|
| | 96 |
|
| | 97 | if (strcmp(st_param_which, 'default'))
|
| | 98 |
|
| | 99 | param_map('it_ak_perc_n') = 250;
|
| | 100 | param_map('bl_bridge') = true;
|
| | 101 |
|
| | 102 | elseif (strcmp(st_param_which, 'small'))
|
| | 103 |
|
| | 104 | param_map('it_w_perc_n') = 7;
|
| | 105 | param_map('it_ak_perc_n') = 7;
|
| | 106 | param_map('it_coh_bridge_perc_n') = 3;
|
| | 107 | param_map('fl_w_interp_grid_gap') = 2;
|
| | 108 | param_map('fl_coh_interp_grid_gap') = 2;
|
| | 109 |
|
| | 110 | param_map('bl_bridge') = true;
|
| | 111 | param_map('it_coh_bridge_perc_n') = 3;
|
| | 112 |
|
| | 113 | elseif (strcmp(st_param_which, 'ff_ipwkbz_evf'))
|
| | 114 |
|
| | 115 | param_map('fl_r_fsv') = 0.025;
|
| | 116 | param_map('fl_r_inf') = 0.025;
|
| | 117 | param_map('fl_r_inf_bridge') = 0.025;
|
| | 118 | param_map('fl_r_fbr') = 0.025;
|
| | 119 | param_map('it_ak_perc_n') = 250;
|
| | 120 |
|
| | 121 | param_map('bl_bridge') = false;
|
| | 122 | param_map('it_coh_bridge_perc_n') = 1;
|
| | 123 |
|
| | 124 | end
|
| | 125 |
|
| | 126 | param_map('fl_w_interp_grid_gap') = (param_map('fl_w_max')-param_map('fl_b_bd'))/param_map('it_ak_perc_n');
|
| | 127 |
|
| | 128 | [armt_map, func_map] = ffs_ipwkbz_fibs_get_funcgrid(param_map, support_map, bl_input_override); % 1 for override
|
| | 129 |
|
| | 130 | % Generating Defaults
|
| | 131 | params_group = values(armt_map, {'ar_ameshk_tnext_with_r', 'ar_k_mesha', 'ar_z'});
|
| | 132 | [ar_ameshk_tnext_with_r, ar_k_mesha, ar_z] = params_group{:};
|
| | 133 | params_group = values(func_map, {'f_util_standin'});
|
| | 134 | [f_util_standin] = params_group{:};
|
| | 135 |
|
| | 136 | % works with replicating ff_ipwkbz_evf.m result
|
| | 137 | mt_val = f_util_standin(ar_z, ar_ameshk_tnext_with_r, ar_k_mesha);
|
| | 138 |
|
< 0.001 | 135 | 139 | end
|
| | 140 |
|
| | 141 | %% Parse Parameters
|
| | 142 |
|
| | 143 | % armt_map
|
0.004 | 135 | 144 | params_group = values(armt_map, {'mt_z_trans', 'ar_z',...
|
| | 145 | 'ar_w_level', 'ar_w_level_full', 'ar_coh_bridge_perc', ...
|
| | 146 | 'ar_k_mesha', 'ar_a_meshk', 'ar_ameshk_tnext_with_r', 'mt_k'});
|
0.003 | 135 | 147 | [mt_z_trans, ar_z, ...
|
| 135 | 148 | ar_w_level, ar_w_level_full, ar_coh_bridge_perc, ...
|
| 135 | 149 | ar_k_mesha, ar_a_meshk, ar_ameshk_tnext_with_r, mt_k] = params_group{:};
|
| | 150 |
|
| | 151 | % param_map
|
0.002 | 135 | 152 | params_group = values(param_map, {'it_z_n', 'fl_nan_replace', 'fl_b_bd'});
|
0.001 | 135 | 153 | [it_z_n, fl_nan_replace, fl_b_bd] = params_group{:};
|
0.002 | 135 | 154 | params_group = values(param_map, {'bl_bridge'});
|
< 0.001 | 135 | 155 | [bl_bridge] = params_group{:};
|
| | 156 |
|
| | 157 | % support_map
|
0.002 | 135 | 158 | params_group = values(support_map, {'bl_graph_onebyones','bl_display_evf', 'bl_graph_evf'});
|
0.001 | 135 | 159 | [bl_graph_onebyones, bl_display_evf, bl_graph_evf] = params_group{:};
|
0.002 | 135 | 160 | params_group = values(support_map, {'bl_img_save', 'st_img_path', 'st_img_prefix', 'st_img_name_main', 'st_img_suffix'});
|
0.002 | 135 | 161 | [bl_img_save, st_img_path, st_img_prefix, st_img_name_main, st_img_suffix] = params_group{:};
|
0.002 | 135 | 162 | params_group = values(support_map, {'it_display_summmat_rowmax', 'it_display_summmat_colmax'});
|
0.001 | 135 | 163 | [it_display_summmat_rowmax, it_display_summmat_colmax] = params_group{:};
|
| | 164 |
|
| | 165 | % append function name
|
< 0.001 | 135 | 166 | st_func_name = 'ff_ipwkbz_evf';
|
0.001 | 135 | 167 | st_img_name_main = [st_func_name st_img_name_main];
|
| | 168 |
|
| | 169 | %% Integrate *E(V(coh(k',b'), z')|z, w)*
|
| | 170 | % Each column for a different state z, each value *E(V(coh,z')|z)* integrated already
|
| | 171 | % Here, each column is a current z, more to right higher EV
|
| | 172 | % dim(mt_ev_condi_z): *Q by M*
|
| | 173 | % Note that: mt_ev_condi_z = mt_val*mt_z_trans' is a mistake, that would be
|
| | 174 | % what we do in the
|
| | 175 | % <https://fanwangecon.github.io/CodeDynaAsset/m_ipwkbz/paramfunc/html/ffs_ipwkbz_set_functions.html
|
| | 176 | % ffs_ipwkbz_set_functions> code where we loop over current z, and for each
|
| | 177 | % current z, grab out a particular row from the mt_z_trans that corresponds
|
| | 178 | % to a current shock's transition into all future states.
|
| | 179 | %
|
| | 180 | % here, each column of mt_val corresponds to a state z, think of that as
|
| | 181 | % future state z. The input mt_val is *V(coh, z)*, we need to integrate to
|
| | 182 | % get *E(V(coh,z')|z)*.
|
| | 183 | %
|
| | 184 |
|
0.438 | 135 | 185 | mt_ev_condi_z = mt_val*mt_z_trans';
|
< 0.001 | 135 | 186 | if(bl_display_evf)
|
| | 187 | disp('----------------------------------------');
|
| | 188 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 189 | disp('mt_ev_condi_z: Q by M');
|
| | 190 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 191 | disp(size(mt_ev_condi_z));
|
| | 192 | disp(head(array2table(mt_ev_condi_z), 20));
|
| | 193 | disp(tail(array2table(mt_ev_condi_z), 20));
|
| | 194 | end
|
| | 195 |
|
| | 196 | %% Reshape *E(V(coh,z'|z,w))* to allow for maxing
|
| | 197 | % dim(mt_ev_condi_z): *IxJ by M*
|
| | 198 |
|
0.003 | 135 | 199 | [it_mt_bp_rown, it_mt_bp_coln] = size(mt_k);
|
< 0.001 | 135 | 200 | mt_ev_condi_z_full = reshape(mt_ev_condi_z, [it_mt_bp_rown, it_mt_bp_coln*it_z_n]);
|
| | 201 |
|
| | 202 | %% Maximize *max_{k'}(E(V(coh(k',b'=w-k'),z'|z,w))* optimal value and index
|
| | 203 | % Maximization, find optimal k'/b' combination given z and w=k'+b'
|
| | 204 |
|
0.103 | 135 | 205 | [ar_ev_condi_z_max, ar_ev_condi_z_max_idx] = max(mt_ev_condi_z_full);
|
< 0.001 | 135 | 206 | mt_ev_condi_z_max = reshape(ar_ev_condi_z_max, [it_mt_bp_coln, it_z_n]);
|
< 0.001 | 135 | 207 | mt_ev_condi_z_max_idx = reshape(ar_ev_condi_z_max_idx, [it_mt_bp_coln, it_z_n]);
|
< 0.001 | 135 | 208 | if(bl_display_evf)
|
| | 209 |
|
| | 210 | disp('----------------------------------------');
|
| | 211 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 212 | disp('mt_ev_condi_z_full: J by IxM');
|
| | 213 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 214 | disp(size(mt_ev_condi_z_full));
|
| | 215 | % disp(head(array2table(mt_ev_condi_z_full), 20));
|
| | 216 | % disp(tail(array2table(mt_ev_condi_z_full), 20));
|
| | 217 |
|
| | 218 |
|
| | 219 | disp('----------------------------------------');
|
| | 220 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 221 | disp('mt_ev_condi_z_max: I by M');
|
| | 222 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 223 | disp(size(mt_ev_condi_z_max));
|
| | 224 | disp(head(array2table(mt_ev_condi_z_max), 20));
|
| | 225 | disp(tail(array2table(mt_ev_condi_z_max), 20));
|
| | 226 |
|
| | 227 |
|
| | 228 | disp('----------------------------------------');
|
| | 229 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 230 | disp('mt_ev_condi_z_max_idx: I by M');
|
| | 231 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 232 | disp(size(mt_ev_condi_z_max_idx));
|
| | 233 | disp(head(array2table(mt_ev_condi_z_max_idx), 20));
|
| | 234 | disp(tail(array2table(mt_ev_condi_z_max_idx), 20));
|
| | 235 |
|
| | 236 | end
|
| | 237 |
|
| | 238 | %% Reindex K' and B' Choices for each State at the Optimal *w'=k'+b'* choice
|
| | 239 | % The K' and B' Optimal Choices Associated with EV opti
|
| | 240 | % dim(mt_ev_condi_z_max_kp): *I by M*
|
0.007 | 135 | 241 | ar_add_grid = linspace(0, it_mt_bp_rown*(it_mt_bp_coln-1), it_mt_bp_coln);
|
0.016 | 135 | 242 | mt_ev_condi_z_max_idx = mt_ev_condi_z_max_idx + ar_add_grid';
|
| | 243 |
|
< 0.001 | 135 | 244 | if(bl_display_evf)
|
| | 245 | disp('----------------------------------------');
|
| | 246 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 247 | disp('mt_ev_condi_z_max_idx: I by M');
|
| | 248 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 249 | disp(size(mt_ev_condi_z_max_idx));
|
| | 250 | disp(head(array2table(mt_ev_condi_z_max_idx), 20));
|
| | 251 | disp(tail(array2table(mt_ev_condi_z_max_idx), 20));
|
| | 252 | end
|
| | 253 |
|
0.058 | 135 | 254 | mt_ev_condi_z_max_kp = reshape(ar_k_mesha(mt_ev_condi_z_max_idx), [it_mt_bp_coln, it_z_n]);
|
0.047 | 135 | 255 | mt_ev_condi_z_max_bp = reshape(ar_a_meshk(mt_ev_condi_z_max_idx), [it_mt_bp_coln, it_z_n]);
|
| | 256 |
|
< 0.001 | 135 | 257 | if(bl_display_evf)
|
| | 258 | disp('----------------------------------------');
|
| | 259 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 260 | disp('mt_ev_condi_z_max_kp: I by M');
|
| | 261 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 262 | disp(size(mt_ev_condi_z_max_kp));
|
| | 263 | disp(head(array2table(mt_ev_condi_z_max_kp), 20));
|
| | 264 | disp(tail(array2table(mt_ev_condi_z_max_kp), 20));
|
| | 265 |
|
| | 266 | disp('----------------------------------------');
|
| | 267 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 268 | disp('mt_ev_condi_z_max_bp: I by M');
|
| | 269 | disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
| | 270 | disp(size(mt_ev_condi_z_max_bp));
|
| | 271 | disp(head(array2table(mt_ev_condi_z_max_bp), 20));
|
| | 272 | disp(tail(array2table(mt_ev_condi_z_max_bp), 20));
|
| | 273 | end
|
| | 274 |
|
| | 275 | %% Graph
|
| | 276 |
|
< 0.001 | 135 | 277 | if (bl_graph_evf)
|
| | 278 |
|
| | 279 | %% Graph 1, V and EV
|
| | 280 | if (~bl_graph_onebyones)
|
| | 281 | figure('PaperPosition', [0 0 14 4]);
|
| | 282 | hold on;
|
| | 283 | end
|
| | 284 |
|
| | 285 |
|
| | 286 | for subplot_j=1:1:2
|
| | 287 |
|
| | 288 | if (~bl_graph_onebyones)
|
| | 289 | hAxis(subplot_j) = subplot(1,2,subplot_j);
|
| | 290 | else
|
| | 291 | figure('PaperPosition', [0 0 7 4]);
|
| | 292 | end
|
| | 293 |
|
| | 294 | if (subplot_j==1)
|
| | 295 | chart = plot(mt_val);
|
| | 296 | end
|
| | 297 | if (subplot_j==2)
|
| | 298 | chart = plot(mt_ev_condi_z);
|
| | 299 | end
|
| | 300 |
|
| | 301 | clr = jet(numel(chart));
|
| | 302 | for m = 1:numel(chart)
|
| | 303 | set(chart(m),'Color',clr(m,:))
|
| | 304 | end
|
| | 305 |
|
| | 306 | legend2plot = fliplr([1 round(numel(chart)/3) round((2*numel(chart))/3) numel(chart)]);
|
| | 307 | legendCell = cellstr(num2str(ar_z', 'shock=%3.2f'));
|
| | 308 | legend(chart(legend2plot), legendCell(legend2plot), 'Location','southeast');
|
| | 309 |
|
| | 310 | if (subplot_j==1)
|
| | 311 | title('V(coh,zp); w(k+b),k,z');
|
| | 312 | end
|
| | 313 | if (subplot_j==2)
|
| | 314 | title('E_z(V(coh,zp|z))');
|
| | 315 | end
|
| | 316 |
|
| | 317 | ylabel('Next Period Value');
|
| | 318 | xlabel({'Index of Cash-on-Hand Discrete Point'...
|
| | 319 | 'Each Segment is a w=k+b; within segment increasing k'...
|
| | 320 | 'EV and V identical if shock is fully persistent'});
|
| | 321 | grid on;
|
| | 322 | grid minor;
|
| | 323 | end
|
| | 324 |
|
| | 325 | % Share y axis
|
| | 326 | if (~bl_graph_onebyones)
|
| | 327 | linkaxes(hAxis,'y');
|
| | 328 | end
|
| | 329 |
|
| | 330 | % save file
|
| | 331 | if (bl_img_save)
|
| | 332 | mkdir(support_map('st_img_path'));
|
| | 333 | st_file_name = [st_img_prefix st_img_name_main '_vev' st_img_suffix];
|
| | 334 | saveas(gcf, strcat(st_img_path, st_file_name));
|
| | 335 | end
|
| | 336 |
|
| | 337 | %% Graph 2, max(EV)
|
| | 338 |
|
| | 339 | if(~bl_graph_onebyones)
|
| | 340 | figure('PaperPosition', [0 0 7 4]);
|
| | 341 | end
|
| | 342 |
|
| | 343 | for sub_j=1:1:1
|
| | 344 |
|
| | 345 | if(sub_j==1)
|
| | 346 | mt_outcome = mt_ev_condi_z_max;
|
| | 347 | st_y_label = 'max_{k''}(E(V(coh(k'',b''=w-k''),z''|z,w))';
|
| | 348 | end
|
| | 349 |
|
| | 350 | if(~bl_graph_onebyones)
|
| | 351 | subplot(1,1,sub_j)
|
| | 352 | else
|
| | 353 | figure('PaperPosition', [0 0 7 4]);
|
| | 354 | end
|
| | 355 | hold on;
|
| | 356 |
|
| | 357 | 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)]);
|
| | 358 | clr = jet(length(ar_it_z_graph));
|
| | 359 | i_ctr = 0;
|
| | 360 | for i = ar_it_z_graph
|
| | 361 | i_ctr = i_ctr + 1;
|
| | 362 | ar_x = ar_w_level_full;
|
| | 363 | ar_y = mt_outcome(:, i);
|
| | 364 | scatter(ar_x, ar_y, 5, ...
|
| | 365 | 'MarkerEdgeColor', clr(i_ctr,:), ...
|
| | 366 | 'MarkerFaceColor', clr(i_ctr,:));
|
| | 367 | end
|
| | 368 |
|
| | 369 | grid on;
|
| | 370 | grid minor;
|
| | 371 | title(['2nd Stage Exp Value at Optimal K given W=K''+B'''])
|
| | 372 | ylabel(st_y_label)
|
| | 373 | xlabel({'Aggregate Savings'})
|
| | 374 |
|
| | 375 | legendCell = cellstr(num2str(ar_z', 'shock=%3.2f'));
|
| | 376 | legendCell{length(legendCell) + 1} = 'max-agg-save';
|
| | 377 | legend(legendCell([ar_it_z_graph length(legendCell)]), 'Location','southeast');
|
| | 378 |
|
| | 379 | xline0 = xline(0);
|
| | 380 | xline0.HandleVisibility = 'off';
|
| | 381 | yline0 = yline(0);
|
| | 382 | yline0.HandleVisibility = 'off';
|
| | 383 |
|
| | 384 | end
|
| | 385 |
|
| | 386 | % save file
|
| | 387 | if (bl_img_save)
|
| | 388 | mkdir(support_map('st_img_path'));
|
| | 389 | st_file_name = [st_img_prefix st_img_name_main '_maxev' st_img_suffix];
|
| | 390 | saveas(gcf, strcat(st_img_path, st_file_name));
|
| | 391 | end
|
| | 392 |
|
| | 393 | %% Graph 3, at max(EV) optimal choice category, color regions, borrow save
|
| | 394 |
|
| | 395 | % Borrow Vs Save
|
| | 396 | [ar_z_mw, ar_w_mz] = meshgrid(ar_z, ar_w_level_full);
|
| | 397 | mt_it_borr_idx = (mt_ev_condi_z_max_bp < 0);
|
| | 398 | mt_it_riskyhalf_idx = ((mt_ev_condi_z_max_kp./mt_ev_condi_z_max_bp) > 0.5);
|
| | 399 | mt_it_kzero_idx = (mt_ev_condi_z_max_kp == 0);
|
| | 400 | mt_it_isnan_idx = (isnan(mt_ev_condi_z_max_kp));
|
| | 401 |
|
| | 402 | figure('PaperPosition', [0 0 7 4]);
|
| | 403 | % States: ar_w, ar_z
|
| | 404 | % Choices: mt_ev_condi_z_max_kp, mt_ev_condi_z_max_bp
|
| | 405 | hold on;
|
| | 406 | it_sca_size = 10;
|
| | 407 | chart_br = scatter(ar_w_mz(mt_it_borr_idx),...
|
| | 408 | ar_z_mw(mt_it_borr_idx),...
|
| | 409 | it_sca_size, 'blue', 'filled');
|
| | 410 | % legend([chart_br], {'Borrow'}, 'Location','northeast');
|
| | 411 | chart_khalf = scatter(ar_w_mz(~mt_it_borr_idx & mt_it_riskyhalf_idx),...
|
| | 412 | ar_z_mw(~mt_it_borr_idx & mt_it_riskyhalf_idx),...
|
| | 413 | it_sca_size, 'black', 'filled');
|
| | 414 | % legend([chart_khalf], {'Save >0.5 K'}, 'Location','northeast');
|
| | 415 | chart_sv = scatter(ar_w_mz(~mt_it_borr_idx & ~mt_it_riskyhalf_idx),...
|
| | 416 | ar_z_mw(~mt_it_borr_idx & ~mt_it_riskyhalf_idx),...
|
| | 417 | it_sca_size, 'red', 'filled');
|
| | 418 | % legend([chart_sv], {'Save <0.5 K'}, 'Location','northeast');
|
| | 419 | chart_invalid = scatter(ar_w_mz(mt_it_kzero_idx | mt_it_isnan_idx),...
|
| | 420 | ar_z_mw(mt_it_kzero_idx | mt_it_isnan_idx),...
|
| | 421 | it_sca_size, 'yellow', 'filled');
|
| | 422 | legend([chart_br, chart_khalf, chart_sv, chart_invalid], ...
|
| | 423 | {'Borrow','Save >0.5 K','Save <0.5 K', 'k=0 or k=nan'}, 'Location','northeast');
|
| | 424 | title('Borrow and Save Regions')
|
| | 425 | ylabel('Shocks')
|
| | 426 | xlabel({'Total Savings w=k+b'})
|
| | 427 | grid on;
|
| | 428 |
|
| | 429 | % save file
|
| | 430 | if (bl_img_save)
|
| | 431 | mkdir(support_map('st_img_path'));
|
| | 432 | st_file_name = [st_img_prefix st_img_name_main '_maxbrsv' st_img_suffix];
|
| | 433 | saveas(gcf, strcat(st_img_path, st_file_name));
|
| | 434 | end
|
| | 435 |
|
| | 436 | %% Graph 4, Optimal K' and B' Levels
|
| | 437 | % compare results here to results from <https://fanwangecon.github.io/CodeDynaAsset/m_ipwkbz/solve/html/ff_ipwkbz_evf.html
|
| | 438 | % ff_ipwkbz_evf>. Several key differences:
|
| | 439 | %
|
| | 440 | % # Each color line is thicker here, because there is in effect another
|
| | 441 | % state that is relevant now in the 2nd stage, which is the
|
| | 442 | % cash-on-hand percentage, which is implemented as a percentage of the
|
| | 443 | % w = k' + b' choice that needs to go cover bridge loan. So different
|
| | 444 | % percentages have the same color, hence thicker lines fore each color
|
| | 445 | % # Jump between saving and borrowing, here, the borrowing and savings
|
| | 446 | % interest rates differ
|
| | 447 | % # Finally, the discontinuities in choices, they occur here because of
|
| | 448 | % the formal menu of choices, the little squiggly up and downs are due
|
| | 449 | % to households using informal choices to complement formal choices.
|
| | 450 | %
|
| | 451 |
|
| | 452 | [~, ar_w_mz] = meshgrid(ar_z, ar_w_level_full);
|
| | 453 | for sub_j=1:1:4
|
| | 454 |
|
| | 455 | if (bl_graph_onebyones)
|
| | 456 | figure('PaperPosition', [0 0 7 4]);
|
| | 457 | end
|
| | 458 |
|
| | 459 | if (sub_j==1)
|
| | 460 | if(~bl_graph_onebyones)
|
| | 461 | figure('PaperPosition', [0 0 14 4]);
|
| | 462 | subplot(1,2,sub_j);
|
| | 463 | end
|
| | 464 | mt_y = mt_ev_condi_z_max_bp;
|
| | 465 | end
|
| | 466 | if (sub_j==2)
|
| | 467 | if(~bl_graph_onebyones)
|
| | 468 | subplot(1,2,sub_j);
|
| | 469 | end
|
| | 470 |
|
| | 471 | mt_y = mt_ev_condi_z_max_kp;
|
| | 472 | end
|
| | 473 | if (sub_j==3)
|
| | 474 | if(~bl_graph_onebyones)
|
| | 475 | figure('PaperPosition', [0 0 14 4]);
|
| | 476 | subplot(1,2,sub_j-2);
|
| | 477 | end
|
| | 478 | mt_y = zeros(size(mt_ev_condi_z_max_bp));
|
| | 479 | mt_it_borr_idx = (mt_ev_condi_z_max_bp < 0);
|
| | 480 | mt_y(mt_it_borr_idx) = -mt_ev_condi_z_max_bp(mt_it_borr_idx)/fl_b_bd;
|
| | 481 | mt_y(~mt_it_borr_idx) = mt_ev_condi_z_max_bp(~mt_it_borr_idx)./ar_w_mz(~mt_it_borr_idx);
|
| | 482 | end
|
| | 483 | if (sub_j==4)
|
| | 484 | if(~bl_graph_onebyones)
|
| | 485 | subplot(1,2,sub_j-2);
|
| | 486 | end
|
| | 487 | mt_y = mt_ev_condi_z_max_kp./(ar_w_level_full'-fl_b_bd);
|
| | 488 | end
|
| | 489 |
|
| | 490 | hold on;
|
| | 491 | clr = jet(length(ar_z));
|
| | 492 | for m = 1:length(ar_z)
|
| | 493 | chart(m) = scatter(ar_w_level_full, mt_y(:, m), 3, ...
|
| | 494 | 'Marker', 'O', ...
|
| | 495 | 'MarkerEdgeColor', clr(m,:), 'MarkerFaceAlpha', 0.75, ...
|
| | 496 | 'MarkerFaceColor', clr(m,:), 'MarkerEdgeAlpha', 0.75);
|
| | 497 | end
|
| | 498 |
|
| | 499 | legend2plot = fliplr([1 round(numel(chart)/3) round((2*numel(chart))/3) numel(chart)]);
|
| | 500 | legendCell = cellstr(num2str(ar_z', 'shock=%3.2f'));
|
| | 501 |
|
| | 502 | xline0 = xline(0);
|
| | 503 | xline0.HandleVisibility = 'off';
|
| | 504 | yline0 = yline(0);
|
| | 505 | yline0.HandleVisibility = 'off';
|
| | 506 | grid on;
|
| | 507 | if (sub_j<=2)
|
| | 508 | hline = refline([1 0]);
|
| | 509 | hline.Color = 'k';
|
| | 510 | hline.LineStyle = ':';
|
| | 511 | hline.HandleVisibility = 'off';
|
| | 512 | end
|
| | 513 |
|
| | 514 | if (sub_j==1)
|
| | 515 | title('B Choices of W');
|
| | 516 | ylabel('B Choices');
|
| | 517 | xlabel({'Total Savings w=k+b'});
|
| | 518 | legend(chart(legend2plot), legendCell(legend2plot), 'Location','northwest');
|
| | 519 | end
|
| | 520 | if (sub_j==2)
|
| | 521 | title('K Choices of W');
|
| | 522 | ylabel('K Choices');
|
| | 523 | xlabel({'Total Savings w=k+b'});
|
| | 524 | legend(chart(legend2plot), legendCell(legend2plot), 'Location','northwest');
|
| | 525 | end
|
| | 526 |
|
| | 527 | if (sub_j==3)
|
| | 528 | title('B Fraction of Borrow Max and Save');
|
| | 529 | ylabel('B/bar(B) if br or B/W if sv');
|
| | 530 | xlabel({'Total Savings w=k+b'});
|
| | 531 | % set(gca, 'YScale', 'log');
|
| | 532 | ylim([-1.1 1.1]);
|
| | 533 | legend(chart(legend2plot), legendCell(legend2plot), 'Location','northwest');
|
| | 534 | end
|
| | 535 | if (sub_j==4)
|
| | 536 | title('K Fraction Choices of Total K Possible');
|
| | 537 | ylabel('K/(W-bar(b)) ');
|
| | 538 | xlabel({'Total Savings w=k+b'});
|
| | 539 | % set(gca, 'YScale', 'log');
|
| | 540 | ylim([0 1.1]);
|
| | 541 | legend(chart(legend2plot), legendCell(legend2plot), 'Location','northeast');
|
| | 542 | end
|
| | 543 |
|
| | 544 | end
|
| | 545 |
|
| | 546 | % save file
|
| | 547 | if (bl_img_save)
|
| | 548 | mkdir(support_map('st_img_path'));
|
| | 549 | st_file_name = [st_img_prefix st_img_name_main '_wkbopti' st_img_suffix];
|
| | 550 | saveas(gcf, strcat(st_img_path, st_file_name));
|
| | 551 | end
|
| | 552 |
|
| | 553 | end
|
| | 554 |
|
| | 555 | %% Display Various Containers
|
| | 556 |
|
< 0.001 | 135 | 557 | if (bl_display_evf)
|
| | 558 |
|
| | 559 | %% Display 1 support_map
|
| | 560 | fft_container_map_display(support_map, it_display_summmat_rowmax, it_display_summmat_colmax);
|
| | 561 |
|
| | 562 | %% Display 2 armt_map
|
| | 563 | fft_container_map_display(armt_map, it_display_summmat_rowmax, it_display_summmat_colmax);
|
| | 564 |
|
| | 565 | %% Display 3 param_map
|
| | 566 | fft_container_map_display(param_map, it_display_summmat_rowmax, it_display_summmat_colmax);
|
| | 567 |
|
| | 568 | %% Display 4 func_map
|
| | 569 | fft_container_map_display(func_map, it_display_summmat_rowmax, it_display_summmat_colmax);
|
| | 570 | end
|
| | 571 |
|
0.201 | 135 | 572 | end
|
Other subfunctions in this file are not included in this listing.