% Code adapted from the work of Gualtiero Azzalini (IIES) clear close all clc %% Part (c) % generate the grid run grid % solve the model outputloss = 'quadratic'; %the options are 'constant' or 'quadratic' save loss_spec outputloss run solveEGVFI % simulate the model run simulateEG % statistics run statistics % debt distribution Figure1 = figure; bar(d,Ddistr); xlabel('Debt'); ylabel('%'); title('Debt Distribution') saveas(Figure1,'dist_quadratic.png') Figure2 = figure; plot(ya) hold on plot(y,'--') hold off xlabel('Grid point (y)') ylabel('Output') legend('Autarky', 'Good financial standing', 'Location', 'NorthWest') saveas(Figure2,'loss_quadratic.png') % save conditional average to calibrate the constant case save cond_av loss %% Part (d) close all % solve the model outputloss = 'constant'; %the options are 'constant' or 'quadratic' save loss_spec outputloss run solveEGVFI % simulate the model run simulateEG % statistics run statistics % debt distribution Figure3 = figure; bar(d,Ddistr); xlabel('Debt'); ylabel('%'); title('Debt Distribution') saveas(Figure3,'dist_constant.png') Figure4 = figure; plot(ya) hold on plot(y,'--') hold off xlabel('Grid point (y)') ylabel('Output') legend('Autarky', 'Good financial standing', 'Location', 'NorthWest') saveas(Figure4,'loss_constant.png') close all