I propose an updated version of BasicRealBusinessCycleModel.m
Nothing of substance, but something useful to interpret the model results:
- Convert policy from indices to values. Get policy for labor d(k,z) and policy for next-period capital k’(k,z).
- Add vfoptions=struct(); It is not really needed but is clearer that we are using the default settings.
2b) Add vfoptions for grid interpolation BUT commented out, just to tell users that there is this option, but is more advanced.
- Add plots for policy functions, besides the plot for value function.
% Example using a variant of the Basic RBC model (following Aruoba, Fernandez-Villaverde, & Rubio-Ramirez, 2006)
%
% Note: On GPU this will take fractions of a second, on CPUs you will want to make the grids smaller (n_d,n_a,n_z) or it will take a while.
clear
tic;
UseAlternativeParams=1;
%% Set up
% Number of grid points
n_d=50;
n_a=250;
n_z=21; %Note, for the figures to correctly use z=0 this must be an odd number (make it 39)
%Discounting rate
Params.beta = 0.9896;
%Parameter values
Params.alpha = 0.4; % alpha
Params.theta=0.357;
Params.rho = 0.95; % rho
Params.tau=2;
Params.delta = 0.0196; % delta
Params.sigma_epsilon=0.007;
if UseAlternativeParams==1
Params.tau=50;
Params.sigma_epsilon=0.035;
end
%% Compute the steady state (just use these when picking grids)
varphi=(1/Params.alpha*(1/Params.beta-1+Params.delta))^(1/(1-Params.alpha));
Psi=Params.theta/(1-Params.theta)*(1-Params.alpha)*varphi^(-Params.alpha);
Omega=varphi^(1-Params.alpha)-Params.delta;
K_ss=Psi/(Omega+varphi*Psi);
%% Create grids (it is very important that each grid is defined as a column vector)
Tauchen_q=3; %Parameter for the Tauchen method
[z_grid,pi_z]=discretizeAR1_Tauchen(0,Params.rho,Params.sigma_epsilon,n_z,Tauchen_q);
a_grid=linspace(0.01,5*K_ss,n_a)';
d_grid=linspace(0,1,n_d)';
%% Now, create the return function
DiscountFactorParamNames={'beta'};
ReturnFn=@(d_val,aprime_val, a_val, s_val,alpha,delta,theta,tau) BasicRealBusinessCycleModel_ReturnFn(d_val,aprime_val, a_val, s_val,alpha,delta,theta,tau);
%% Solve
%Do the value function iteration. Returns both the value function itself, and the optimal policy function.
vfoptions = struct(); % Use default options
% If you want to solve the VFI using linear interpolation (GPU only), uncomment the following:
% vfoptions.gridinterplayer = 1;
% vfoptions.ngridinterp = 15; % number of extra points between grid points
% simoptions.gridinterplayer = vfoptions.gridinterplayer;
% simoptions.ngridinterp = vfoptions.ngridinterp;
[V,Policy]=ValueFnIter_Case1(n_d,n_a,n_z,d_grid,a_grid,z_grid, pi_z, ReturnFn, Params, DiscountFactorParamNames,[]);
time1=toc;
% Convert policy from indices to values
PolicyValues = PolicyInd2Val_Case1(Policy, n_d, n_a, n_z, d_grid, a_grid, vfoptions);
PolicyValues_d = squeeze(PolicyValues(1,:,:));
PolicyValues_k = squeeze(PolicyValues(2,:,:));
%% Report some output
fprintf('Run time for value function iteration: %8.2f seconds \n', time1)
%% Graph of the value function.
figure(1)
surf(a_grid*ones(1,n_z), ones(n_a,1)*z_grid', V)
%% Graph of the policy function
figure(2)
plot(a_grid,a_grid,'--')
hold on
plot(a_grid,PolicyValues_k(:,1))
hold on
plot(a_grid,PolicyValues_k(:,n_z))
legend('45 line','Given z(1)','Given z(n_z)')
title('Policy function for next period capital')
xlabel('Current period capital')
figure(3)
plot(a_grid,PolicyValues_d(:,1))
hold on
plot(a_grid,PolicyValues_d(:,n_z))
legend('Given z(1)','Given z(n_z)')
title('Policy function for labor')
xlabel('Current period capital')