This is a static copy of a profile report

Home

Function details for hhsave_VFI_2OCThis is a static copy of a profile report

Home

hhsave_VFI_2OC (Calls: 1, Time: 2.371 s)
Generated 28-Jun-2020 22:32:30 using performance time.
function in file /Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Households/hhsave_VFI_2OC.m
Copy to new window for comparing multiple runs

Parents (calling functions)
No parent
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
77
fl_risk,it_zgridno, it_agridno...
11.840 s77.6%
25
addpath(genpath('/Users/sidhan...
10.469 s19.8%
39
close all;
10.015 s0.6%
57
[ar_z, mt_trans_z] = mytauchen...
10.010 s0.4%
86
[mt_Tvf,mt_oploc] = max((mt_ut...
3620.008 s0.4%
All other lines  0.028 s1.2%
Totals  2.371 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
hhsave_util_2OCfunction11.839 s77.6%
genpathfunction10.370 s15.6%
addpathfunction10.098 s4.1%
closefunction10.015 s0.6%
mytauchen_zfunction10.009 s0.4%
linspacefunction10.002 s0.1%
dealfunction10.001 s0.0%
Self time (built-ins, overhead, etc.)  0.036 s1.5%
Totals  2.371 s100% 
Code Analyzer results
Line numberMessage
31The value assigned here to 'fl_mu' appears to be unused. Consider replacing it by ~.
31The value assigned here to 'fl_sig' appears to be unused. Consider replacing it by ~.
31The value assigned here to 'fl_rho' appears to be unused. Consider replacing it by ~.
67The value assigned to variable 'fl_R' might be unused.
72The value assigned to variable 'mt_Tv' might be unused.
113The value assigned to variable 'chart' might be unused.
128The variable 'a' appears to change size on every loop iteration. Consider preallocating for speed.
129The variable 'b' appears to change size on every loop iteration. Consider preallocating for speed.
Coverage results
Show coverage for parent directory
Total lines in function172
Non-code lines (comments, blank lines)41
Code lines (lines that can run)131
Code lines that did run52
Code lines that did not run79
Coverage (did run/can run)39.69 %
Function listing
time 
Calls 
 line
  16 
function [mt_vf, mt_pf, mt_oploc, mt_o, mt_k, mt_l]=hhsave_VFI_2OC(varargin)
  17 

  18 
bl_profile = true;      % Switch off profile if running a tester/calling from another function
  19 
bl_saveimg = true;
  20 
if(bl_profile)
  21 
profile off;
  22 
profile on;
< 0.001 
      1 
  23
end 
  24 

  0.469 
      1 
  25
addpath(genpath('/Users/sidhantkhanna/Documents/GitHub/BKS modified/')); 
  26 

< 0.001 
      1 
  27
if ~isempty(varargin) 
  28 
    
  29 
    [ar_a,ar_z, ...
  30 
        fl_alpha,fl_theta,fl_delta,fl_kappa,fl_r,fl_w,fl_phi,fl_ahi,fl_zhi, ...
  31 
         fl_risk,it_zgridno, it_agridno,mt_trans_z,fl_beta, fl_mu, fl_sig,fl_rho, fl_tolvfi ...
  32 
        ] = varargin{:};
  33 
    
  34 
    bl_print  = false;
  35 
    bl_plot   = true;
  36 

  37 
    
< 0.001 
      1 
  38
else 
  0.015 
      1 
  39
    close all; 
  40 
    
< 0.001 
      1 
  41
    fl_ahi         = 50; 
< 0.001 
      1 
  42
    fl_zhi         = 1.8; 
< 0.001 
      1 
  43
    it_agridno     = 25; 
< 0.001 
      1 
  44
    it_zgridno     = 10; 
  0.002 
      1 
  45
    ar_a           = linspace(0,fl_ahi,it_agridno); 
< 0.001 
      1 
  46
    fl_phi         = 0.3; 
< 0.001 
      1 
  47
    fl_risk        = 1; 
< 0.001 
      1 
  48
    fl_alpha       = 0.4; 
< 0.001 
      1 
  49
    fl_theta       = 0.79-fl_alpha; 
< 0.001 
      1 
  50
    fl_delta       = 0.05; 
< 0.001 
      1 
  51
    fl_kappa       = 0; 
< 0.001 
      1 
  52
    fl_mu          = 0;                   % mean of AR(1) entrepeneurial productivity process 
< 0.001 
      1 
  53
    fl_rho         = 0.9;                 % persistence parameter of the AR(1) entrepreneurial productivity process 
< 0.001 
      1 
  54
    fl_sig         = 0.2;      
< 0.001 
      1 
  55
    fl_lambda      = 3;       
< 0.001 
      1 
  56
    fl_beta       = 0.92;  
  0.010 
      1 
  57
    [ar_z, mt_trans_z] = mytauchen_z(fl_mu,fl_rho,fl_sig,it_zgridno,fl_lambda);     
< 0.001 
      1 
  58
    ar_z           = exp(ar_z); 
< 0.001 
      1 
  59
    [fl_r,fl_w] = ... 
      1 
  60
        deal(0.05,2); 
< 0.001 
      1 
  61
    fl_tolvfi    = 10^-12; 
< 0.001 
      1 
  62
    bl_print     = false; 
< 0.001 
      1 
  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 

  1.840 
      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.002 
    362 
  82
mt_evf = mt_vf*mt_trans_z'; 
  0.003 
    362 
  83
mt_ev1 = repmat(mt_evf, [1 1 it_agridno]); 
  0.005 
    362 
  84
mt_ev1 = permute(mt_ev1,[3 2 1]);     
  85 

  0.008 
    362 
  86
[mt_Tvf,mt_oploc] = max((mt_util+fl_beta.*(mt_ev1)),[], 3); 
  87 

< 0.001 
    362 
  88
    mt_diff= mt_Tvf-mt_vf; 
  0.007 
    362 
  89
    fl_crit=norm(mt_diff); 
< 0.001 
    362 
  90
    mt_vf = mt_Tvf; 
< 0.001 
    362 
  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('Value');
 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) 
  0.005 
      1 
 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.