-
Notifications
You must be signed in to change notification settings - Fork 19
/
updateCoefficients_polynomials.m
77 lines (61 loc) · 3.22 KB
/
updateCoefficients_polynomials.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function mCoefficientsNew = updateCoefficients_polynomials(mCoefficients)
% Updates polynomial coefficients approximating the conditional expectation function in steady state
%
% Inputs
% (1) mCoefficients: nEpsilon x nAssets matrix, storing previous iteration's coefficients
%
% Outputs
% (1) mCoefficientsNew: nEpsilon x nAssets matrix, storing updated coefficients
%
% Thomas Winberry, January 19, 2016
% Declare global variables
global bbeta ssigma aaBar mmu ttau mEpsilonTransition ...
nEpsilon nAssets nState assetsMin assetsMax ...
mEpsilonGrid mAssetsGrid ...
vAssetsPoly vAssetsPolySquared w r mEpsilonPrimeGrid
%---------------------------------------------------------------
% Compute current period's savings policy function
%---------------------------------------------------------------
% Compute conditional expectation
mConditionalExpectation = exp(mCoefficients * vAssetsPoly');
% Compute target saving
mAssetsPrimeStar = w * (mmu * (1 - mEpsilonGrid) + (1 - ttau) * mEpsilonGrid) + (1 + r) * mAssetsGrid - ...
(mConditionalExpectation .^ (-1 / ssigma));
% Compute actual saving
% mAssetsPrime = max(mAssetsPrimeStar,aaBar * ones(nEpsilon,nAssets));
mAssetsPrime = max(mAssetsPrimeStar,aaBar);
mAssetsPrimeGrid = repmat(reshape(mAssetsPrime,1,nState),[nEpsilon 1]);
% Compute next period's polynomials
mAssetsPrimeZeros = scaleDown(mAssetsPrime,assetsMin,assetsMax);
mPolyAssetsPrime = computeChebyshev(nAssets,reshape(mAssetsPrimeZeros,nState,1));
%---------------------------------------------------------------
% Compute next period's savings policy function
%---------------------------------------------------------------
% Compute conditional expectation
mConditionalExpectationPrime = exp(mCoefficients * mPolyAssetsPrime');
% Compute target saving
mAssetsPrimePrimeStar = w * (mmu * (1 - mEpsilonPrimeGrid) + (1 - ttau) * mEpsilonPrimeGrid) + (1 + r) * mAssetsPrimeGrid - ...
(mConditionalExpectationPrime .^ (-1 / ssigma));
% Compute actual savings
% mAssetsPrimePrimeGrid = max(mAssetsPrimePrimeStar,aaBar*ones(nEpsilon,nEpsilon*nAssets));
mAssetsPrimePrimeGrid = max(mAssetsPrimePrimeStar,aaBar);
%---------------------------------------------------------------
% Update conditional expectation function
%---------------------------------------------------------------
% Compute new conditional expectation function
mConsumptionPrime = w * (mmu * (1 - mEpsilonPrimeGrid) + (1 - ttau) * mEpsilonPrimeGrid) + (1 + r) * ...
mAssetsPrimeGrid - mAssetsPrimePrimeGrid;
aConditionalExpectationTilde = reshape(bbeta * mEpsilonTransition * ((1 + r) * (mConsumptionPrime .^ (-ssigma))),...
nEpsilon,nEpsilon,nAssets);
% Extract the relevant entries
mConditionalExpectation = zeros(nEpsilon,nAssets);
for iEpsilon = 1:nEpsilon
mConditionalExpectation(iEpsilon,:) = aConditionalExpectationTilde(iEpsilon,iEpsilon,:);
end
% Update the coefficients
mCoefficientsNew = zeros(nEpsilon,nAssets);
for iEpsilon = 1:nEpsilon
% vCoefficients = sum(vAssetsPoly' .* (ones(nAssets,1) * log(mConditionalExpectation(iEpsilon,:))),2);
vCoefficients = vAssetsPoly' * log(mConditionalExpectation(iEpsilon,:))';
mCoefficientsNew(iEpsilon,:) = (vCoefficients ./ vAssetsPolySquared)';
end