-
Notifications
You must be signed in to change notification settings - Fork 12
/
ff_ipwkbzr_ds_wrapper.m
157 lines (119 loc) · 4.75 KB
/
ff_ipwkbzr_ds_wrapper.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
%% Derive Distributions for Risky + Safe Asset (Save + Borr + R Shock) Interpolated-Percentage (Wrapper)
% *back to <https://fanwangecon.github.io Fan>'s
% <https://fanwangecon.github.io/CodeDynaAsset/ Dynamic Assets Repository>
% Table of Content.*
%%
function [result_map] = ff_ipwkbzr_ds_wrapper(varargin)
%% FF_IPWKBZR_DS_WRAPPER finds the stationary asset distributions
% This is a warpper function.
%% Default
% # it_subset = 5 is basic invoke quick test
% # it_subset = 6 is invoke full test
% # it_subset = 7 is profiling invoke
% # it_subset = 8 is matlab publish
% # it_subset = 9 is invoke operational (only final stats) and coh graph
it_param_set = 8;
[param_map, support_map] = ffs_ipwkbzr_set_default_param(it_param_set);
param_map('bl_default') = true;
%% Change Parameter to Main Options
st_param_which = 'default';
if (ismember(st_param_which, ["default"]))
% default
elseif ismember(st_param_which, ["ff_ipwkbz_ds_wrapper"])
% ff_ipwkbzr_evf default
param_map('fl_z_r_borr_min') = 0.095;
param_map('fl_z_r_borr_max') = 0.095;
param_map('fl_z_r_borr_n') = 1;
param_map('fl_r_save') = 0.025;
param_map('it_z_n') = param_map('it_z_wage_n') * param_map('fl_z_r_borr_n');
end
%% Adjust Parametesr
% Note: param_map and support_map can be adjusted here or outside to override defaults
% param_map('it_w_perc_n') = 50;
% param_map('it_ak_perc_n') = param_map('it_w_perc_n');
% param_map('it_z_n') = 15;
% param_map('fl_coh_interp_grid_gap') = 0.025;
% param_map('it_c_interp_grid_gap') = 0.001;
% param_map('fl_w_interp_grid_gap') = 0.25;
% param_map('it_w_perc_n') = 100;
% param_map('it_ak_perc_n') = param_map('it_w_perc_n');
% param_map('it_z_n') = 11;
% param_map('fl_coh_interp_grid_gap') = 0.1;
% param_map('it_c_interp_grid_gap') = 10^-4;
% param_map('fl_w_interp_grid_gap') = 0.1;
% param_map('it_w_perc_n') = 100;
% param_map('fl_r_save') = 0.025;
% param_map('fl_c_min') = 0.02;
%% Set Distribution Derivation Types
% param_map('st_analytical_stationary_type') = 'loop';
% param_map('st_analytical_stationary_type') = 'vector';
param_map('st_analytical_stationary_type') = 'eigenvector';
%% Generate Grids
% get armt and func map
[armt_map, func_map] = ffs_ipwkbzr_get_funcgrid(param_map, support_map); % 1 for override
default_params = {param_map support_map armt_map func_map};
%% Parse Parameters 1
% if varargin only has param_map and support_map,
params_len = length(varargin);
[default_params{1:params_len}] = varargin{:};
param_map = [param_map; default_params{1}];
support_map = [support_map; default_params{2}];
if params_len >= 1 && params_len <= 2
% If override param_map, re-generate armt and func if they are not
% provided
[armt_map, func_map] = ffs_ipwkbzr_get_funcgrid(param_map, support_map);
else
% Override all
armt_map = [armt_map; default_params{3}];
func_map = [func_map; default_params{4}];
end
% if profile, profile DP + Dist here
support_map('bl_profile_dist') = false;
% append function name
st_func_name = 'ff_ipwkbzr_ds_wrapper';
support_map('st_profile_name_main') = [st_func_name support_map('st_profile_name_main')];
support_map('st_mat_name_main') = [st_func_name support_map('st_mat_name_main')];
support_map('st_img_name_main') = [st_func_name support_map('st_img_name_main')];
%% Parse Parameters
% param_map
params_group = values(param_map, {'st_analytical_stationary_type'});
[st_analytical_stationary_type] = params_group{:};
% support_map
params_group = values(support_map, ...
{'st_profile_path', 'st_profile_prefix', 'st_profile_name_main', 'st_profile_suffix','bl_time'});
[st_profile_path, st_profile_prefix, st_profile_name_main, st_profile_suffix, bl_time] = params_group{:};
%% Start Profiler and Timer
% Start Profile
if (it_param_set == 7)
close all;
profile off;
profile on;
end
% Start Timer
if (bl_time)
tic;
end
%% Solve DP
bl_input_override = true;
result_map = ff_ipwkbzr_vf_vecsv(param_map, support_map, armt_map, func_map);
%% Derive Distribution
if (strcmp(st_analytical_stationary_type, 'loop'))
result_map = ff_iwkz_ds(param_map, support_map, armt_map, func_map, result_map, bl_input_override);
elseif (strcmp(st_analytical_stationary_type, 'vector'))
result_map = ff_iwkz_ds_vec(param_map, support_map, armt_map, func_map, result_map, bl_input_override);
elseif (strcmp(st_analytical_stationary_type, 'eigenvector'))
result_map = ff_iwkz_ds_vecsv(param_map, support_map, armt_map, func_map, result_map, bl_input_override);
end
%% End Profiler and Timer
% End Timer
if (bl_time)
toc;
end
% End Profile
if (it_param_set == 7)
profile off
profile viewer
st_file_name = [st_profile_prefix st_profile_name_main st_profile_suffix];
profsave(profile('info'), strcat(st_profile_path, st_file_name));
end
end