time | Calls | line |
---|
| | 16 | function [mt_vf, mt_pf, mt_oploc, mt_o, mt_k, mt_l]=hhsave_VFI_2OC(varargin)
|
| | 17 |
|
< 0.001 | 1 | 18 | bl_profile = false; % Switch off profile if running a tester/calling from another function
|
< 0.001 | 1 | 19 | bl_saveimg = true;
|
< 0.001 | 1 | 20 | if(bl_profile)
|
| | 21 | profile off;
|
| | 22 | profile on;
|
| | 23 | end
|
| | 24 |
|
0.426 | 1 | 25 | addpath(genpath('/Users/sidhantkhanna/Documents/GitHub/BKS modified/'));
|
| | 26 |
|
< 0.001 | 1 | 27 | if ~isempty(varargin)
|
| | 28 |
|
< 0.001 | 1 | 29 | [ar_a,ar_z, ...
|
| 1 | 30 | fl_alpha,fl_theta,fl_delta,fl_kappa,fl_r,fl_w,fl_phi,fl_ahi,fl_zhi, ...
|
| 1 | 31 | fl_risk,it_zgridno, it_agridno,mt_trans_z,fl_beta, fl_mu, fl_sig,fl_rho, fl_tolvfi ...
|
| 1 | 32 | ] = varargin{:};
|
| | 33 |
|
< 0.001 | 1 | 34 | bl_print = false;
|
< 0.001 | 1 | 35 | bl_plot = false;
|
| | 36 |
|
| | 37 |
|
| | 38 | else
|
| | 39 | close all;
|
| | 40 |
|
| | 41 | fl_ahi = 50;
|
| | 42 | fl_zhi = 1.8;
|
| | 43 | it_agridno = 15;
|
| | 44 | it_zgridno = 5;
|
| | 45 | ar_a = linspace(0,fl_ahi,it_agridno);
|
| | 46 | fl_phi = 0.3;
|
| | 47 | fl_risk = 1;
|
| | 48 | fl_alpha = 0.4;
|
| | 49 | fl_theta = 0.79-fl_alpha;
|
| | 50 | fl_delta = 0.05;
|
| | 51 | fl_kappa = 0;
|
| | 52 | fl_mu = 0; % mean of AR(1) entrepeneurial productivity process
|
| | 53 | fl_rho = 0.9; % persistence parameter of the AR(1) entrepreneurial productivity process
|
| | 54 | fl_sig = 0.2;
|
| | 55 | fl_lambda = 3;
|
| | 56 | fl_beta = 0.92;
|
| | 57 | [ar_z, mt_trans_z] = mytauchen_z(fl_mu,fl_rho,fl_sig,it_zgridno,fl_lambda);
|
| | 58 | ar_z = exp(ar_z);
|
| | 59 | [fl_r,fl_w] = ...
|
| | 60 | deal(0.05,2);
|
| | 61 | fl_tolvfi = 10^-12;
|
| | 62 | bl_print = false;
|
| | 63 | bl_plot = false;
|
| | 64 |
|
< 0.001 | 1 | 65 | end
|
| | 66 |
|
< 0.001 | 1 | 67 | fl_R = fl_r + fl_delta;
|
| | 68 |
|
| | 69 | %% Value function Iteration
|
| | 70 |
|
< 0.001 | 1 | 71 | mt_vf = zeros(it_agridno,it_zgridno); % Value function
|
< 0.001 | 1 | 72 | mt_Tv = zeros(it_agridno,it_zgridno); % Next guess of value function
|
< 0.001 | 1 | 73 | mt_oploc = zeros(it_agridno,it_zgridno); %
|
| | 74 |
|
2.843 | 1 | 75 | [mt_util, mt_coh, mt_k, mt_l, mt_o] = hhsave_util_2OC(ar_a,ar_z, ...
|
| 1 | 76 | fl_alpha,fl_theta,fl_delta,fl_kappa,fl_r,fl_w,fl_phi,fl_ahi,fl_zhi, ...
|
| 1 | 77 | fl_risk,it_zgridno, it_agridno);
|
| | 78 |
|
< 0.001 | 1 | 79 | fl_crit = 1; % difference between current and next guess of value function
|
| | 80 |
|
< 0.001 | 1 | 81 | while fl_crit > fl_tolvfi
|
0.003 | 717 | 82 | mt_evf = mt_vf*mt_trans_z';
|
0.002 | 717 | 83 | mt_ev1 = repmat(mt_evf, [1 1 it_agridno]);
|
0.002 | 717 | 84 | mt_ev1 = permute(mt_ev1,[3 2 1]);
|
| | 85 |
|
0.003 | 717 | 86 | [mt_Tvf,mt_oploc] = max((mt_util+fl_beta.*(mt_ev1)),[], 3);
|
| | 87 |
|
< 0.001 | 717 | 88 | mt_diff= mt_Tvf-mt_vf;
|
0.005 | 717 | 89 | fl_crit=norm(mt_diff);
|
< 0.001 | 717 | 90 | mt_vf = mt_Tvf;
|
< 0.001 | 717 | 91 | end
|
| | 92 |
|
| | 93 |
|
< 0.001 | 1 | 94 | mt_pf = ar_a(mt_oploc);
|
< 0.001 | 1 | 95 | mt_con = mt_coh - mt_pf;
|
| | 96 |
|
< 0.001 | 1 | 97 | if(bl_print)
|
| | 98 | disp('Below is the Value function');
|
| | 99 | disp(mt_vf);
|
| | 100 | disp('Below is the Policy Function');
|
| | 101 | disp(mt_pf);
|
| | 102 | disp('Below is the Location of optimal choice of assets');
|
| | 103 | disp(mt_oploc);
|
| | 104 | end
|
| | 105 |
|
| | 106 | %% Printing Outputs
|
| | 107 |
|
| | 108 | %% Plot Value function, Policy Function and Consumption
|
| | 109 |
|
| | 110 | % 3D Value function
|
< 0.001 | 1 | 111 | if(bl_plot)
|
| | 112 | figure(1)
|
| | 113 | chart=surf(ar_z,ar_a,mt_vf);
|
| | 114 | title('Value Function');
|
| | 115 | xlabel('Productivity') ;
|
| | 116 | ylabel('Assets');
|
| | 117 | zlabel('Value');
|
| | 118 | xt = get(gca, 'XTick');
|
| | 119 | set(gca, 'XTick', xt, 'XTickLabel', xt*fl_ahi/it_agridno);
|
| | 120 | if(bl_saveimg)
|
| | 121 | saveas(gcf, '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Households/figures/hhsave_VFI_2OC/Valuefunction_3D.png')
|
| | 122 | end
|
| | 123 |
|
| | 124 | % 2D Value function
|
| | 125 | figure(2)
|
| | 126 | %chart = plot(mt_vf);
|
| | 127 | for i = 1: it_zgridno
|
| | 128 | a(i) = plot((mt_vf(:,i,1)));
|
| | 129 | b{i} = sprintf(['Z shock =', num2str(ar_z(i))]);
|
| | 130 | hold on
|
| | 131 | end
|
| | 132 | legend(b,'Location','north')
|
| | 133 | %clr = jet(numel(chart));
|
| | 134 | %for m = 1:numel(chart)
|
| | 135 | % set(chart(m),'Color',clr(m,:))
|
| | 136 | %end
|
| | 137 | title('Value Function');
|
| | 138 | xlabel('Asset') ;
|
| | 139 | ylabel('Asset choice');
|
| | 140 | xt = get(gca, 'XTick');
|
| | 141 | set(gca, 'XTick', xt, 'XTickLabel', xt*fl_ahi/it_agridno);
|
| | 142 | if(bl_saveimg)
|
| | 143 | saveas(gcf, '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Households/figures/hhsave_VFI_2OC/Valuefunction_2D.png')
|
| | 144 | end
|
| | 145 |
|
| | 146 |
|
| | 147 | figure(3)
|
| | 148 | for i = 1: it_zgridno
|
| | 149 | a(i) = plot((mt_pf(:,i,1)));
|
| | 150 | b{i} = sprintf(['Z shock =', num2str(ar_z(i))]);
|
| | 151 | hold on
|
| | 152 | end
|
| | 153 | legend(b,'Location','north')
|
| | 154 | title('Policy Function');
|
| | 155 | xlabel('Asset') ;
|
| | 156 | ylabel('Asset choice');
|
| | 157 | xt = get(gca, 'XTick');
|
| | 158 | set(gca, 'XTick', xt, 'XTickLabel', xt*fl_ahi/it_agridno);
|
| | 159 | if(bl_saveimg)
|
| | 160 | saveas(gcf, '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Households/figures/hhsave_VFI_2OC/Policyfunction.png')
|
| | 161 | end
|
| | 162 |
|
| | 163 | figure(4)
|
| | 164 | for i = 1: it_zgridno
|
| | 165 | a(i) = plot((mt_con(:,i,1)));
|
| | 166 | b{i} = sprintf(['Z shock =', num2str(ar_z(i))]);
|
| | 167 | hold on
|
| | 168 | end
|
| | 169 | legend(b,'Location','north')
|
| | 170 | title('Consumption');
|
| | 171 | xlabel('Asset') ;
|
| | 172 | ylabel('Consumption');
|
| | 173 | xt = get(gca, 'XTick');
|
| | 174 | set(gca, 'XTick', xt, 'XTickLabel', xt*fl_ahi/it_agridno);
|
| | 175 | if(bl_saveimg)
|
| | 176 | saveas(gcf, '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Households/figures/hhsave_VFI_2OC/Consumption.png')
|
| | 177 | end
|
| | 178 |
|
| | 179 | end
|
| | 180 | %% Profile off
|
| | 181 |
|
< 0.001 | 1 | 182 | if(bl_profile)
|
| | 183 | profile off;
|
| | 184 | profile viewer;
|
| | 185 | st_file_name = '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Profile/Households/hhsave_VFI_2OC';
|
| | 186 | profsave(profile('info'), st_file_name);
|
| | 187 | end
|
Other subfunctions in this file are not included in this listing.