time | Calls | line |
---|
| | 7 | function [ar_forbrblk, ar_forbrblk_r] = ffs_for_br_block_gen(varargin)
|
| | 8 | %% FFS_FOR_BR_BLOCK_GEN formal borrowing blocks
|
| | 9 | % Grid of formal borrowing points with associated interest rates. Policies
|
| | 10 | % could shift this. This function could be invoked to generate multiple
|
| | 11 | % formal borrowing grids from multiple formal borrowing providers, and the
|
| | 12 | % overall formal borrowing choice set is a combination of these grids.
|
| | 13 | %
|
| | 14 | % @param fl_r_fbr boolean single formal borrowing interest rate
|
| | 15 | %
|
| | 16 | % @param st_forbrblk_type string different formal borrowing grid
|
| | 17 | % structures, some for testing/illustration purposes. Estimation uses real
|
| | 18 | % observed blocks from data.
|
| | 19 | %
|
| | 20 | % @param st_forbrblk_type string different formal borrowing grid
|
| | 21 | % structures, some for testing/illustration purposes. Estimation uses real
|
| | 22 | % observed blocks from data.
|
| | 23 | %
|
| | 24 | % # *unif*: uniform grid equal gap from min to
|
| | 25 | % # *seg3*: three segment blocks, the first 1/3 gap of the third segement,
|
| | 26 | % respect min and max from fl_forbrblk_brmost and fl_forbrblk_brleast,
|
| | 27 | % smallest borrowing segment gap is fl_forbrblk_gap
|
| | 28 | %
|
| | 29 | % @param fl_forbrblk_brmost float maximum formal borrowing allowed on grid,
|
| | 30 | % , might not not be relevant for all _st_forbrblk_type_
|
| | 31 | %
|
| | 32 | % @param fl_forbrblk_brleast float minimum formal borrowing allowed on
|
| | 33 | % grid, might not be relevant for all _st_forbrblk_type_
|
| | 34 | %
|
| | 35 | % @param fl_forbrblk_gap float formal borrowing grid gap, means different
|
| | 36 | % things for different _st_forbrblk_type_
|
| | 37 | %
|
| | 38 | % @return ar_forbrblk array array of formal borrowing grid points. should
|
| | 39 | % be ordered from lowest to highest including zero at the top. i.e.: [-4,
|
| | 40 | % -2, -1, 0]. These are assumed to be in principles units always.
|
| | 41 | % PRINCIPLES only, do not include interest rates.
|
| | 42 | %
|
| | 43 | % @return ar_forbrblk_r array interest rates associated with equal-length
|
| | 44 | % _ar_forbrblk_. ar_forbrblk_r multiplied element-wise with ar_forbrblk
|
| | 45 | % will provide the principle + interest rates associated with each formal
|
| | 46 | % borrowing grid elements.
|
| | 47 | %
|
| | 48 | % @example
|
| | 49 | %
|
| | 50 | % [ar_forbrblk, ar_forbrblk_r] = ...
|
| | 51 | % ffs_for_br_block_gen(fl_r_fbr, st_forbrblk_type, fl_forbrblk_brmost, fl_forbrblk_brleast, fl_forbrblk_gap);
|
| | 52 | %
|
| | 53 | % @seealso
|
| | 54 | %
|
| | 55 | % * Formal Borrowing Grid: <https://fanwangecon.github.io/CodeDynaAsset/m_fibs/paramfunc_fibs/html/ffs_for_br_block_gen.html ffs_for_br_block_gen>
|
| | 56 | % * Informal Interest Rates: <https://fanwangecon.github.io/CodeDynaAsset/m_fibs/paramfunc_fibs/html/ffs_r_inf.html ffs_r_inf>
|
| | 57 | % * 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>
|
| | 58 | % * 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>
|
| | 59 | % * Bridge Loan: <https://fanwangecon.github.io/CodeDynaAsset/m_fibs/paramfunc_fibs/html/ffs_fibs_inf_bridge.html ffs_fibs_inf_bridge>
|
| | 60 | % * 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>
|
| | 61 | % * Discrete Choices: <https://fanwangecon.github.io/CodeDynaAsset/m_fibs/paramfunc_fibs/html/ffs_fibs_identify_discrete.html ffs_fibs_identify_discrete>
|
| | 62 | %
|
| | 63 |
|
| | 64 |
|
| | 65 | %% Default
|
| | 66 |
|
0.004 | 57729 | 67 | fl_r_fbr = 0.045;
|
0.335 | 57729 | 68 | [st_forbrblk_type, fl_forbrblk_brmost, fl_forbrblk_brleast, fl_forbrblk_gap] = deal('seg3', -19, -1, -1.5);
|
0.003 | 57729 | 69 | bl_display_forbrblock = false;
|
0.091 | 57729 | 70 | default_params = {fl_r_fbr st_forbrblk_type fl_forbrblk_brmost fl_forbrblk_brleast fl_forbrblk_gap ...
|
| 57729 | 71 | bl_display_forbrblock};
|
| | 72 |
|
| | 73 | %% Parse Parameters
|
| | 74 |
|
| | 75 | % numvarargs is the number of varagin inputted
|
0.216 | 57729 | 76 | [default_params{1:length(varargin)}] = varargin{:};
|
0.194 | 57729 | 77 | [fl_r_fbr, st_forbrblk_type, fl_forbrblk_brmost, fl_forbrblk_brleast, fl_forbrblk_gap, ...
|
| 57729 | 78 | bl_display_forbrblock] = default_params{:};
|
| | 79 |
|
| | 80 | %% Set Formal Borrowing Grid Uniform
|
| | 81 |
|
0.056 | 57729 | 82 | if (strcmp(st_forbrblk_type, 'unif'))
|
| | 83 | ar_forbrblk = fl_forbrblk_brleast:fl_forbrblk_gap:fl_forbrblk_brmost;
|
| | 84 | end
|
| | 85 |
|
| | 86 | %% Set Formal Borrowing Grid Three Segment
|
| | 87 | % An example grid with three segments, the first segement has
|
| | 88 | % fl_forbrblk_gap as gap, the second segment gap is twice, the third
|
| | 89 | % segement the gap is 3 times as large as fl_forbrblk_gap. Respect
|
| | 90 | % fl_forbrblk_brmost fl_forbrblk_brleast, which means divided into three
|
| | 91 | % parts based on them as much as possible
|
| | 92 |
|
0.022 | 57729 | 93 | if (strcmp(st_forbrblk_type, 'seg3'))
|
0.004 | 57729 | 94 | fl_most_least_gap = (fl_forbrblk_brmost - fl_forbrblk_brleast);
|
0.003 | 57729 | 95 | fl_most_least_seg3_interval = fl_most_least_gap/3;
|
| | 96 |
|
0.040 | 57729 | 97 | ar_seg1 = fl_forbrblk_brleast:fl_forbrblk_gap:fl_most_least_seg3_interval;
|
0.032 | 57729 | 98 | ar_seg2 = max(ar_seg1):(fl_forbrblk_gap*2):fl_most_least_seg3_interval*2;
|
0.024 | 57729 | 99 | ar_seg3 = max(ar_seg2):(fl_forbrblk_gap*3):fl_forbrblk_brmost;
|
| | 100 |
|
0.098 | 57729 | 101 | ar_forbrblk =[ar_seg1, ar_seg2, ar_seg3];
|
0.003 | 57729 | 102 | end
|
| | 103 |
|
| | 104 | %% Set Formal Borrowing Grid Three Segment
|
| | 105 | % An example grid with three segments, the first segement has
|
| | 106 | % fl_forbrblk_gap as gap, the second segment gap is twice, the third
|
| | 107 | % segement the gap is 3 times as large as fl_forbrblk_gap. Respect
|
| | 108 | % fl_forbrblk_brmost fl_forbrblk_brleast, which means divided into three
|
| | 109 | % parts based on them as much as possible
|
| | 110 |
|
0.025 | 57729 | 111 | if (strcmp(st_forbrblk_type, 'testfx'))
|
| | 112 | fl_most_least_gap = (fl_forbrblk_brmost - fl_forbrblk_brleast);
|
| | 113 | fl_most_least_seg3_interval = fl_most_least_gap/3;
|
| | 114 |
|
| | 115 | ar_seg1 = fl_forbrblk_brleast:fl_forbrblk_gap:fl_most_least_seg3_interval;
|
| | 116 | ar_seg2 = max(ar_seg1):(fl_forbrblk_gap*2):fl_most_least_seg3_interval*2;
|
| | 117 | ar_seg3 = max(ar_seg2):(fl_forbrblk_gap*3):fl_forbrblk_brmost;
|
| | 118 |
|
| | 119 | ar_forbrblk =[-3 -6];
|
| | 120 | end
|
| | 121 |
|
| | 122 |
|
| | 123 | %% Sort Borrowing Blocks
|
| | 124 |
|
| | 125 | % add zero because formal borrowing = 0 should be an option
|
0.060 | 57729 | 126 | ar_forbrblk = [-0 ar_forbrblk];
|
1.507 | 57729 | 127 | ar_forbrblk = sort(unique([ar_forbrblk]));
|
| | 128 |
|
| | 129 | %% Generate Corresponding Interest Rates Arrays
|
0.064 | 57729 | 130 | ar_forbrblk_r = fl_r_fbr + zeros(size(ar_forbrblk));
|
| | 131 |
|
0.003 | 57729 | 132 | if (bl_display_forbrblock)
|
| | 133 | disp('ar_forbrblk');
|
| | 134 | disp(ar_forbrblk);
|
| | 135 | disp('ar_forbrblk_r');
|
| | 136 | disp(ar_forbrblk_r);
|
| | 137 | end
|
| | 138 |
|
0.095 | 57729 | 139 | end
|
Other subfunctions in this file are not included in this listing.