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
|