-
Notifications
You must be signed in to change notification settings - Fork 12
/
ffs_abzr_fibs_set_functions.m
175 lines (141 loc) · 5.78 KB
/
ffs_abzr_fibs_set_functions.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
%% Set Model Functions (ABZR FIBS)
% *back to <https://fanwangecon.github.io Fan>'s
% <https://fanwangecon.github.io/CodeDynaAsset/ Dynamic Assets Repository>
% Table of Content.*
%%
function [f_util_log, f_util_crra, f_util_standin, f_inc, f_coh, f_cons_coh_fbis, f_cons_coh_save, f_bprime] = ...
ffs_abzr_fibs_set_functions(varargin)
%% FFS_ABZ_SET_FIBS_FUNCTIONS setting model functions
% Define functions for the abzr problem with formal and informal borrowing
% and savings. See here:
% <https://fanwangecon.github.io/CodeDynaAsset/m_abzr/paramfunc/html/ffs_abzr_set_functions.html
% ffs_abzr_set_functions> for *abzr* function settings without without formal
% and informal considerations. Note, param_map('bl_b_is_principle') =
% false for _abzr_fibs_.
%
% @param fl_crra float crra utility
%
% @param fl_c_min float minimum consumption
%
% @param fl_r_fbr float formal borrowing interest rate
%
% @param fl_r_fsv float savings interest rates
%
% @param fl_w float wage rate
%
% @return f_util_log handle log utility
%
% @return f_util_crra handle crra utility general
%
% @return f_util_standin handle log utility with coh for testing graphing codes
%
% @return f_inc income handle equation wage and interests
%
% @return f_coh_fbis handle cash on hand equation given current period
% shock and formal and informal borrowing and savings choices.
%
% @return f_cons_coh_fbis handle consumption given cash on hand and formal
% and informal borrowing and savings choices.
%
% @return f_bprime handle aggregate borrowing and savings principles
%
% @example
%
% [f_util_log, f_util_crra, f_util_standin, f_inc, f_coh_fbis, f_cons_coh_fbis] = ...
% ffs_abzr_set_functions(fl_crra, fl_c_min, fl_r_fbr, fl_r_fsv, fl_w);
%
%% Default
if (isempty(varargin))
bl_display_setfunc = true;
else
bl_display_setfunc = false;
end
[fl_crra, fl_c_min] = deal(1, 0.001);
[fl_r_fbr, fl_r_fsv, fl_w] = deal(0.035, 0.025, 1.28);
bl_b_is_principle = false;
default_params = {fl_crra fl_c_min fl_r_fbr fl_r_fsv fl_w bl_display_setfunc};
%% Parse Parameters
% numvarargs is the number of varagin inputted
[default_params{1:length(varargin)}] = varargin{:};
[fl_crra, fl_c_min, fl_r_fbr, fl_r_fsv, fl_w, bl_display_setfunc] = default_params{:};
%% Define Utility Functions
f_util_log = @(c) log(c);
f_util_crra = @(c) (((c).^(1-fl_crra)-1)./(1-fl_crra));
%% Define Income Equation
if (bl_b_is_principle)
f_inc = @(ar_z, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save) ...
(ar_z*fl_w ...
+ (ar_for_borr.*(fl_r_fbr) ...
+ ar_inf_borr.*(fl_r_inf) ...
+ ar_for_save.*(fl_r_fsv)));
else
f_inc = @(ar_z, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save) ...
(ar_z*fl_w ...
+ ((ar_for_borr./(1+fl_r_fbr))*fl_r_fbr ...
+ (ar_inf_borr./(1+fl_r_inf))*fl_r_inf ...
+ (ar_for_save./(1+fl_r_fsv))*fl_r_fsv));
end
if (bl_display_setfunc)
disp('f_inc')
disp(f_inc)
[ar_z, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save] = deal(1, 0.06, -1, -0.33, 0);
fl_inc = f_inc(ar_z, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save);
fprintf('fl_inc=%.3f\nwith fl_r_inf:%.3f, ar_for_borr:%.3f, ar_inf_borr:%.3f, ar_for_save:%.3f',...
fl_inc, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save);
end
%% Define Cash on Hand Current Period
if (bl_b_is_principle)
f_coh = @(ar_z, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save) ...
(ar_z*fl_w ...
+ (ar_for_borr.*(1+fl_r_fbr) ...
+ ar_inf_borr.*(1+fl_r_inf) ...
+ ar_for_save.*(1+fl_r_fsv)));
else
f_coh = @(ar_z, ar_b) (ar_z*fl_w + ar_b);
end
if (bl_display_setfunc)
disp('f_coh_fbis')
disp(f_coh)
if (bl_b_is_principle)
[ar_z, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save] = deal(1, 0.06, -1, -0.33, 0);
fl_coh_fbis = f_coh(ar_z, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save);
fprintf('fl_coh_fbis=%.3f\nwith fl_r_inf:%.3f, ar_for_borr:%.3f, ar_inf_borr:%.3f, ar_for_save:%.3f',...
fl_coh_fbis, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save);
end
end
%% Define Consumption
if (bl_b_is_principle)
% ar_for_borr, ar_inf_borr, ar_for_save are choices
f_cons_coh_fbis = @(coh, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save) ...
(coh + (ar_for_borr + ar_inf_borr + ar_for_save));
f_cons_coh_save = @(coh, ar_for_save) (coh - ar_for_save);
f_bprime = @(fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save) ...
(ar_for_borr + ar_inf_borr + ar_for_save);
else
% ar_bprime_in_c: array of b prime choice in current consumption units
f_cons_coh_fbis = @(coh, ar_bprime_in_c) (coh + ar_bprime_in_c);
f_cons_coh_save = @(coh, ar_for_save) (coh - ar_for_save./(1+fl_r_fsv));
f_bprime = @(fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save) ...
(ar_for_borr./(1+fl_r_fbr) ...
+ ar_inf_borr./(1+fl_r_inf) ...
+ ar_for_save./(1+fl_r_fsv));
end
if (bl_display_setfunc)
disp('f_cons_coh_fbis')
disp(f_cons_coh_fbis)
if (bl_b_is_principle)
% current period states
[ar_z, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save] = deal(1, 0.06, -1, -0.33, 0);
fl_coh_fbis = f_coh(ar_z, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save);
% current period choices
[ar_for_borr, ar_inf_borr, ar_for_save] = deal(-1, -0.33, 0);
fl_cons_coh_fbis = f_cons_coh_fbis(fl_coh_fbis, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save);
% display
fprintf('fl_cons_coh_fbis=%.3f\nwith fl_r_inf:%.3f, ar_for_borr:%.3f, ar_inf_borr:%.3f, ar_for_save:%.3f',...
fl_cons_coh_fbis, fl_r_inf, ar_for_borr, ar_inf_borr, ar_for_save);
end
end
%% Defome Stand-in Utility for Testing
f_coh_simple = @(ar_z, ar_b) (ar_z*fl_w + ar_b);
f_util_standin = @(z, b) f_util_log(f_coh_simple(z, b).*(f_coh_simple(z, b) > 0) + fl_c_min.*(f_coh_simple(z, b) <= 0));
end