Value Function iteration
This function solves the dynamic infinite horizon optimal asset choice problem in case of 2 occupational choices - worker and entrepreneur
Back to full code page https://kritikhanna.github.io/BKS-modified/
Function Inputs : asset grid(1 by M) and entrepreneurial productivity grid(1 by N) relevant model parameters required Calls function hhsave_util_2OC.m
Function Outputs : Value function (MXNX1), Policy Function (MXNX1), Optimal Location of asset choice (MXNX1)
Contents
function [mt_vf, mt_pf, mt_oploc, mt_o, mt_k, mt_l]=hhsave_VFI_2OC(varargin)
bl_profile = false; % Switch off profile if running a tester/calling from another function bl_saveimg = true; if(bl_profile) profile off; profile on; end addpath(genpath('/Users/sidhantkhanna/Documents/GitHub/BKS modified/')); if ~isempty(varargin) [ar_a,ar_z, ... fl_alpha,fl_theta,fl_delta,fl_kappa,fl_r,fl_w,fl_phi,fl_ahi,fl_zhi, ... fl_risk,it_zgridno, it_agridno,mt_trans_z,fl_beta, fl_mu, fl_sig,fl_rho, fl_tolvfi ... ] = varargin{:}; bl_print = true; bl_plot = true; else close all; fl_ahi = 50; fl_zhi = 2.2; it_agridno = 100; it_zgridno = 7; ar_a = linspace(0,fl_ahi,it_agridno); fl_phi = 0.5; fl_risk = 1.5; fl_alpha = 0.4; fl_theta = 0.79-fl_alpha; fl_delta = 0.05; fl_kappa = 0; fl_mu = 0; % mean of AR(1) entrepeneurial productivity process fl_rho = 0.95; % persistence parameter of the AR(1) entrepreneurial productivity process fl_sig = 0.02; fl_lambda = 3; fl_beta = 0.96; [ar_z, mt_trans_z] = mytauchen_z(fl_mu,fl_rho,fl_sig,it_zgridno,fl_lambda); ar_z = ar_z'; ar_z = exp(ar_z); P1=mt_trans_z^1000; sd=P1(1,:); el=sum(sd.*ar_z ); ar_z =ar_z ./el; [fl_r,fl_w] = ... deal(0.02,0.9); fl_tolvfi = 10^-12; bl_print = true; bl_plot = true; end fl_R = fl_r + fl_delta;
Value function Iteration
mt_vf = zeros(it_agridno,it_zgridno); % Value function mt_Tv = zeros(it_agridno,it_zgridno); % Next guess of value function mt_oploc = zeros(it_agridno,it_zgridno); % [mt_util, mt_coh, mt_k, mt_l, mt_o] = hhsave_util_2OC(ar_a,ar_z, ... fl_alpha,fl_theta,fl_delta,fl_kappa,fl_r,fl_w,fl_phi,fl_ahi,fl_zhi, ... fl_risk,it_zgridno, it_agridno); fl_crit = 1; % difference between current and next guess of value function while fl_crit > fl_tolvfi mt_evf = mt_vf*mt_trans_z'; mt_ev1 = repmat(mt_evf, [1 1 it_agridno]); mt_ev1 = permute(mt_ev1,[3 2 1]); [mt_Tvf,mt_oploc] = max((mt_util+fl_beta.*(mt_ev1)),[], 3); mt_diff = mt_Tvf-mt_vf; fl_crit = norm(mt_diff); mt_vf = mt_Tvf; end mt_pf = ar_a(mt_oploc); mt_con = mt_coh - mt_pf; mt_savefraccoh = mt_pf./mt_coh; if(bl_print) st_ar_a = strsplit(num2str(ar_a)); for i=1:it_agridno st_a(i) =strcat('a=', st_ar_a(i)); end % st_ar_z = strsplit(num2str(ar_z)); disp('Table for value function'); tb_VF = array2table(mt_vf,'VariableNames',{'z1','z2','z3','z4','z5','z6','z7'}); tb_VF.Properties.RowNames = st_a; disp(tb_VF); disp('Table for Policy function'); tb_pf = array2table(mt_pf,'VariableNames',{'z1','z2','z3','z4','z5','z6','z7'}); tb_pf.Properties.RowNames = st_a; disp(tb_pf); disp('Table for savefraccoh'); tb_savefraccoh = array2table(mt_savefraccoh,'VariableNames',{'z1','z2','z3','z4','z5','z6','z7'}); tb_savefraccoh.Properties.RowNames = st_a; disp(tb_savefraccoh); disp('Table for Consumption'); tb_con = array2table(mt_con,'VariableNames',{'z1','z2','z3','z4','z5','z6','z7'}); tb_con.Properties.RowNames = st_a; disp(tb_con); end
Table for value function z1 z2 z3 z4 z5 z6 z7 ________ ________ ________ ________ ________ ________ _______ a=0 -2.6904 -2.6859 -2.6768 -2.6566 -2.5997 -2.3791 -1.0751 a=0.505051 -2.2634 -2.2589 -2.2499 -2.2296 -2.1214 -1.6053 0.37109 a=1.0101 -1.8476 -1.8431 -1.834 -1.8102 -1.5481 -0.43382 1.8802 a=1.51515 -1.4425 -1.438 -1.4287 -1.3684 -0.9494 0.80072 3.457 a=2.0202 -1.0477 -1.0432 -1.0311 -0.92384 -0.33172 2.1104 5.0195 a=2.52525 -0.66299 -0.65814 -0.6403 -0.38962 0.5438 3.4807 6.2061 a=3.0303 -0.28787 -0.28225 -0.24284 0.20798 1.591 4.584 7.1691 a=3.53535 0.078001 0.086333 0.21267 0.81447 2.608 5.5041 7.9821 a=4.0404 0.43519 0.45406 0.63685 1.3585 3.4869 6.294 8.6865 a=4.54545 0.78496 0.81777 1.0716 1.9288 4.2646 6.9856 9.3081 a=5.05051 1.128 1.1789 1.5848 2.6661 4.9507 7.6009 9.8644 a=5.55556 1.465 1.5451 2.0594 3.3223 5.5648 8.1552 10.368 a=6.06061 1.7976 1.9118 2.5016 3.9131 6.121 8.6597 10.827 a=6.56566 2.1265 2.2754 2.9162 4.4499 6.6301 9.1226 11.25 a=7.07071 2.452 2.6338 3.3067 4.9415 7.1001 9.5502 11.64 a=7.57576 2.7737 2.9853 3.6762 5.3948 7.5375 9.9475 12.003 a=8.08081 3.0916 3.3289 4.0287 5.816 7.9477 10.318 12.342 a=8.58586 3.405 3.664 4.3769 6.2134 8.3348 10.666 12.659 a=9.09091 3.7138 3.9915 4.7192 6.5896 8.7023 10.992 12.957 a=9.59596 4.0176 4.3118 5.0548 6.9467 9.0533 11.299 13.238 a=10.101 4.3163 4.6254 5.3828 7.2863 9.3897 11.588 13.504 a=10.6061 4.6098 4.9323 5.703 7.6074 9.7054 11.861 13.756 a=11.1111 4.8982 5.2328 6.0148 7.9111 10.002 12.119 13.996 a=11.6162 5.1814 5.5269 6.318 8.1988 10.282 12.365 14.225 a=12.1212 5.4595 5.8146 6.6124 8.4716 10.547 12.599 14.443 a=12.6263 5.7324 6.0959 6.898 8.7305 10.797 12.823 14.653 a=13.1313 6.0001 6.3709 7.1748 8.9764 11.034 13.037 14.854 a=13.6364 6.2628 6.6395 7.4429 9.2101 11.259 13.244 15.048 a=14.1414 6.5203 6.9018 7.7025 9.4402 11.477 13.443 15.235 a=14.6465 6.7727 7.1578 7.9542 9.6664 11.687 13.636 15.415 a=15.1515 7.02 7.4077 8.1988 9.8881 11.891 13.822 15.588 a=15.6566 7.2622 7.6514 8.4366 10.105 12.087 14.003 15.757 a=16.1616 7.4994 7.8893 8.6681 10.317 12.278 14.179 15.919 a=16.6667 7.7316 8.1214 8.8936 10.523 12.462 14.35 16.076 a=17.1717 7.9589 8.348 9.1133 10.725 12.64 14.518 16.228 a=17.6768 8.1814 8.5693 9.3276 10.922 12.813 14.682 16.375 a=18.1818 8.3992 8.7853 9.5366 11.113 12.98 14.84 16.517 a=18.6869 8.6122 8.9964 9.7406 11.301 13.141 14.992 16.655 a=19.1919 8.8208 9.2027 9.9397 11.483 13.296 15.138 16.789 a=19.697 9.0249 9.4042 10.134 11.661 13.448 15.281 16.919 a=20.202 9.2247 9.6013 10.324 11.835 13.598 15.42 17.046 a=20.7071 9.4203 9.794 10.509 12.004 13.746 15.556 17.169 a=21.2121 9.6119 9.9824 10.691 12.17 13.892 15.689 17.289 a=21.7172 9.7994 10.167 10.868 12.332 14.036 15.819 17.406 a=22.2222 9.9831 10.347 11.042 12.49 14.177 15.946 17.52 a=22.7273 10.163 10.524 11.212 12.646 14.315 16.069 17.631 a=23.2323 10.339 10.697 11.38 12.798 14.451 16.19 17.74 a=23.7374 10.512 10.867 11.545 12.947 14.585 16.308 17.846 a=24.2424 10.681 11.033 11.709 13.093 14.716 16.424 17.949 a=24.7475 10.847 11.198 11.869 13.237 14.844 16.536 18.051 a=25.2525 11.011 11.36 12.027 13.378 14.971 16.646 18.15 a=25.7576 11.173 11.521 12.183 13.517 15.095 16.753 18.247 a=26.2626 11.333 11.679 12.337 13.653 15.217 16.859 18.343 a=26.7677 11.491 11.836 12.488 13.787 15.336 16.961 18.437 a=27.2727 11.647 11.99 12.637 13.918 15.454 17.062 18.529 a=27.7778 11.801 12.142 12.783 14.048 15.57 17.161 18.621 a=28.2828 11.953 12.292 12.928 14.177 15.683 17.258 18.711 a=28.7879 12.104 12.441 13.07 14.304 15.795 17.355 18.801 a=29.2929 12.252 12.587 13.211 14.43 15.905 17.451 18.889 a=29.798 12.399 12.731 13.349 14.553 16.013 17.546 18.977 a=30.303 12.543 12.874 13.485 14.676 16.12 17.64 19.063 a=30.8081 12.686 13.014 13.62 14.797 16.226 17.733 19.149 a=31.3131 12.827 13.153 13.753 14.917 16.33 17.825 19.233 a=31.8182 12.967 13.29 13.884 15.035 16.433 17.916 19.315 a=32.3232 13.104 13.425 14.013 15.153 16.535 18.006 19.397 a=32.8283 13.241 13.559 14.14 15.268 16.635 18.094 19.477 a=33.3333 13.375 13.69 14.266 15.382 16.734 18.182 19.556 a=33.8384 13.507 13.82 14.39 15.495 16.832 18.269 19.634 a=34.3434 13.638 13.949 14.513 15.606 16.929 18.354 19.71 a=34.8485 13.768 14.075 14.634 15.716 17.024 18.439 19.786 a=35.3535 13.896 14.201 14.754 15.825 17.119 18.522 19.86 a=35.8586 14.022 14.324 14.871 15.933 17.213 18.605 19.934 a=36.3636 14.147 14.446 14.988 16.039 17.306 18.687 20.006 a=36.8687 14.27 14.567 15.103 16.144 17.399 18.768 20.078 a=37.3737 14.392 14.686 15.217 16.248 17.49 18.848 20.148 a=37.8788 14.512 14.803 15.329 16.351 17.581 18.927 20.218 a=38.3838 14.631 14.919 15.44 16.452 17.671 19.006 20.286 a=38.8889 14.748 15.034 15.55 16.553 17.76 19.084 20.354 a=39.3939 14.864 15.147 15.658 16.652 17.848 19.161 20.421 a=39.899 14.979 15.259 15.765 16.75 17.936 19.237 20.487 a=40.404 15.092 15.37 15.871 16.847 18.023 19.313 20.552 a=40.9091 15.204 15.479 15.975 16.944 18.109 19.387 20.617 a=41.4141 15.315 15.588 16.079 17.039 18.194 19.462 20.682 a=41.9192 15.424 15.694 16.181 17.133 18.278 19.535 20.746 a=42.4242 15.533 15.8 16.282 17.226 18.362 19.608 20.809 a=42.9293 15.639 15.904 16.382 17.318 18.445 19.68 20.872 a=43.4343 15.745 16.007 16.48 17.409 18.527 19.752 20.934 a=43.9394 15.85 16.109 16.578 17.499 18.608 19.823 20.996 a=44.4444 15.953 16.21 16.675 17.588 18.689 19.893 21.057 a=44.9495 16.055 16.31 16.772 17.677 18.769 19.963 21.118 a=45.4545 16.156 16.409 16.867 17.764 18.848 20.032 21.178 a=45.9596 16.256 16.506 16.961 17.851 18.926 20.101 21.238 a=46.4646 16.355 16.603 17.055 17.937 19.004 20.169 21.298 a=46.9697 16.452 16.698 17.147 18.022 19.081 20.236 21.358 a=47.4747 16.549 16.793 17.239 18.106 19.157 20.303 21.417 a=47.9798 16.645 16.887 17.33 18.189 19.233 20.369 21.476 a=48.4848 16.739 16.98 17.42 18.271 19.307 20.435 21.535 a=48.9899 16.833 17.072 17.51 18.353 19.382 20.5 21.593 a=49.4949 16.926 17.164 17.598 18.434 19.455 20.565 21.651 a=50 17.018 17.255 17.686 18.514 19.528 20.63 21.708 Table for Policy function z1 z2 z3 z4 z5 z6 z7 _______ _______ _______ ______ _______ ______ _______ a=0 0 0 0 0 0 0 0.50505 a=0.505051 0 0 0 0 0.50505 1.0101 1.0101 a=1.0101 0.50505 0.50505 0.50505 1.0101 1.0101 1.5152 1.5152 a=1.51515 1.0101 1.0101 1.0101 1.5152 1.5152 2.0202 2.0202 a=2.0202 1.5152 1.5152 1.5152 2.0202 2.0202 2.5253 2.5253 a=2.52525 2.0202 2.0202 2.0202 2.5253 3.0303 3.0303 3.0303 a=3.0303 2.5253 2.5253 3.0303 3.0303 3.5354 3.5354 3.5354 a=3.53535 3.0303 3.0303 3.5354 3.5354 4.0404 4.0404 4.0404 a=4.0404 3.5354 3.5354 4.0404 4.0404 4.5455 4.5455 4.5455 a=4.54545 4.0404 4.0404 4.5455 4.5455 5.0505 5.0505 5.0505 a=5.05051 4.5455 4.5455 5.0505 5.0505 5.5556 5.5556 5.5556 a=5.55556 5.0505 5.0505 5.5556 5.5556 6.0606 6.0606 6.0606 a=6.06061 5.5556 5.5556 6.0606 6.0606 6.5657 6.5657 6.5657 a=6.56566 6.0606 6.0606 6.5657 6.5657 7.0707 7.0707 7.0707 a=7.07071 6.5657 6.5657 7.0707 7.0707 7.5758 7.5758 7.5758 a=7.57576 7.0707 7.0707 7.5758 7.5758 8.0808 8.0808 8.0808 a=8.08081 7.5758 7.5758 7.5758 8.0808 8.5859 8.5859 8.5859 a=8.58586 8.0808 8.0808 8.0808 8.5859 9.0909 9.0909 9.0909 a=9.09091 8.5859 8.5859 8.5859 9.0909 9.596 9.596 9.596 a=9.59596 9.0909 9.0909 9.0909 9.596 9.596 10.101 10.101 a=10.101 9.596 9.596 9.596 10.101 10.101 10.606 10.606 a=10.6061 10.101 10.101 10.101 10.606 10.606 11.111 11.111 a=11.1111 10.606 10.606 10.606 11.111 11.111 11.616 11.616 a=11.6162 11.111 11.111 11.111 11.616 11.616 12.121 12.121 a=12.1212 11.616 11.616 11.616 12.121 12.121 12.626 12.626 a=12.6263 12.121 12.121 12.121 12.626 12.626 13.131 13.131 a=13.1313 12.626 12.626 12.626 13.131 13.131 13.636 13.636 a=13.6364 13.131 13.131 13.131 13.636 13.636 14.141 14.141 a=14.1414 13.636 13.636 13.636 13.636 14.141 14.646 14.646 a=14.6465 14.141 14.141 14.141 14.141 14.646 15.152 15.152 a=15.1515 14.646 14.646 14.646 14.646 15.152 15.657 15.657 a=15.6566 15.152 15.152 15.152 15.152 15.657 16.162 16.162 a=16.1616 15.657 15.657 15.657 15.657 16.162 16.667 16.667 a=16.6667 16.162 16.162 16.162 16.162 16.667 17.172 17.172 a=17.1717 16.667 16.667 16.667 16.667 17.172 17.172 17.677 a=17.6768 17.172 17.172 17.172 17.172 17.677 17.677 18.182 a=18.1818 17.677 17.677 17.677 17.677 18.182 18.182 18.687 a=18.6869 18.182 18.182 18.182 18.182 18.687 18.687 19.192 a=19.1919 18.687 18.687 18.687 18.687 19.192 19.192 19.697 a=19.697 19.192 19.192 19.192 19.192 19.192 19.697 20.202 a=20.202 19.697 19.697 19.697 19.697 19.697 20.202 20.707 a=20.7071 20.202 20.202 20.202 20.202 20.202 20.707 21.212 a=21.2121 20.707 20.707 20.707 20.707 20.707 21.212 21.717 a=21.7172 21.212 21.212 21.212 21.212 21.212 21.717 22.222 a=22.2222 21.717 21.717 21.717 21.717 21.717 22.222 22.727 a=22.7273 22.222 22.222 21.717 22.222 22.222 22.727 23.232 a=23.2323 22.727 22.727 22.222 22.727 22.727 23.232 23.737 a=23.7374 23.232 23.232 22.727 23.232 23.232 23.737 24.242 a=24.2424 23.737 23.737 23.232 23.737 23.737 24.242 24.747 a=24.7475 24.242 23.737 23.737 24.242 24.242 24.747 25.253 a=25.2525 24.242 24.242 24.242 24.747 24.747 25.253 25.758 a=25.7576 24.747 24.747 24.747 25.253 25.253 25.758 26.263 a=26.2626 25.253 25.253 25.253 25.758 25.758 26.263 26.768 a=26.7677 25.758 25.758 25.758 26.263 26.263 26.768 27.273 a=27.2727 26.263 26.263 26.263 26.768 26.768 27.273 27.778 a=27.7778 26.768 26.768 26.768 26.768 27.273 27.778 28.283 a=28.2828 27.273 27.273 27.273 27.273 27.778 27.778 28.788 a=28.7879 27.778 27.778 27.778 27.778 28.283 28.283 29.293 a=29.2929 28.283 28.283 28.283 28.283 28.788 28.788 29.798 a=29.798 28.788 28.788 28.788 28.788 29.293 29.293 29.798 a=30.303 29.293 29.293 29.293 29.293 29.798 29.798 30.303 a=30.8081 29.798 29.798 29.798 29.798 30.303 30.303 30.808 a=31.3131 30.303 30.303 30.303 30.303 30.808 30.808 31.313 a=31.8182 30.808 30.808 30.808 30.808 31.313 31.313 31.818 a=32.3232 31.313 31.313 31.313 31.313 31.818 31.818 32.323 a=32.8283 31.818 31.818 31.818 31.818 32.323 32.323 32.828 a=33.3333 32.323 32.323 32.323 32.323 32.828 32.828 33.333 a=33.8384 32.828 32.828 32.828 32.828 33.333 33.333 33.838 a=34.3434 33.333 33.333 33.333 33.333 33.838 33.838 34.343 a=34.8485 33.838 33.838 33.838 33.838 34.343 34.343 34.848 a=35.3535 34.343 34.343 34.343 34.343 34.343 34.848 35.354 a=35.8586 34.848 34.848 34.848 34.848 34.848 35.354 35.859 a=36.3636 35.354 35.354 35.354 35.354 35.354 35.859 36.364 a=36.8687 35.859 35.859 35.859 35.859 35.859 36.364 36.869 a=37.3737 36.364 36.364 36.364 36.364 36.364 36.869 37.374 a=37.8788 36.869 36.869 36.869 36.869 36.869 37.374 37.879 a=38.3838 37.374 37.374 37.374 37.374 37.374 37.879 38.384 a=38.8889 37.879 37.879 37.879 37.879 37.879 38.384 38.889 a=39.3939 38.384 38.384 38.384 38.384 38.384 38.889 39.394 a=39.899 38.889 38.889 38.889 38.889 38.889 39.394 39.899 a=40.404 39.394 39.394 39.394 39.394 39.394 39.899 40.404 a=40.9091 39.899 39.899 39.899 39.899 39.899 40.404 40.909 a=41.4141 40.404 40.404 40.404 40.404 40.404 40.909 41.414 a=41.9192 40.909 40.909 40.909 40.909 40.909 41.414 41.919 a=42.4242 41.414 41.414 41.414 41.414 41.414 41.919 42.424 a=42.9293 41.919 41.919 41.919 41.919 41.919 42.424 42.929 a=43.4343 42.424 42.424 42.424 42.424 42.424 42.929 43.434 a=43.9394 42.929 42.929 42.424 42.929 42.929 43.434 43.939 a=44.4444 43.434 43.434 42.929 43.434 43.434 43.939 44.444 a=44.9495 43.939 43.939 43.434 43.939 43.939 44.444 44.949 a=45.4545 44.444 44.444 43.939 44.444 44.444 44.949 44.949 a=45.9596 44.949 44.949 44.444 44.949 44.949 45.455 45.455 a=46.4646 45.455 45.455 44.949 45.455 45.455 45.96 45.96 a=46.9697 45.96 45.96 45.455 45.96 45.96 46.465 46.465 a=47.4747 46.465 46.465 45.96 46.465 46.465 46.97 46.97 a=47.9798 46.97 46.465 46.465 46.97 46.97 47.475 47.475 a=48.4848 47.475 46.97 46.97 47.475 47.475 47.98 47.98 a=48.9899 47.98 47.475 47.475 47.98 47.98 47.98 48.485 a=49.4949 48.485 47.98 47.98 48.485 48.485 48.485 48.99 a=50 48.485 48.485 48.485 48.99 48.99 48.99 49.495 Table for savefraccoh z1 z2 z3 z4 z5 z6 z7 _______ _______ _______ _______ _______ _______ _______ a=0 0 0 0 0 0 0 0.56117 a=0.505051 0 0 0 0 0.35689 0.71378 0.71378 a=1.0101 0.26164 0.26164 0.26164 0.52329 0.52329 0.78493 0.78493 a=1.51515 0.41305 0.41305 0.41305 0.61958 0.61958 0.8261 0.81922 a=2.0202 0.51177 0.51177 0.51177 0.68236 0.68236 0.85205 0.80958 a=2.52525 0.58123 0.58123 0.58123 0.72653 0.87184 0.84671 0.80719 a=3.0303 0.63275 0.63275 0.7593 0.7593 0.88088 0.84532 0.80794 a=3.53535 0.67249 0.67249 0.78458 0.78458 0.87981 0.8459 0.81018 a=4.0404 0.70408 0.70408 0.80467 0.80467 0.8801 0.84752 0.81313 a=4.54545 0.72979 0.72979 0.82102 0.81974 0.88117 0.8497 0.81642 a=5.05051 0.75113 0.75113 0.83459 0.82857 0.8827 0.85217 0.81983 a=5.55556 0.76911 0.76911 0.84602 0.83639 0.8845 0.85478 0.82327 a=6.06061 0.78448 0.78448 0.8558 0.84339 0.88645 0.85745 0.82666 a=6.56566 0.79777 0.79777 0.86425 0.84971 0.88848 0.86011 0.82997 a=7.07071 0.80936 0.80936 0.87162 0.85546 0.89054 0.86275 0.83319 a=7.57576 0.81958 0.81958 0.87812 0.86073 0.89259 0.86532 0.83629 a=8.08081 0.82864 0.82864 0.82864 0.86559 0.89463 0.86784 0.83929 a=8.58586 0.83673 0.83673 0.83673 0.87009 0.89664 0.87028 0.84218 a=9.09091 0.84401 0.84401 0.84401 0.87427 0.8986 0.87265 0.84496 a=9.59596 0.85058 0.85058 0.85058 0.87817 0.85549 0.87495 0.84764 a=10.101 0.85655 0.85655 0.85655 0.88183 0.85942 0.87717 0.85023 a=10.6061 0.86199 0.86199 0.86199 0.88527 0.86311 0.87932 0.85271 a=11.1111 0.86698 0.86698 0.86698 0.88851 0.86659 0.8814 0.85511 a=11.6162 0.87156 0.87156 0.87156 0.89157 0.86989 0.88342 0.85743 a=12.1212 0.87579 0.87579 0.87579 0.89447 0.87301 0.88537 0.85966 a=12.6263 0.8797 0.8797 0.8797 0.89723 0.87597 0.88726 0.86182 a=13.1313 0.88333 0.88333 0.88333 0.89985 0.87879 0.88909 0.86391 a=13.6364 0.88671 0.88671 0.88671 0.90235 0.88148 0.89086 0.86592 a=14.1414 0.88986 0.88986 0.88986 0.87242 0.88405 0.89258 0.86788 a=14.6465 0.8928 0.8928 0.8928 0.87574 0.88651 0.89425 0.86977 a=15.1515 0.89556 0.89556 0.89556 0.8789 0.88886 0.89587 0.87161 a=15.6566 0.89815 0.89815 0.89815 0.8819 0.89112 0.89745 0.87339 a=16.1616 0.90059 0.90059 0.90059 0.88477 0.8933 0.89898 0.87511 a=16.6667 0.90288 0.90288 0.90288 0.88747 0.89538 0.90047 0.87679 a=17.1717 0.90505 0.90505 0.90505 0.89003 0.8974 0.87615 0.87842 a=17.6768 0.9071 0.9071 0.9071 0.89245 0.89933 0.87824 0.88001 a=18.1818 0.90904 0.90904 0.90904 0.89474 0.9012 0.88025 0.88155 a=18.6869 0.91089 0.91089 0.91089 0.89692 0.90301 0.8822 0.88305 a=19.1919 0.91263 0.91263 0.91263 0.89899 0.90476 0.88408 0.88451 a=19.697 0.9143 0.9143 0.9143 0.90095 0.88321 0.8859 0.88594 a=20.202 0.91588 0.91588 0.91588 0.90283 0.88539 0.88766 0.88733 a=20.7071 0.91739 0.91739 0.91739 0.90462 0.88749 0.88937 0.88868 a=21.2121 0.91883 0.91883 0.91883 0.90633 0.88952 0.89103 0.89 a=21.7172 0.92021 0.92021 0.92021 0.90796 0.89148 0.89264 0.8913 a=22.2222 0.92152 0.92152 0.92152 0.90952 0.89337 0.89421 0.89256 a=22.7273 0.92278 0.92278 0.90181 0.91102 0.89517 0.89573 0.89379 a=23.2323 0.92399 0.92399 0.90345 0.91245 0.8969 0.89721 0.89499 a=23.7374 0.92514 0.92514 0.90503 0.91383 0.89857 0.89865 0.89617 a=24.2424 0.92625 0.92625 0.90655 0.91515 0.90017 0.90006 0.89733 a=24.7475 0.92732 0.908 0.908 0.91642 0.9017 0.90142 0.89845 a=25.2525 0.9094 0.9094 0.9094 0.91765 0.90318 0.90276 0.89956 a=25.7576 0.91075 0.91075 0.91075 0.91882 0.90461 0.90406 0.90064 a=26.2626 0.91204 0.91204 0.91204 0.91995 0.90598 0.90532 0.9017 a=26.7677 0.91329 0.91329 0.91329 0.92105 0.90731 0.90656 0.90274 a=27.2727 0.91449 0.91449 0.91449 0.9221 0.90858 0.90777 0.90375 a=27.7778 0.91566 0.91566 0.91566 0.90602 0.90982 0.90895 0.90475 a=28.2828 0.91678 0.91678 0.91678 0.9073 0.91101 0.89386 0.90573 a=28.7879 0.91786 0.91786 0.91786 0.90853 0.91216 0.89525 0.90669 a=29.2929 0.91891 0.91891 0.91891 0.90972 0.91328 0.89661 0.90763 a=29.798 0.91992 0.91992 0.91992 0.91087 0.91436 0.89794 0.89342 a=30.303 0.9209 0.9209 0.9209 0.91199 0.9154 0.89922 0.89456 a=30.8081 0.92185 0.92185 0.92185 0.91307 0.91641 0.90046 0.89568 a=31.3131 0.92276 0.92276 0.92276 0.91411 0.9174 0.90167 0.89677 a=31.8182 0.92365 0.92365 0.92365 0.91513 0.91835 0.90284 0.89785 a=32.3232 0.92452 0.92452 0.92452 0.91611 0.91927 0.90397 0.8989 a=32.8283 0.92535 0.92535 0.92535 0.91706 0.92017 0.90507 0.89993 a=33.3333 0.92617 0.92617 0.92617 0.91799 0.92104 0.90614 0.90095 a=33.8384 0.92696 0.92696 0.92696 0.91889 0.92188 0.90719 0.90194 a=34.3434 0.92772 0.92772 0.92772 0.91976 0.92271 0.9082 0.90292 a=34.8485 0.92847 0.92847 0.92847 0.92061 0.9235 0.90918 0.90388 a=35.3535 0.92919 0.92919 0.92919 0.92144 0.91089 0.91014 0.90482 a=35.8586 0.92989 0.92989 0.92989 0.92224 0.91182 0.91107 0.90574 a=36.3636 0.93058 0.93058 0.93058 0.92303 0.91274 0.91198 0.90665 a=36.8687 0.93125 0.93125 0.93125 0.92379 0.91362 0.91287 0.90754 a=37.3737 0.93189 0.93189 0.93189 0.92453 0.91449 0.91373 0.90842 a=37.8788 0.93253 0.93253 0.93253 0.92525 0.91533 0.91457 0.90928 a=38.3838 0.93314 0.93314 0.93314 0.92595 0.91615 0.91539 0.91013 a=38.8889 0.93374 0.93374 0.93374 0.92664 0.91695 0.91619 0.91097 a=39.3939 0.93433 0.93433 0.93433 0.92731 0.91774 0.91697 0.91179 a=39.899 0.9349 0.9349 0.9349 0.92796 0.9185 0.91773 0.9126 a=40.404 0.93545 0.93545 0.93545 0.9286 0.91924 0.91847 0.91339 a=40.9091 0.936 0.936 0.936 0.92922 0.91997 0.9192 0.91416 a=41.4141 0.93653 0.93653 0.93653 0.92983 0.92068 0.91991 0.91491 a=41.9192 0.93704 0.93704 0.93704 0.93042 0.92137 0.9206 0.91565 a=42.4242 0.93755 0.93755 0.93755 0.931 0.92205 0.92128 0.91637 a=42.9293 0.93804 0.93804 0.93804 0.93156 0.92271 0.92194 0.91707 a=43.4343 0.93853 0.93853 0.93853 0.93212 0.92336 0.92258 0.91776 a=43.9394 0.939 0.939 0.92795 0.93266 0.92399 0.92322 0.91844 a=44.4444 0.93946 0.93946 0.92854 0.93318 0.92461 0.92384 0.9191 a=44.9495 0.93991 0.93991 0.92911 0.9337 0.92521 0.92444 0.91974 a=45.4545 0.94035 0.94035 0.92967 0.93421 0.9258 0.92504 0.91015 a=45.9596 0.94078 0.94078 0.93021 0.9347 0.92638 0.92562 0.91087 a=46.4646 0.94121 0.94121 0.93075 0.93519 0.92695 0.92618 0.91158 a=46.9697 0.94162 0.94162 0.93127 0.93566 0.92751 0.92674 0.91228 a=47.4747 0.94202 0.94202 0.93179 0.93612 0.92805 0.92729 0.91296 a=47.9798 0.94242 0.93229 0.93229 0.93658 0.92858 0.92782 0.91363 a=48.4848 0.94281 0.93278 0.93278 0.93702 0.92911 0.92835 0.91429 a=48.9899 0.94319 0.93326 0.93326 0.93746 0.92962 0.91918 0.91493 a=49.4949 0.94356 0.93373 0.93373 0.93789 0.93012 0.91978 0.91556 a=50 0.9342 0.9342 0.9342 0.93831 0.93061 0.92037 0.91618 Table for Consumption z1 z2 z3 z4 z5 z6 z7 ______ ______ _______ _______ _______ _______ _______ a=0 0.9 0.9 0.9 0.9 0.9 0.9 0.39495 a=0.505051 1.4152 1.4152 1.4152 1.4152 0.9101 0.40505 0.40505 a=1.0101 1.4253 1.4253 1.4253 0.9202 0.9202 0.41515 0.41515 a=1.51515 1.4354 1.4354 1.4354 0.9303 0.9303 0.42525 0.44581 a=2.0202 1.4455 1.4455 1.4455 0.9404 0.9404 0.43848 0.59395 a=2.52525 1.4556 1.4556 1.4556 0.95051 0.44545 0.54861 0.72383 a=3.0303 1.4657 1.4657 0.96061 0.96061 0.47807 0.64691 0.8404 a=3.53535 1.4758 1.4758 0.97071 0.97071 0.55195 0.73604 0.94666 a=4.0404 1.4859 1.4859 0.98081 0.98081 0.61924 0.81778 1.0446 a=4.54545 1.496 1.496 0.99091 0.99957 0.68106 0.89337 1.1357 a=5.05051 1.5061 1.5061 1.001 1.045 0.73823 0.96375 1.2209 a=5.55556 1.5162 1.5162 1.0111 1.0868 0.79138 1.0296 1.301 a=6.06061 1.5263 1.5263 1.0212 1.1254 0.84101 1.0915 1.3767 a=6.56566 1.5364 1.5364 1.0313 1.1613 0.8875 1.15 1.4485 a=7.07071 1.5465 1.5465 1.0414 1.1946 0.9312 1.2052 1.5168 a=7.57576 1.5566 1.5566 1.0515 1.2257 0.97237 1.2577 1.5818 a=8.08081 1.5667 1.5667 1.5667 1.2548 1.0112 1.3075 1.644 a=8.58586 1.5768 1.5768 1.5768 1.282 1.048 1.355 1.7036 a=9.09091 1.5869 1.5869 1.5869 1.3074 1.0828 1.4004 1.7607 a=9.59596 1.597 1.597 1.597 1.3313 1.6209 1.4437 1.8156 a=10.101 1.6071 1.6071 1.6071 1.3536 1.6523 1.4852 1.8683 a=10.6061 1.6172 1.6172 1.6172 1.3746 1.6821 1.5249 1.9192 a=11.1111 1.6273 1.6273 1.6273 1.3942 1.7105 1.563 1.9682 a=11.6162 1.6374 1.6374 1.6374 1.4127 1.7375 1.5996 2.0155 a=12.1212 1.6475 1.6475 1.6475 1.43 1.7632 1.6348 2.0612 a=12.6263 1.6576 1.6576 1.6576 1.4463 1.7878 1.6686 2.1054 a=13.1313 1.6677 1.6677 1.6677 1.4615 1.8112 1.7011 2.1482 a=13.6364 1.6778 1.6778 1.6778 1.4757 1.8335 1.7324 2.1896 a=14.1414 1.6879 1.6879 1.6879 1.9941 1.8547 1.7626 2.2297 a=14.6465 1.698 1.698 1.698 2.0065 1.875 1.7917 2.2686 a=15.1515 1.7081 1.7081 1.7081 2.0182 1.8944 1.8197 2.3063 a=15.6566 1.7182 1.7182 1.7182 2.029 1.9129 1.8468 2.3429 a=16.1616 1.7283 1.7283 1.7283 2.0392 1.9305 1.8728 2.3785 a=16.6667 1.7384 1.7384 1.7384 2.0493 1.9473 1.898 2.413 a=17.1717 1.7485 1.7485 1.7485 2.0594 1.9634 2.4274 2.4466 a=17.6768 1.7586 1.7586 1.7586 2.0695 1.9786 2.4508 2.4792 a=18.1818 1.7687 1.7687 1.7687 2.0796 1.9932 2.4735 2.5109 a=18.6869 1.7788 1.7788 1.7788 2.0897 2.0071 2.4954 2.5418 a=19.1919 1.7889 1.7889 1.7889 2.0998 2.0203 2.5165 2.5718 a=19.697 1.799 1.799 1.799 2.1099 2.5379 2.5369 2.601 a=20.202 1.8091 1.8091 1.8091 2.12 2.5498 2.5566 2.6294 a=20.7071 1.8192 1.8192 1.8192 2.1301 2.5611 2.5757 2.6571 a=21.2121 1.8293 1.8293 1.8293 2.1402 2.5719 2.5941 2.684 a=21.7172 1.8394 1.8394 1.8394 2.1503 2.5821 2.6118 2.7103 a=22.2222 1.8495 1.8495 1.8495 2.1604 2.5922 2.629 2.7358 a=22.7273 1.8596 1.8596 2.3646 2.1705 2.6023 2.6456 2.7607 a=23.2323 1.8697 1.8697 2.3747 2.1806 2.6124 2.6616 2.785 a=23.7374 1.8798 1.8798 2.3848 2.1907 2.6225 2.677 2.8086 a=24.2424 1.8899 1.8899 2.3949 2.2008 2.6326 2.6919 2.8317 a=24.7475 1.9 2.4051 2.4051 2.2109 2.6427 2.7063 2.8541 a=25.2525 2.4152 2.4152 2.4152 2.221 2.6528 2.7202 2.876 a=25.7576 2.4253 2.4253 2.4253 2.2311 2.6629 2.7336 2.8974 a=26.2626 2.4354 2.4354 2.4354 2.2412 2.673 2.7465 2.9182 a=26.7677 2.4455 2.4455 2.4455 2.2513 2.6831 2.7589 2.9384 a=27.2727 2.4556 2.4556 2.4556 2.2614 2.6932 2.7709 2.9582 a=27.7778 2.4657 2.4657 2.4657 2.7765 2.7033 2.7824 2.9775 a=28.2828 2.4758 2.4758 2.4758 2.7866 2.7134 3.2985 2.9962 a=28.7879 2.4859 2.4859 2.4859 2.7967 2.7235 3.3092 3.0145 a=29.2929 2.496 2.496 2.496 2.8068 2.7336 3.3195 3.0324 a=29.798 2.5061 2.5061 2.5061 2.8169 2.7437 3.3296 3.5548 a=30.303 2.5162 2.5162 2.5162 2.827 2.7538 3.3397 3.5718 a=30.8081 2.5263 2.5263 2.5263 2.8371 2.7639 3.3498 3.5883 a=31.3131 2.5364 2.5364 2.5364 2.8472 2.774 3.3599 3.6044 a=31.8182 2.5465 2.5465 2.5465 2.8573 2.7841 3.37 3.6201 a=32.3232 2.5566 2.5566 2.5566 2.8674 2.7942 3.3801 3.6353 a=32.8283 2.5667 2.5667 2.5667 2.8775 2.8043 3.3902 3.6502 a=33.3333 2.5768 2.5768 2.5768 2.8876 2.8144 3.4003 3.6647 a=33.8384 2.5869 2.5869 2.5869 2.8977 2.8245 3.4104 3.6788 a=34.3434 2.597 2.597 2.597 2.9078 2.8346 3.4205 3.6926 a=34.8485 2.6071 2.6071 2.6071 2.9179 2.8447 3.4306 3.706 a=35.3535 2.6172 2.6172 2.6172 2.928 3.3599 3.4407 3.719 a=35.8586 2.6273 2.6273 2.6273 2.9381 3.37 3.4508 3.7317 a=36.3636 2.6374 2.6374 2.6374 2.9482 3.3801 3.4609 3.744 a=36.8687 2.6475 2.6475 2.6475 2.9583 3.3902 3.471 3.756 a=37.3737 2.6576 2.6576 2.6576 2.9684 3.4003 3.4811 3.7677 a=37.8788 2.6677 2.6677 2.6677 2.9785 3.4104 3.4912 3.779 a=38.3838 2.6778 2.6778 2.6778 2.9886 3.4205 3.5013 3.79 a=38.8889 2.6879 2.6879 2.6879 2.9987 3.4306 3.5114 3.8008 a=39.3939 2.698 2.698 2.698 3.0088 3.4407 3.5215 3.8112 a=39.899 2.7081 2.7081 2.7081 3.0189 3.4508 3.5316 3.8213 a=40.404 2.7182 2.7182 2.7182 3.029 3.4609 3.5417 3.8314 a=40.9091 2.7283 2.7283 2.7283 3.0392 3.471 3.5518 3.8415 a=41.4141 2.7384 2.7384 2.7384 3.0493 3.4811 3.5619 3.8516 a=41.9192 2.7485 2.7485 2.7485 3.0594 3.4912 3.572 3.8617 a=42.4242 2.7586 2.7586 2.7586 3.0695 3.5013 3.5821 3.8718 a=42.9293 2.7687 2.7687 2.7687 3.0796 3.5114 3.5922 3.8819 a=43.4343 2.7788 2.7788 2.7788 3.0897 3.5215 3.6023 3.892 a=43.9394 2.7889 2.7889 3.2939 3.0998 3.5316 3.6124 3.9021 a=44.4444 2.799 2.799 3.304 3.1099 3.5417 3.6225 3.9122 a=44.9495 2.8091 2.8091 3.3141 3.12 3.5518 3.6326 3.9223 a=45.4545 2.8192 2.8192 3.3242 3.1301 3.5619 3.6427 4.4375 a=45.9596 2.8293 2.8293 3.3343 3.1402 3.572 3.6528 4.4476 a=46.4646 2.8394 2.8394 3.3444 3.1503 3.5821 3.6629 4.4577 a=46.9697 2.8495 2.8495 3.3545 3.1604 3.5922 3.673 4.4678 a=47.4747 2.8596 2.8596 3.3646 3.1705 3.6023 3.6831 4.4779 a=47.9798 2.8697 3.3747 3.3747 3.1806 3.6124 3.6932 4.488 a=48.4848 2.8798 3.3848 3.3848 3.1907 3.6225 3.7033 4.4981 a=48.9899 2.8899 3.3949 3.3949 3.2008 3.6326 4.2184 4.5082 a=49.4949 2.9 3.4051 3.4051 3.2109 3.6427 4.2285 4.5183 a=50 3.4152 3.4152 3.4152 3.221 3.6528 4.2386 4.5284
Printing Outputs
Plot Value function, Policy Function and Consumption
% 3D Value function if(bl_plot) figure(1) chart = surf(ar_z,ar_a,mt_vf); title('Value Function'); xlabel('Productivity') ; ylabel('Assets'); zlabel('Value'); xt = get(gca, 'XTick'); set(gca, 'XTick', xt, 'XTickLabel', xt*fl_ahi/it_agridno); if(bl_saveimg) saveas(gcf, '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Households/figures/hhsave_VFI_2OC/Valuefunction_3D.png') end % 2D Value function figure(2) %chart = plot(mt_vf); for i = 1: it_zgridno hold on a(i) = plot((mt_vf(:,i)),'.'); b{i} = sprintf(['Z shock =', num2str(ar_z(i))]); end clr = jet(numel(a)); for m = 1:numel(a) set(a(m),'Color',clr(m,:)) end legend(b,'Location','north') title('Value Function'); xlabel('Asset') ; ylabel('V(a,z)'); xt = get(gca, 'XTick'); set(gca, 'XTick', xt, 'XTickLabel', xt*fl_ahi/it_agridno); if(bl_saveimg) saveas(gcf, '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Households/figures/hhsave_VFI_2OC/Valuefunction_2D.png') end figure(3) for i = 1: it_zgridno a(i) = plot((mt_pf(:,i)),'.'); b{i} = sprintf(['Z shock =', num2str(ar_z(i))]); hold on end clr = jet(numel(a)); for m = 1:numel(a) set(a(m),'Color',clr(m,:)) end legend(b,'Location','north') title('Policy Function'); xlabel('Asset') ; ylabel('Asset choice'); xt = get(gca, 'XTick'); set(gca, 'XTick', xt, 'XTickLabel', xt*fl_ahi/it_agridno); if(bl_saveimg) saveas(gcf, '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Households/figures/hhsave_VFI_2OC/Policyfunction.png') end figure(4) for i = 1: it_zgridno a(i) = plot((mt_con(:,i)),'-o'); b{i} = sprintf(['Z shock =', num2str(ar_z(i))]); hold on end clr = jet(numel(a)); for m = 1:numel(a) set(a(m),'Color',clr(m,:)) end legend(b,'Location','north') title('Consumption'); xlabel('Asset') ; ylabel('Consumption'); xt = get(gca, 'XTick'); set(gca, 'XTick', xt, 'XTickLabel', xt*fl_ahi/it_agridno); if(bl_saveimg) saveas(gcf, '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Households/figures/hhsave_VFI_2OC/Consumption.png') end figure(5) for i = 1: it_zgridno a(i) = plot(mt_savefraccoh(:,i), '-o'); b{i} = sprintf(['Z shock =', num2str(ar_z(i))]); hold on end clr = jet(numel(a)); for m = 1:numel(a) set(a(m),'Color',clr(m,:)) end legend(b,'Location','north') title('savefraccoh(a,z)'); xlabel('Asset') ; ylabel('savefraccoh(a,z)'); xt = get(gca, 'XTick'); set(gca, 'XTick', xt, 'XTickLabel', xt*fl_ahi/it_agridno); if(bl_saveimg) saveas(gcf, '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Households/figures/hhsave_VFI_2OC/Consumption.png') end end
Profile off
if(bl_profile) profile off; profile viewer; st_file_name = '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Profile/Households/hhsave_VFI_2OC'; profsave(profile('info'), st_file_name); end