%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Program name: ECO387vf_cheb.m
%
% This program generates the same value functions and
% decision rules for the code attached to HW #8, only
% the iterations in this code employs a Chebychev
% polynomial approximation to the value functions as
% opposed to a grid search technique.
%
% 4.23.02, Written by Scott Dressler
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
clc
fprintf('---------------------------------------')
fprintf('\n\tValue Function Iteration \n\tusing Chebychev Polynomials\n')
fprintf('---------------------------------------')
% Define model parameters...
BETA = 0.995; % discount
SIG = 1.5; % CRRA
Y = 1; % normalized earnings when employed
H = 0.25; % income when unemployed
% Transition matrix associated with individual uncertainty...
PI = zeros(2,2);
PI(1,1) = 0.9565; % => E[emp|emp]
PI(1,2) = 1 - PI(1,1); % => E[une|emp]
PI(2,2) = 0.5; % => E[une|une]
PI(2,1) = 1 - PI(2,2); % => E[emp|une]
% Endogenous state => money holdings
% - Define a bounded region for the state variable and calculate
% the optimal points for the Chebychev polynomials.
% (see Atkinson, p. 211)
MMIN = 0; % Lower bound on money holdings
MMAX = 10.8; % Upper bound...
N = 20; % # of grid points for approximation
MVEC = cheby_points1(MMIN,MMAX,N); % optimal points for basis function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Value Function Iteration...
%
% Given the Chebychev points, the procedure below calculates
% an orthogonal family of degree 3 around these
% points with normalization -1= 1.e-5;
% Chebchev coefficients
b1 = TtT * T' * V1;
b2 = TtT * T' * V2;
% INSIDE LOOP: For every element of Mvec (the state) a maximize
% the VF which then gives you the decision rule.
for i = 1:N
M0 = MVEC(i); % The initial condition
if count == 0
x10 = Y; % Initial guess for state 1
x20 = H; % Initial guess for state 2
else
x10 = DR1(i);
x20 = DR2(i);
end
% The maximization problem (actually, its a minimization
% problem because that's the only type of algorithm
% MATLAB has - just multiply by THE RETURN FCN ONLY (-1)
% Constraints:
lb = 0;
ub1 = Y + M0;
ub2 = H + M0;
[DR1(i),VNEW1(i)] = fmincon(@VFUN1,x10,[],[],[],[],lb,ub1,[],opts,b1,b2,PARMS,M0);
[DR2(i),VNEW2(i)] = fmincon(@VFUN2,x20,[],[],[],[],lb,ub2,[],opts,b1,b2,PARMS,M0);
end
clear i
% Check tolerance: (using sup norm)
VTOL = max([max(abs(VNEW1 - V1)) max(abs(VNEW2 - V2))]);
% Update value functions:
V1 = VNEW1;
V2 = VNEW2;
count = count + 1;
end
toc;
% Find Smoother functions for Value functions and decision
% rules using a canned Spline interpolation technique.
MINT = linspace(MMIN,MMAX,500);
DR1INT = interp1(MVEC,DR1,MINT,'spline');
DR2INT = interpl(MVEC,DR2,MINT,'spline');
V1INT = interp1(MVEC,V1,MINT,'spline');
V2INT = interp1(MVEC,V2,MINT,'spline');
% Plot Results...
figure
plot(MINT,-V1INT,MINT,-V2INT,'--')
xlabel('Money Holdings')
ylabel('Value Function')
legend('Employed','Unemployed')
title('Fig 1: Smoothed Value Functions using Chebyshev Polynomials')
hold
figure
plot(MINT,DR1INT-MINT,MINT,DR2INT-MINT,'--')
xlabel('Money Holdings')
ylabel('(Level) Changes in Holdings')
legend('Employed','Unemployed')
title('Fig 2: Smoothed Decision Rules using Chebychev Polynomials')
hold
save IMROG MINT MVEC DR1 DR2 DR1INT DR2INT V1 V2 V1INT V2INT