This is a static copy of a profile report

Home

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

Home

ffs_fibs_inf_bridge (Calls: 17010, Time: 0.175 s)
Generated 14-Jul-2019 14:56:02 using performance time.
function in file C:\Users\fan\CodeDynaAsset\m_fibs\paramfunc_fibs\ffs_fibs_inf_bridge.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
ff_abzr_fibs_vffunction17010
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
70
[bl_b_is_principle, fl_r_bridg...
170100.080 s45.6%
121
ar_b_bridge(ar_coh_today<0)...
170100.035 s20.0%
161
end
170100.023 s13.4%
110
ar_b_bridge = zeros(size(ar_co...
170100.012 s6.7%
67
if (~isempty(varargin))
170100.001 s0.7%
All other lines  0.024 s13.6%
Totals  0.175 s100% 
Children (called functions)
No children
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function155
Non-code lines (comments, blank lines)113
Code lines (lines that can run)42
Code lines that did run12
Code lines that did not run30
Coverage (did run/can run)28.57 %
Function listing
time 
Calls 
 line
   7 
function [ar_aprime_nobridge, ar_b_bridge, ar_c_bridge] = ffs_fibs_inf_bridge(varargin)
   8 
%% FFS_FIBS_INF_BRIDGE Amount of Informal Borrowing Needed as Bridge Loans
   9 
% Bridge loan needed to pay for debt that is still unpaid due to
  10 
% insufficient cash on hand. Potentially, only informal lender is willing
  11 
% to extend this loan offers. So some existing debts are paid back with
  12 
% revenue, parts that revenue can not cover is paid back potentially with
  13 
% informal borrowing. This works with single and multiple assets.
  14 
%
  15 
% @param bl_b_is_principle boolean solving with aggregate save/borr as
  16 
% principles + interests, or just principles no interests. If true,
  17 
% principels only, no interests. These refer to the _ar_aprime_ vector.
  18 
%
  19 
% @param fl_r_bridge float interest rate for bridge loan
  20 
%
  21 
% @param fl_r_fsv float (formal) savings interest rate
  22 
%
  23 
% @param fl_r_fbr float borrowing interest rate
  24 
%
  25 
% @param ar_aprime array N by 1 level of aggregate borrowing including
  26 
% potentially bridge loan. Note that bridge loan is needed if coh is
  27 
% negative and households can not pay back principle and interests.
  28 
%
  29 
% @param ar_coh_today array N by 1 the level of cash-on-hand today, when the
  30 
% borrowing and savings decisions are made. If this is positive, then
  31 
% households freely borrow, do not need bridge loans. If this is negative
  32 
% households need to first borrow to meet bridge loan needs.
  33 
%
  34 
% @return ar_aprime_nobridge array next period asset choice without debt
  35 
% incurred for bridge loans. This is the difference between _ar_coh_today_
  36 
% and _ar_b_bridge_.
  37 
%
  38 
% @return ar_b_bridge array bridge loan debt to pay for unpaid uncovered
  39 
% cash-on-hand. Includes interests and principle if _bl_b_is_principle_ is
  40 
% false. If _bl_b_is_principle_ is true, only includes principle.
  41 
%
  42 
% @return ar_c_bridge array consumption gain (for today) from bridge loan,
  43 
% or consumption costs (for next period) of bridge loans. Both consider the
  44 
% impact of principles as well as interest rates on bridge loans.
  45 
%
  46 
% @example
  47 
%
  48 
%   bl_input_override = true;
  49 
%   [ar_aprime_nobridge, ar_c_bridge] = ...
  50 
%        ffs_fibs_inf_bridge(bl_b_is_principle, fl_r_bridge, ...
  51 
%                              ar_aprime, ar_coh_today, ...
  52 
%                              bl_display_infbridge, bl_input_override);
  53 
%
  54 
% @seealso
  55 
%
  56 
% * Formal Borrowing Grid: <https://fanwangecon.github.io/CodeDynaAsset/m_fibs/paramfunc_fibs/html/ffs_for_br_block_gen.html ffs_for_br_block_gen>
  57 
% * Informal Interest Rates: <https://fanwangecon.github.io/CodeDynaAsset/m_fibs/paramfunc_fibs/html/ffs_r_inf.html ffs_r_inf>
  58 
% * Match Borrowing to Formal Grid: <https://fanwangecon.github.io/CodeDynaAsset/m_fibs/paramfunc_fibs/html/ffs_for_br_block_match.html ffs_for_br_block_match>
  59 
% * Optimize Formal and Informal, Borrowing and Savings Joint Choices: <https://fanwangecon.github.io/CodeDynaAsset/m_fibs/paramfunc_fibs/html/ffs_fibs_min_c_cost.html ffs_fibs_min_c_cost>
  60 
% * Bridge Loan: <https://fanwangecon.github.io/CodeDynaAsset/m_fibs/paramfunc_fibs/html/ffs_fibs_inf_bridge.html ffs_fibs_inf_bridge>
  61 
% * Overall Optimization: <https://fanwangecon.github.io/CodeDynaAsset/m_fibs/paramfunc_fibs/html/ffs_fibs_min_c_cost_bridge.html ffs_fibs_min_c_cost_bridge>
  62 
% * Discrete Choices: <https://fanwangecon.github.io/CodeDynaAsset/m_fibs/paramfunc_fibs/html/ffs_fibs_identify_discrete.html ffs_fibs_identify_discrete>
  63 
%
  64 

  65 
%% Default and Parse Parameters
  66 

  0.001 
  17010 
  67
if (~isempty(varargin)) 
  68 
    
  69 
    % override when called from outside
  0.080 
  17010 
  70
    [bl_b_is_principle, fl_r_bridge, ar_aprime, ar_coh_today, bl_display_infbridge] = varargin{:}; 
  71 
    
  72 
else
  73 
    close all
  74 

  75 
    % Default
  76 
    it_param_set = 4;
  77 
    [param_map, ~] = ffs_ipwkbz_fibs_set_default_param(it_param_set);
  78 

  79 
    % Gather Inputs from param_map
  80 
    params_group = values(param_map, {'bl_b_is_principle', 'fl_r_inf'});
  81 
    [bl_b_is_principle, fl_r_inf] = params_group{:};
  82 
    % bl_b_is_principle = true;
  83 
    
  84 
    % For benchmark, assume that the informal lender
  85 
    fl_r_bridge = fl_r_inf;
  86 

  87 
    % Testing COH and Aprime Vectors
  88 
    ar_aprime =    [-20. -5,-5, -4.5,-4.5, -0.1,-0.1]';
  89 
    ar_coh_today = [-19, 1, -1,   1,-1,      1,0 ]';
  90 
    
  91 
%     % Testing COH and Aprime coh is row vector, aprime is column vector
  92 
%     ar_aprime =    linspace(-5, 10, 5)';
  93 
%     ar_coh_today = linspace(-10, 0, 10);
  94 

  95 
    % Set Display Control
  96 
    bl_display_infbridge = true;
  0.001 
  17010 
  97
end 
  98 

  99 
%% Bridge Loan Required
 100 
% when coh <= cmin/0. Income does not fully repay debts. Suppose formal
 101 
% lenders have strict rules about not allowing for roll-over. Then when
 102 
% this happens, households would go to default state if default is allowed.
 103 
% If default is not allowed, households would never borrow such that coh
 104 
% ends up lower than 0. But now informal lender comes in and is willing to
 105 
% offer bridge loan. This bridge loan might be a fraction of total debt
 106 
% taken out last period, and it will become share of the debt carried on
 107 
% today. Or households after using bridge loan to cover debt, actually end
 108 
% up saving in net.
 109 

  0.012 
  17010 
 110
ar_b_bridge = zeros(size(ar_coh_today)); 
 111 

< 0.001 
  17010 
 112
if (bl_b_is_principle) 
 113 

 114 
    % c_bridge is cost of borrowing in next period consumption
 115 
    ar_b_bridge(ar_coh_today<0) = ar_coh_today(ar_coh_today<0);
 116 
    ar_c_bridge = ar_b_bridge.*(1+fl_r_bridge);
 117 

< 0.001 
  17010 
 118
else 
 119 

 120 
    % c_bridge is the gain from borrowing in current period consumption
  0.035 
  17010 
 121
    ar_b_bridge(ar_coh_today<0) = ar_coh_today(ar_coh_today<0).*(1+fl_r_bridge); 
< 0.001 
  17010 
 122
    ar_c_bridge = (-1)*ar_b_bridge./(1+fl_r_bridge); 
 123 

< 0.001 
  17010 
 124
end 
 125 

 126 
% remaining aprime after allocating to pay debt not covered by coh
< 0.001 
  17010 
 127
ar_aprime_nobridge = ar_aprime - ar_b_bridge; 
 128 

 129 
%% Display
< 0.001 
  17010 
 130
if (bl_display_infbridge) 
 131 
        
 132 
    disp(['bl_b_is_principle:', num2str(bl_b_is_principle)]);
 133 
    disp(['fl_r_bridge:', num2str(fl_r_bridge)]);
 134 
    disp(['ar_aprime:', num2str(ar_aprime')]);
 135 
    disp(['ar_b_bridge:', num2str(ar_coh_today')]);
 136 
    disp(['bl_display_infbridge:', num2str(bl_display_infbridge)]);
 137 

 138 
    tab_aprime_bridge = table(ar_coh_today, ar_aprime, ar_b_bridge, ar_c_bridge, ar_aprime_nobridge);
 139 
    tab_aprime_bridge.Properties.VariableDescriptions{'ar_coh_today'} = ...
 140 
        '*ar_coh_today*: cash on hand someone arrives in the period with given debt and current income';
 141 
    tab_aprime_bridge.Properties.VariableDescriptions{'ar_aprime'} = ...
 142 
        '*ar_aprime*: func called during finding optimal aprime, this is the current aprime overall choice';
 143 
    tab_aprime_bridge.Properties.VariableDescriptions{'ar_b_bridge'} = ...
 144 
        '*ar_b_bridge*: amount of bridge loan required to cover negative coh (includes interest if bl_b_is_principle = false)';
 145 
    tab_aprime_bridge.Properties.VariableDescriptions{'ar_c_bridge'} = ...
 146 
        '*ar_c_bridge*: consumption gain today from the bridge loan to cover negative coh; or consumption cost tomorrow for debt which increases c today';
 147 
    tab_aprime_bridge.Properties.VariableDescriptions{'ar_aprime_nobridge'} = ...
 148 
        ['*ar_aprime_nobridge*ar_aprime_nobridge:' ...
 149 
         'aprime = -10, -5 for bridge; -5 left for other borrowing choices;' ...
 150 
         'aprime = -10, -11 for bridge (given r), +1 savings left, reduces consumption, back to neg coh, infeasible state;'];
 151 
    
 152 
    disp(tab_aprime_bridge);
 153 
    sc_summary = summary(tab_aprime_bridge);
 154 
    cl_var_name = fieldnames(sc_summary);
 155 
    for it_var_name = 1:length(cl_var_name)
 156 
        disp(sc_summary.(cl_var_name{it_var_name}).Description);
 157 
    end
 158 
    
 159 
end
 160 

  0.023 
  17010 
 161
end 

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