This is a static copy of a profile report

Home

Function details for ff_ipwkz_evfThis is a static copy of a profile report

Home

ff_ipwkz_evf (Calls: 75, Time: 0.041 s)
Generated 06-Jul-2019 16:11:07 using performance time.
function in file C:\Users\fan\CodeDynaAsset\m_ipwkz\solve\ff_ipwkz_evf.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
ff_ipwkz_vffunction75
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
122
mt_ev_condi_z = mt_val*mt_z_tr...
750.006 s14.8%
142
[ar_ev_condi_z_max, ar_ev_cond...
750.004 s9.5%
478
end
750.004 s9.0%
176
ar_add_grid = linspace(0, it_m...
750.004 s8.7%
64
[mt_val, param_map, support_ma...
750.003 s6.1%
All other lines  0.021 s51.8%
Totals  0.041 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
linspacefunction750.002 s5.9%
Self time (built-ins, overhead, etc.)  0.039 s94.1%
Totals  0.041 s100% 
Code Analyzer results
Line numberMessage
66Using CLEAR ALL usually decreases code performance and is often unnecessary.
96The value assigned here to 'fl_nan_replace' appears to be unused. Consider replacing it by ~.
224The variable 'hAxis' appears to change size on every loop iteration. Consider preallocating for speed.
306Use of brackets [] is unnecessary. Use parentheses to group, if needed.
Coverage results
Show coverage for parent directory
Total lines in function472
Non-code lines (comments, blank lines)166
Code lines (lines that can run)306
Code lines that did run35
Code lines that did not run271
Coverage (did run/can run)11.44 %
Function listing
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_ipwkz_evf(varargin)
   8 
%% FF_IPWKZ_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_ipwkz/paramfunc/ffs_ipwkz_set_default_param.m ffs_ipwkz_set_default_param>
  52 
% * <https://github.com/FanWangEcon/CodeDynaAsset/blob/master/m_ipwkz/paramfunc/ffs_ipwkz_get_funcgrid.m ffs_ipwkz_get_funcgrid>
  53 
%
  54 

  55 
%% Default
  56 

< 0.001 
     75 
  57
params_len = length(varargin); 
< 0.001 
     75 
  58
bl_input_override = 0; 
< 0.001 
     75 
  59
if (params_len == 5) 
< 0.001 
     75 
  60
    bl_input_override = varargin{5}; 
< 0.001 
     75 
  61
end 
< 0.001 
     75 
  62
if (bl_input_override) 
  63 
    % override when called from outside
  0.003 
     75 
  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 
    it_param_set = 4;
  71 
    bl_input_override = true;
  72 
    [param_map, support_map] = ffs_ipwkz_set_default_param(it_param_set);
  73 
    
  74 
    support_map('bl_graph_evf') = true;
  75 
    support_map('bl_display_evf') = true;
  76 
    
  77 
    param_map('it_ak_perc_n') = 250;
  78 
    param_map('fl_w_interp_grid_gap') = (param_map('fl_w_max')-param_map('fl_b_bd'))/param_map('it_ak_perc_n');
  79 
    
  80 
    [armt_map, func_map] = ffs_ipwkz_get_funcgrid(param_map, support_map, bl_input_override); % 1 for override
  81 
    
  82 
    % Generating Defaults
  83 
    params_group = values(armt_map, {'ar_a_meshk', 'ar_k_mesha', 'ar_z'});
  84 
    [ar_a_meshk, ar_k_mesha, ar_z] = params_group{:};
  85 
    params_group = values(func_map, {'f_util_standin'});
  86 
    [f_util_standin] = params_group{:};
  87 
    mt_val = f_util_standin(ar_z, ar_a_meshk, ar_k_mesha);
< 0.001 
     75 
  88
end 
  89 

  90 
%% Parse Parameters
  0.002 
     75 
  91
params_group = values(armt_map, {'mt_z_trans', 'ar_z',... 
  92 
    'ar_w_level', 'ar_k_mesha', 'ar_a_meshk', 'mt_k'});
  0.002 
     75 
  93
[mt_z_trans, ar_z, ar_w_level, ... 
     75 
  94
    ar_k_mesha, ar_a_meshk, mt_k] = params_group{:}; 
  0.001 
     75 
  95
params_group = values(param_map, {'it_z_n', 'fl_nan_replace', 'fl_b_bd'}); 
  0.001 
     75 
  96
[it_z_n, fl_nan_replace, fl_b_bd] = params_group{:}; 
  0.001 
     75 
  97
params_group = values(support_map, {'bl_graph_onebyones','bl_display_evf', 'bl_graph_evf'}); 
  0.001 
     75 
  98
[bl_graph_onebyones, bl_display_evf, bl_graph_evf] = params_group{:}; 
  0.001 
     75 
  99
params_group = values(support_map, {'bl_img_save', 'st_img_path', 'st_img_prefix', 'st_img_name_main', 'st_img_suffix'}); 
  0.002 
     75 
 100
[bl_img_save, st_img_path, st_img_prefix, st_img_name_main, st_img_suffix] = params_group{:}; 
 101 

 102 
% append function name
< 0.001 
     75 
 103
st_func_name = 'ff_ipwkz_evf'; 
< 0.001 
     75 
 104
st_img_name_main = [st_func_name st_img_name_main]; 
 105 

 106 
%% Integrate *E(V(coh(k',b'), z')|z, w)*
 107 
% Each column for a different state z, each value *E(V(coh,z')|z)* integrated already
 108 
% Here, each column is a current z, more to right higher EV
 109 
% dim(mt_ev_condi_z): *Q by M*
 110 
% Note that: mt_ev_condi_z = mt_val*mt_z_trans' is a mistake, that would be
 111 
% what we do in the
 112 
% <https://fanwangecon.github.io/CodeDynaAsset/m_ipwkz/paramfunc/html/ffs_ipwkz_set_functions.html
 113 
% ffs_ipwkz_set_functions> code where we loop over current z, and for each
 114 
% current z, grab out a particular row from the mt_z_trans that corresponds
 115 
% to a current shock's transition into all future states.
 116 
%
 117 
% here, each column of mt_val corresponds to a state z, think of that as
 118 
% future state z. The input mt_val is *V(coh, z)*, we need to integrate to
 119 
% get *E(V(coh,z')|z)*.
 120 
%
 121 

  0.006 
     75 
 122
mt_ev_condi_z = mt_val*mt_z_trans'; 
< 0.001 
     75 
 123
if(bl_display_evf) 
 124 
    disp('----------------------------------------');
 125 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 126 
    disp('mt_ev_condi_z: Q by M');
 127 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 128 
    disp(size(mt_ev_condi_z));
 129 
    disp(head(array2table(mt_ev_condi_z), 20));
 130 
    disp(tail(array2table(mt_ev_condi_z), 20));    
 131 
end
 132 

 133 
%% Reshape *E(V(coh,z'|z,w))* to allow for maxing
 134 
% dim(mt_ev_condi_z): *IxJ by M*
 135 

  0.002 
     75 
 136
[it_mt_bp_rown, it_mt_bp_coln] = size(mt_k); 
< 0.001 
     75 
 137
mt_ev_condi_z_full = reshape(mt_ev_condi_z, [it_mt_bp_rown, it_mt_bp_coln*it_z_n]); 
 138 

 139 
%% Maximize *max_{k'}(E(V(coh(k',b'=w-k'),z'|z,w))* optimal value and index
 140 
% Maximization, find optimal k'/b' combination given z and w=k'+b'
 141 

  0.004 
     75 
 142
[ar_ev_condi_z_max, ar_ev_condi_z_max_idx] = max(mt_ev_condi_z_full); 
< 0.001 
     75 
 143
mt_ev_condi_z_max = reshape(ar_ev_condi_z_max, [it_mt_bp_coln, it_z_n]); 
< 0.001 
     75 
 144
mt_ev_condi_z_max_idx = reshape(ar_ev_condi_z_max_idx, [it_mt_bp_coln, it_z_n]); 
 145 

< 0.001 
     75 
 146
if(bl_display_evf) 
 147 
    disp('----------------------------------------');
 148 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 149 
    disp('mt_ev_condi_z_full: J by IxM');
 150 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 151 
    disp(size(mt_ev_condi_z_full));
 152 
%     disp(head(array2table(mt_ev_condi_z_full), 20));
 153 
%     disp(tail(array2table(mt_ev_condi_z_full), 20));
 154 
        
 155 
    disp('----------------------------------------');
 156 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 157 
    disp('mt_ev_condi_z_max: I by M');
 158 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 159 
    disp(size(mt_ev_condi_z_max));
 160 
    disp(head(array2table(mt_ev_condi_z_max), 20));
 161 
    disp(tail(array2table(mt_ev_condi_z_max), 20));
 162 
    
 163 

 164 
    disp('----------------------------------------');
 165 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 166 
    disp('mt_ev_condi_z_max_idx: I by M');
 167 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 168 
    disp(size(mt_ev_condi_z_max_idx));
 169 
    disp(head(array2table(mt_ev_condi_z_max_idx), 20));
 170 
    disp(tail(array2table(mt_ev_condi_z_max_idx), 20));
 171 
end
 172 

 173 
%% Reindex K' and B' Choices for each State at the Optimal *w'=k'+b'* choice
 174 
% The K' and B' Optimal Choices Associated with EV opti
 175 
% dim(mt_ev_condi_z_max_kp): *I by M*
  0.004 
     75 
 176
ar_add_grid = linspace(0, it_mt_bp_rown*(it_mt_bp_coln-1), it_mt_bp_coln); 
< 0.001 
     75 
 177
mt_ev_condi_z_max_idx = mt_ev_condi_z_max_idx + ar_add_grid'; 
 178 

< 0.001 
     75 
 179
if(bl_display_evf) 
 180 
    disp('----------------------------------------');
 181 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 182 
    disp('mt_ev_condi_z_max_idx: I by M');
 183 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 184 
    disp(size(mt_ev_condi_z_max_idx));
 185 
    disp(head(array2table(mt_ev_condi_z_max_idx), 20));
 186 
    disp(tail(array2table(mt_ev_condi_z_max_idx), 20));    
 187 
end
 188 

  0.001 
     75 
 189
mt_ev_condi_z_max_kp = reshape(ar_k_mesha(mt_ev_condi_z_max_idx), [it_mt_bp_coln, it_z_n]); 
  0.001 
     75 
 190
mt_ev_condi_z_max_bp = reshape(ar_a_meshk(mt_ev_condi_z_max_idx), [it_mt_bp_coln, it_z_n]); 
 191 

< 0.001 
     75 
 192
if(bl_display_evf) 
 193 
    disp('----------------------------------------');
 194 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 195 
    disp('mt_ev_condi_z_max_kp: I by M');
 196 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 197 
    disp(size(mt_ev_condi_z_max_kp));
 198 
    disp(head(array2table(mt_ev_condi_z_max_kp), 20));
 199 
    disp(tail(array2table(mt_ev_condi_z_max_kp), 20));        
 200 
    
 201 
    disp('----------------------------------------');
 202 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 203 
    disp('mt_ev_condi_z_max_bp: I by M');
 204 
    disp('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
 205 
    disp(size(mt_ev_condi_z_max_bp));
 206 
    disp(head(array2table(mt_ev_condi_z_max_bp), 20));
 207 
    disp(tail(array2table(mt_ev_condi_z_max_bp), 20));    
 208 
end
 209 

 210 
%% Graph
 211 

< 0.001 
     75 
 212
if (bl_graph_evf) 
 213 
    
 214 
    %% Graph 1, V and EV
 215 
    if (~bl_graph_onebyones)
 216 
        figure('PaperPosition', [0 0 14 4]);
 217 
        hold on;
 218 
    end
 219 
    
 220 
    
 221 
    for subplot_j=1:1:2
 222 
        
 223 
        if (~bl_graph_onebyones)
 224 
            hAxis(subplot_j) = subplot(1,2,subplot_j);
 225 
        else
 226 
            figure('PaperPosition', [0 0 7 4]);
 227 
        end
 228 
        
 229 
        if (subplot_j==1)
 230 
            chart = plot(mt_val);
 231 
        end
 232 
        if (subplot_j==2)
 233 
            chart = plot(mt_ev_condi_z);
 234 
        end
 235 
        
 236 
        clr = jet(numel(chart));
 237 
        for m = 1:numel(chart)
 238 
            set(chart(m),'Color',clr(m,:))
 239 
        end
 240 
        
 241 
        legend2plot = fliplr([1 round(numel(chart)/3) round((2*numel(chart))/3)  numel(chart)]);
 242 
        legendCell = cellstr(num2str(ar_z', 'shock=%3.2f'));
 243 
        legend(chart(legend2plot), legendCell(legend2plot), 'Location','southeast');
 244 
        
 245 
        if (subplot_j==1)
 246 
            title('V(coh,zp); w(k+b),k,z');
 247 
        end
 248 
        if (subplot_j==2)
 249 
            title('E_z(V(coh,zp|z))');
 250 
        end
 251 
        
 252 
        ylabel('Next Period Value');
 253 
        xlabel({'Index of Cash-on-Hand Discrete Point'...
 254 
            'Each Segment is a w=k+b; within segment increasing k'...
 255 
            'EV and V identical if shock is fully persistent'});
 256 
        grid on;
 257 
        grid minor;
 258 
    end
 259 
    
 260 
    % Share y axis
 261 
    if (~bl_graph_onebyones)
 262 
        linkaxes(hAxis,'y');
 263 
    end
 264 
    
 265 
    % save file
 266 
    if (bl_img_save)
 267 
        mkdir(support_map('st_img_path'));
 268 
        st_file_name = [st_img_prefix st_img_name_main '_vev' st_img_suffix];
 269 
        saveas(gcf, strcat(st_img_path, st_file_name));
 270 
    end
 271 
    
 272 
    %% Graph 2, max(EV)
 273 
    
 274 
    if(~bl_graph_onebyones)
 275 
        figure('PaperPosition', [0 0 7 4]);
 276 
    end
 277 
    
 278 
    for sub_j=1:1:1
 279 
        
 280 
        if(sub_j==1)
 281 
            mt_outcome = mt_ev_condi_z_max;
 282 
            st_y_label = 'max_{k''}(E(V(coh(k'',b''=w-k''),z''|z,w))';
 283 
        end
 284 
        
 285 
        if(~bl_graph_onebyones)
 286 
            subplot(1,1,sub_j)
 287 
        else
 288 
            figure('PaperPosition', [0 0 7 4]);
 289 
        end
 290 
        hold on;
 291 
        
 292 
        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)]);
 293 
        clr = jet(length(ar_it_z_graph));
 294 
        i_ctr = 0;
 295 
        for i = ar_it_z_graph
 296 
            i_ctr = i_ctr + 1;
 297 
            ar_x = ar_w_level;
 298 
            ar_y = mt_outcome(:, i);
 299 
            scatter(ar_x, ar_y, 5, ...
 300 
                'MarkerEdgeColor', clr(i_ctr,:), ...
 301 
                'MarkerFaceColor', clr(i_ctr,:));
 302 
        end
 303 
        
 304 
        grid on;
 305 
        grid minor;
 306 
        title(['2nd Stage Exp Value at Optimal K given W=K''+B'''])
 307 
        ylabel(st_y_label)
 308 
        xlabel({'Aggregate Savings'})
 309 
        
 310 
        legendCell = cellstr(num2str(ar_z', 'shock=%3.2f'));
 311 
        legendCell{length(legendCell) + 1} = 'max-agg-save';
 312 
        legend(legendCell([ar_it_z_graph length(legendCell)]), 'Location','southeast');
 313 
        
 314 
        xline0 = xline(0);
 315 
        xline0.HandleVisibility = 'off';
 316 
        yline0 = yline(0);
 317 
        yline0.HandleVisibility = 'off';
 318 
        
 319 
    end
 320 
    
 321 
    % save file
 322 
    if (bl_img_save)
 323 
        mkdir(support_map('st_img_path'));
 324 
        st_file_name = [st_img_prefix st_img_name_main '_maxev' st_img_suffix];
 325 
        saveas(gcf, strcat(st_img_path, st_file_name));
 326 
    end
 327 
    
 328 
    %% Graph 3, at max(EV) optimal choice category, color regions, borrow save
 329 
    
 330 
    % Borrow Vs Save
 331 
    [ar_z_mw, ar_w_mz] = meshgrid(ar_z, ar_w_level);
 332 
    mt_it_borr_idx = (mt_ev_condi_z_max_bp < 0);
 333 
    mt_it_riskyhalf_idx = ((mt_ev_condi_z_max_kp./mt_ev_condi_z_max_bp) > 0.5);
 334 
    mt_it_kzero_idx = (mt_ev_condi_z_max_kp == 0);
 335 
    mt_it_isnan_idx = (isnan(mt_ev_condi_z_max_kp));
 336 
    
 337 
    figure('PaperPosition', [0 0 7 4]);
 338 
    % States: ar_w, ar_z
 339 
    % Choices: mt_ev_condi_z_max_kp, mt_ev_condi_z_max_bp
 340 
    hold on;
 341 
    it_sca_size = 10;
 342 
    chart_br = scatter(ar_w_mz(mt_it_borr_idx),...
 343 
        ar_z_mw(mt_it_borr_idx),...
 344 
        it_sca_size, 'blue', 'filled');
 345 
    %     legend([chart_br], {'Borrow'}, 'Location','northeast');
 346 
    chart_khalf = scatter(ar_w_mz(~mt_it_borr_idx & mt_it_riskyhalf_idx),...
 347 
        ar_z_mw(~mt_it_borr_idx & mt_it_riskyhalf_idx),...
 348 
        it_sca_size, 'black', 'filled');
 349 
    %     legend([chart_khalf], {'Save >0.5 K'}, 'Location','northeast');
 350 
    chart_sv = scatter(ar_w_mz(~mt_it_borr_idx & ~mt_it_riskyhalf_idx),...
 351 
        ar_z_mw(~mt_it_borr_idx & ~mt_it_riskyhalf_idx),...
 352 
        it_sca_size, 'red', 'filled');
 353 
    %     legend([chart_sv], {'Save <0.5 K'}, 'Location','northeast');
 354 
    chart_invalid = scatter(ar_w_mz(mt_it_kzero_idx | mt_it_isnan_idx),...
 355 
        ar_z_mw(mt_it_kzero_idx | mt_it_isnan_idx),...
 356 
        it_sca_size, 'yellow', 'filled');
 357 
    legend([chart_br, chart_khalf, chart_sv, chart_invalid], ...
 358 
        {'Borrow','Save >0.5 K','Save <0.5 K', 'k=0 or k=nan'}, 'Location','northeast');
 359 
    title('Borrow and Save Regions')
 360 
    ylabel('Shocks')
 361 
    xlabel({'Total Savings w=k+b'})
 362 
    grid on;
 363 
    
 364 
    % save file
 365 
    if (bl_img_save)
 366 
        mkdir(support_map('st_img_path'));
 367 
        st_file_name = [st_img_prefix st_img_name_main '_maxbrsv' st_img_suffix];
 368 
        saveas(gcf, strcat(st_img_path, st_file_name));
 369 
    end
 370 
    
 371 
    %% Graph 4, Optimal K' and B' Levels
 372 
    
 373 
    [~, ar_w_mz] = meshgrid(ar_z, ar_w_level);
 374 
    for sub_j=1:1:4
 375 
        
 376 
        if (bl_graph_onebyones)
 377 
            figure('PaperPosition', [0 0 7 4]);
 378 
        end
 379 
        
 380 
        if (sub_j==1)
 381 
            if(~bl_graph_onebyones)
 382 
                figure('PaperPosition', [0 0 14 4]);
 383 
                subplot(1,2,sub_j);
 384 
            end
 385 
            mt_y = mt_ev_condi_z_max_bp;
 386 
        end
 387 
        if (sub_j==2)
 388 
            if(~bl_graph_onebyones)
 389 
                subplot(1,2,sub_j);
 390 
            end
 391 
            
 392 
            mt_y = mt_ev_condi_z_max_kp;
 393 
        end
 394 
        if (sub_j==3)
 395 
            if(~bl_graph_onebyones)
 396 
                figure('PaperPosition', [0 0 14 4]);
 397 
                subplot(1,2,sub_j-2);
 398 
            end
 399 
            mt_y = zeros(size(mt_ev_condi_z_max_bp));
 400 
            mt_it_borr_idx = (mt_ev_condi_z_max_bp < 0);
 401 
            mt_y(mt_it_borr_idx) = -mt_ev_condi_z_max_bp(mt_it_borr_idx)/fl_b_bd;
 402 
            mt_y(~mt_it_borr_idx) = mt_ev_condi_z_max_bp(~mt_it_borr_idx)./ar_w_mz(~mt_it_borr_idx);
 403 
        end
 404 
        if (sub_j==4)
 405 
            if(~bl_graph_onebyones)
 406 
                subplot(1,2,sub_j-2);
 407 
            end
 408 
            mt_y = mt_ev_condi_z_max_kp./(ar_w_level'-fl_b_bd);
 409 
        end
 410 
        
 411 
        hold on;
 412 
        chart = plot(ar_w_level, mt_y);
 413 
        clr = jet(numel(chart));
 414 
        
 415 
        if (length(ar_w_level) <= 100)
 416 
            scatter(ar_w_mz(:), mt_y(:), 3, 'filled', 'MarkerEdgeColor', 'b', 'MarkerFaceColor', 'b');
 417 
        end
 418 
        
 419 
        for m = 1:numel(chart)
 420 
            set(chart(m),'Color',clr(m,:))
 421 
        end
 422 
        legend2plot = fliplr([1 round(numel(chart)/3) round((2*numel(chart))/3)  numel(chart)]);
 423 
        legendCell = cellstr(num2str(ar_z', 'shock=%3.2f'));
 424 
        
 425 
        xline0 = xline(0);
 426 
        xline0.HandleVisibility = 'off';
 427 
        yline0 = yline(0);
 428 
        yline0.HandleVisibility = 'off';
 429 
        grid on;
 430 
        if (sub_j<=2)
 431 
            hline = refline([1 0]);
 432 
            hline.Color = 'k';
 433 
            hline.LineStyle = ':';
 434 
            hline.HandleVisibility = 'off';
 435 
        end
 436 
        
 437 
        if (sub_j==1)
 438 
            title('B Choices of W');
 439 
            ylabel('B Choices');
 440 
            xlabel({'Total Savings w=k+b'});
 441 
            legend(chart(legend2plot), legendCell(legend2plot), 'Location','northwest');
 442 
        end
 443 
        if (sub_j==2)
 444 
            title('K Choices of W');
 445 
            ylabel('K Choices');
 446 
            xlabel({'Total Savings w=k+b'});
 447 
            legend(chart(legend2plot), legendCell(legend2plot), 'Location','northwest');
 448 
        end
 449 
        
 450 
        if (sub_j==3)
 451 
            title('B Fraction of Borrow Max and Save');
 452 
            ylabel('B/bar(B) if br or B/W if sv');
 453 
            xlabel({'Total Savings w=k+b'});
 454 
            %             set(gca, 'YScale', 'log');
 455 
            ylim([-1.1 1.1]);
 456 
            legend(chart(legend2plot), legendCell(legend2plot), 'Location','northwest');
 457 
        end
 458 
        if (sub_j==4)
 459 
            title('K Fraction Choices of Total K Possible');
 460 
            ylabel('K/(W-bar(b)) ');
 461 
            xlabel({'Total Savings w=k+b'});
 462 
            %             set(gca, 'YScale', 'log');
 463 
            ylim([0 1.1]);
 464 
            legend(chart(legend2plot), legendCell(legend2plot), 'Location','northeast');
 465 
        end
 466 
        
 467 
    end
 468 
    
 469 
    % save file
 470 
    if (bl_img_save)
 471 
        mkdir(support_map('st_img_path'));
 472 
        st_file_name = [st_img_prefix st_img_name_main '_wkbopti' st_img_suffix];
 473 
        saveas(gcf, strcat(st_img_path, st_file_name));
 474 
    end
 475 
    
 476 
end
 477 

  0.004 
     75 
 478
end 

Other subfunctions in this file are not included in this listing.