time | Calls | line |
---|
| | 16 | function [mt_util,mt_coh, mt_k, mt_l, mt_o]=hhsave_util_2OC(varargin)
|
| | 17 |
|
0.001 | 1 | 18 | close all;
|
< 0.001 | 1 | 19 | bl_profile = false; % Switch off profile if running a tester/calling from another function
|
< 0.001 | 1 | 20 | if(bl_profile)
|
| | 21 | profile off;
|
| | 22 | profile on;
|
| | 23 | end
|
| | 24 |
|
0.431 | 1 | 25 | addpath(genpath('/Users/sidhantkhanna/Documents/GitHub/BKS modified/'));
|
| | 26 |
|
| | 27 | %% Assigning parameters
|
| | 28 |
|
< 0.001 | 1 | 29 | if ~isempty(varargin)
|
| | 30 |
|
0.002 | 1 | 31 | [ar_a,ar_z, ...
|
| 1 | 32 | fl_alpha,fl_theta,fl_delta,fl_kappa,fl_r,fl_w,fl_phi,fl_ahi,fl_zhi, ...
|
| 1 | 33 | fl_risk,it_zgridno, it_agridno, ...
|
| 1 | 34 | ] = varargin{:};
|
| | 35 |
|
< 0.001 | 1 | 36 | bl_print = false;
|
| | 37 |
|
| | 38 |
|
| | 39 | else
|
| | 40 | close all;
|
| | 41 |
|
| | 42 | fl_ahi = 5;
|
| | 43 | fl_zhi = 2.2;
|
| | 44 | it_agridno = 4;
|
| | 45 | it_zgridno = 5;
|
| | 46 | ar_a = linspace(0,fl_ahi,it_agridno);
|
| | 47 | ar_z = linspace(1,fl_zhi,it_zgridno);
|
| | 48 | fl_phi = 0.5;
|
| | 49 | fl_risk = 2;
|
| | 50 |
|
| | 51 | fl_alpha = 0.4;
|
| | 52 | fl_theta = 0.79-fl_alpha;
|
| | 53 | fl_delta = 0.05;
|
| | 54 | fl_kappa = 0;
|
| | 55 |
|
| | 56 | [fl_r,fl_w] = ...
|
| | 57 | deal(0.05,1.5);
|
| | 58 | bl_print = true;
|
| | 59 |
|
< 0.001 | 1 | 60 | end
|
| | 61 |
|
< 0.001 | 1 | 62 | fl_R = fl_r + fl_delta;
|
| | 63 | %% Calling OC2
|
| | 64 |
|
1.402 | 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.001 | 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)
|
< 0.001 | 1 | 89 | mt_util=log(mt_con);
|
| | 90 | else
|
| | 91 | mt_util= (mt_con.^(1-fl_risk) -1)/(1-fl_risk); % Utility Part of value function
|
< 0.001 | 1 | 92 | end
|
< 0.001 | 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)
|
| | 98 | disp('Below is the COH matrix for for all combinations of a, z and future a');
|
| | 99 | disp(mt3_coh);
|
| | 100 | disp('Below is the future assets matrix for each combination of a, z and future a');
|
| | 101 | disp(mt_futassets);
|
| | 102 | disp('Below is the consumption matrix for for all combinations of a, z and future a');
|
| | 103 | disp(mt_con);
|
| | 104 | disp('Below is the utility matrix for for all combinations of a, z and future a');
|
| | 105 | disp(mt_util);
|
| | 106 | end
|
| | 107 |
|
< 0.001 | 1 | 108 | if(bl_profile)
|
| | 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
|