This is a static copy of a profile report

Home

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

Home

hhsave_util_2OC (Calls: 1, Time: 2.842 s)
Generated 02-May-2020 21:54:23 using performance time.
function in file /Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Households/hhsave_util_2OC.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
hhsave_VFI_2OCfunction1
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
66
it_zgridno, it_agridno);
12.429 s85.5%
24
addpath(genpath('/Users/sidhan...
10.406 s14.3%
17
close all;
10.002 s0.1%
32
fl_risk,it_zgridno, it_agridno...
10.001 s0.0%
31
fl_alpha,fl_theta,fl_delta,fl_...
10.001 s0.0%
All other lines  0.003 s0.1%
Totals  2.842 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
OC2function12.428 s85.4%
genpathfunction10.293 s10.3%
addpathfunction10.113 s4.0%
closefunction10.001 s0.1%
Self time (built-ins, overhead, etc.)  0.007 s0.2%
Totals  2.842 s100% 
Code Analyzer results
Line numberMessage
20This statement (and possibly following ones) cannot be reached.
61The value assigned to variable 'fl_R' might be unused.
92If 'mt_util' is an indexed variable, performance can be improved using logical indexing instead of FIND.
108This statement (and possibly following ones) cannot be reached.
Coverage results
Show coverage for parent directory
Total lines in function98
Non-code lines (comments, blank lines)36
Code lines (lines that can run)62
Code lines that did run26
Code lines that did not run36
Coverage (did run/can run)41.94 %
Function listing
time 
Calls 
 line
  15 
function [mt_util,mt_coh, mt_k, mt_l, mt_o]=hhsave_util_2OC(varargin)
  16 

  0.002 
      1 
  17
close all; 
< 0.001 
      1 
  18
bl_profile = false;      % Switch off profile if running a tester/calling from another function 
< 0.001 
      1 
  19
if(bl_profile) 
  20 
profile off;
  21 
profile on;
  22 
end
  23 

  0.406 
      1 
  24
addpath(genpath('/Users/sidhantkhanna/Documents/GitHub/BKS modified/')); 
  25 

  26 
%% Assigning parameters
  27 

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

  37 
    
  38 
else
  39 
    close all;
  40 
    
  41 
    fl_ahi         = 5;
  42 
    fl_zhi         = 2.2;
  43 
    it_agridno     = 4;
  44 
    it_zgridno     = 5;
  45 
    ar_a = linspace(0,fl_ahi,it_agridno);
  46 
    ar_z = linspace(1,fl_zhi,it_zgridno);
  47 
    fl_phi         = 0.5;
  48 
    fl_risk        = 2;
  49 
    
  50 
    fl_alpha = 0.4;
  51 
    fl_theta = 0.79-fl_alpha;
  52 
    fl_delta = 0.05;
  53 
    fl_kappa = 0;
  54 
        
  55 
    [fl_r,fl_w] = ...
  56 
        deal(0.05,1.5);
  57 
    bl_print       = true;
  58 
    
< 0.001 
      1 
  59
end 
  60 

< 0.001 
      1 
  61
fl_R = fl_r + fl_delta; 
  62 
%% Calling OC2
  63 

  2.429 
      1 
  64
[mt_o, mt_coh, mt_k, mt_l] = OC2(ar_a,ar_z, ... 
      1 
  65
        fl_alpha,fl_theta,fl_delta,fl_kappa,fl_r,fl_w,fl_phi,fl_ahi,fl_zhi, ... 
      1 
  66
         it_zgridno, it_agridno); 
  67 

  68 
%% Computing consumption     
  69 

< 0.001 
      1 
  70
mt3_coh= repmat (mt_coh, [1 1 it_agridno]);   
  71 
%Projecting COH matrix to a third dimension of size of asset grid which will be used for evaluating optimal future assets
  72 

< 0.001 
      1 
  73
mt_futassets=ones(it_agridno,it_zgridno,it_agridno).*ar_a';    
  74 
% 3d asset matrix to subtract future assets from COH to compute consumption
  75 

< 0.001 
      1 
  76
mt_futassets=permute(mt_futassets,[3 2 1]);    
  77 
% reorder matrix to correct dimension so as to match COH matrix layout
  78 
        
< 0.001 
      1 
  79
mt_con =mt3_coh-mt_futassets;                       % Consumption Matrix for each a, z, future a 
  80 

< 0.001 
      1 
  81
neg = find(mt_con<=0);                              % Find where consumption is negative ( each combi of a, z, a') 
  82 

  83 
%% Computing utility     
  84 

  85 
%mt_con(neg) = NaN;
  86 

< 0.001 
      1 
  87
if(fl_risk==1) 
< 0.001 
      1 
  88
    mt_util=log(mt_con); 
  89 
else
  90 
mt_util= (mt_con.^(1-fl_risk) -1)/(1-fl_risk);    % Utility Part of value function
< 0.001 
      1 
  91
end 
< 0.001 
      1 
  92
mt_util(neg) = -1000;         % Assign big negative value to optimal consumption                              
  93 

  94 
%% Printing outputs 
  95 

< 0.001 
      1 
  96
if(bl_print) 
  97 
    disp('Below is the COH matrix for for all combinations of a, z and future a');
  98 
    disp(mt3_coh);
  99 
    disp('Below is the future assets matrix for each combination of a, z and future a');
 100 
    disp(mt_futassets);
 101 
    disp('Below is the consumption matrix for for all combinations of a, z and future a');
 102 
    disp(mt_con);
 103 
    disp('Below is the utility matrix for for all combinations of a, z and future a');
 104 
    disp(mt_util);
 105 
 end
 106 

< 0.001 
      1 
 107
if(bl_profile) 
 108 
profile off;
 109 
profile viewer;
 110 
st_file_name = '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Profile/Households/hhsave_util_2OC';
 111 
profsave(profile('info'), st_file_name);
 112 
end