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.202 s)
Generated 28-Jun-2020 10:10:18 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
...private/evalmxdom>instrumentAndRunsubfunction1
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
67
it_zgridno, it_agridno);
11.508 s68.5%
25
addpath(genpath('/Users/sidhan...
10.615 s27.9%
62
fl_R = fl_r + fl_delta;
10.046 s2.1%
82
neg = find(mt_con<=0);     ...
10.008 s0.4%
93
mt_util(neg) = -1000;         ...
10.008 s0.4%
All other lines  0.017 s0.8%
Totals  2.202 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
OC2function11.500 s68.1%
genpathfunction10.405 s18.4%
snapnowfunction50.175 s7.9%
addpathfunction10.100 s4.6%
closefunction10.007 s0.3%
linspacefunction20.001 s0.1%
dealfunction10.000 s0.0%
Self time (built-ins, overhead, etc.)  0.013 s0.6%
Totals  2.202 s100% 
Code Analyzer results
Line numberMessage
62The value assigned to variable 'fl_R' might be unused.
93If 'mt_util' is an indexed variable, performance can be improved using logical indexing instead of FIND.
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 run47
Code lines that did not run15
Coverage (did run/can run)75.81 %
Function listing
time 
Calls 
 line
  16 
function [mt_util,mt_coh, mt_k, mt_l, mt_o]=hhsave_util_2OC(varargin)
  17 

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

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

  27 
%% Assigning parameters
  28 

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

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

  0.046 
      1 
  62
fl_R = fl_r + fl_delta; 
  63 
%% Calling OC2
  64 

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

  69 
%% Computing consumption     
  70 

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

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

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

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

  84 
%% Computing utility     
  85 

  86 
%mt_con(neg) = NaN;
  87 

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

  95 
%% Printing outputs 
  96 

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

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