|
1 |
| -function [V,Policy2]=ValueFnIter_Case1_FHorz_ResidAsset_raw(n_d,n_a,n_r,n_z,N_j, d_grid, a_grid, r_grid, z_gridvals_J, pi_z_J, ReturnFn, Parameters, DiscountFactorParamNames, ReturnFnParamNames, vfoptions) |
| 1 | +function [V,Policy2]=ValueFnIter_Case1_FHorz_ResidAsset_raw(n_d,n_a,n_r,n_z,N_j, d_grid, a_grid, r_grid, z_gridvals_J, pi_z_J, ReturnFn, rprimeFn, Parameters, DiscountFactorParamNames, ReturnFnParamNames, rprimeFnParamNames, vfoptions) |
2 | 2 |
|
3 | 3 | N_d=prod(n_d);
|
4 | 4 | N_a=prod(n_a);
|
|
70 | 70 | rprimeFnParamsVec=CreateVectorFromParams(Parameters, rprimeFnParamNames,N_j);
|
71 | 71 | [rprimeIndexes,rprimeProbs]=CreateResidualAssetFnMatrix_Case1(rprimeFn, n_d, n_a, n_r, n_z, d_grid, a_grid, r_grid, z_gridvals_J(:,:,N_j), rprimeFnParamsVec); % Note, is actually rprime_grid (but r_grid is anyway same for all ages)
|
72 | 72 | % Note: rprimeIndex is [N_d*N_a*N_a*N_z,1], and rprimeProbs is [N_d*N_a*N_a*N_z,1]
|
73 |
| - aprimeIndexes=kron(ones(N_a*N_z,1),(1:1:N_a)'); % aprime over (d,aprime,a,z) |
74 |
| - zprimeIndexes=kron((1:1:N_z)',ones(N_a*N_a,1)); % zprime over (d,aprime,a,z) |
| 73 | + aprimeIndexes=repelem(repmat((1:1:N_a)',N_a*N_z,1),N_d,1); % aprime over (d,aprime,a,z) |
| 74 | + zprimeIndexes=repelem((1:1:N_z)',N_d*N_a*N_a,1); % zprime over (d,aprime,a,z) |
75 | 75 |
|
76 | 76 | % lower r index (size is N_d*N_a*N_a*N_z)
|
77 | 77 | fullindex=aprimeIndexes+N_a*(rprimeIndexes-1)+N_a*N_r*(zprimeIndexes-1); % index for (a',r',z'), as function of (d,a',a,z)
|
|
98 | 98 | EV(isnan(EV))=0; %multilications of -Inf with 0 gives NaN, this replaces them with zeros (as the zeros come from the transition probabilites)
|
99 | 99 | EV=sum(EV,3); % sum over z', leaving a singular second dimension
|
100 | 100 |
|
101 |
| - entireRHS=ReturnMatrix+DiscountFactorParamsVec*(reshape(EV,[N_d*N_a,N_a,1,N_z]); %.*ones(1,1,N_r,1)); |
102 |
| - |
| 101 | + entireRHS=ReturnMatrix+DiscountFactorParamsVec*(reshape(EV,[N_d*N_a,N_a,1,N_z])); |
| 102 | + |
103 | 103 | %Calc the max and it's index
|
104 | 104 | [Vtemp,maxindex]=max(entireRHS,[],1);
|
105 | 105 |
|
|
117 | 117 | EV_z(isnan(EV_z))=0; %multilications of -Inf with 0 gives NaN, this replaces them with zeros (as the zeros come from the transition probabilites)
|
118 | 118 | EV_z=sum(EV_z,3); % sum over z', leaving a singular second dimension
|
119 | 119 |
|
120 |
| - entireRHS_z=ReturnMatrix_z+DiscountFactorParamsVec*(reshape(EV_z,[N_d*N_a,N_a,1]); %.*ones(1,1,N_r)); |
121 |
| - |
| 120 | + entireRHS_z=ReturnMatrix_z+DiscountFactorParamsVec*(reshape(EV_z,[N_d*N_a,N_a,1])); |
| 121 | + |
122 | 122 | %Calc the max and it's index
|
123 | 123 | [Vtemp,maxindex]=max(entireRHS_z,[],1);
|
124 | 124 | V(:,:,z_c,N_j)=Vtemp;
|
|
135 | 135 | EV_z(isnan(EV_z))=0; %multilications of -Inf with 0 gives NaN, this replaces them with zeros (as the zeros come from the transition probabilites)
|
136 | 136 | EV_z=sum(EV_z,3); % sum over z', leaving a singular second dimension
|
137 | 137 |
|
138 |
| - entireRHS_z=ReturnMatrix_z+DiscountFactorParamsVec*(reshape(EV_z,[N_d*N_a,N_a,1]); %.*ones(1,1,N_r)); |
139 |
| - |
| 138 | + entireRHS_z=ReturnMatrix_z+DiscountFactorParamsVec*(reshape(EV_z,[N_d*N_a,N_a,1])); |
| 139 | + |
140 | 140 | %Calc the max and it's index
|
141 | 141 | [Vtemp,maxindex]=max(entireRHS_z,[],1);
|
142 | 142 | V(:,:,z_c,N_j)=Vtemp;
|
|
178 | 178 | DiscountFactorParamsVec=CreateVectorFromParams(Parameters, DiscountFactorParamNames,jj);
|
179 | 179 | DiscountFactorParamsVec=prod(DiscountFactorParamsVec);
|
180 | 180 |
|
181 |
| - VKronNext_j=V(:,:,jj+1); |
| 181 | + VKronNext_j=V(:,:,:,jj+1); |
182 | 182 |
|
183 | 183 | % Residual asset:
|
184 | 184 | % VKronNext_j is over (aprime,r,z)
|
185 | 185 | % Need to convert to be over (d,aprime,a,z)
|
186 | 186 | rprimeFnParamsVec=CreateVectorFromParams(Parameters, rprimeFnParamNames,jj);
|
187 | 187 | [rprimeIndexes,rprimeProbs]=CreateResidualAssetFnMatrix_Case1(rprimeFn, n_d, n_a, n_r, n_z, d_grid, a_grid, r_grid, z_gridvals_J(:,:,jj), rprimeFnParamsVec); % Note, is actually rprime_grid (but r_grid is anyway same for all ages)
|
188 | 188 | % Note: rprimeIndex is [N_d*N_a*N_a*N_z,1], and rprimeProbs is [N_d*N_a*N_a*N_z,1]
|
189 |
| - aprimeIndexes=kron(ones(N_a*N_z,1),(1:1:N_a)'); % aprime over (d,aprime,a,z) |
190 |
| - zprimeIndexes=kron((1:1:N_z)',ones(N_a*N_a,1)); % zprime over (d,aprime,a,z) |
| 189 | + aprimeIndexes=repelem(repmat((1:1:N_a)',N_a*N_z,1),N_d,1); % aprime over (d,aprime,a,z) |
| 190 | + zprimeIndexes=repelem((1:1:N_z)',N_d*N_a*N_a,1); % zprime over (d,aprime,a,z) |
191 | 191 |
|
192 | 192 | % lower r index (size is N_d*N_a*N_a*N_z)
|
193 | 193 | fullindex=aprimeIndexes+N_a*(rprimeIndexes-1)+N_a*N_r*(zprimeIndexes-1); % index for (a',r',z'), as function of (d,a',a,z)
|
|
211 | 211 | EV(isnan(EV))=0; %multilications of -Inf with 0 gives NaN, this replaces them with zeros (as the zeros come from the transition probabilites)
|
212 | 212 | EV=sum(EV,3); % sum over z', leaving a singular second dimension
|
213 | 213 |
|
214 |
| - entireRHS=ReturnMatrix+DiscountFactorParamsVec*(reshape(EV,[N_d*N_a,N_a,1,N_z]); %.*ones(1,1,N_r,1)); |
215 |
| - |
| 214 | + entireRHS=ReturnMatrix+DiscountFactorParamsVec*(reshape(EV,[N_d*N_a,N_a,1,N_z])); |
| 215 | + |
216 | 216 | %Calc the max and it's index
|
217 | 217 | [Vtemp,maxindex]=max(entireRHS,[],1);
|
218 | 218 |
|
|
229 | 229 | EV_z(isnan(EV_z))=0; %multilications of -Inf with 0 gives NaN, this replaces them with zeros (as the zeros come from the transition probabilites)
|
230 | 230 | EV_z=sum(EV_z,3); % sum over z', leaving a singular second dimension
|
231 | 231 |
|
232 |
| - entireRHS_z=ReturnMatrix_z+DiscountFactorParamsVec*(reshape(EV_z,[N_d*N_a,N_a,1]); %.*ones(1,1,N_r)); |
233 |
| - |
| 232 | + entireRHS_z=ReturnMatrix_z+DiscountFactorParamsVec*(reshape(EV_z,[N_d*N_a,N_a,1])); |
| 233 | + |
234 | 234 | %Calc the max and it's index
|
235 | 235 | [Vtemp,maxindex]=max(entireRHS_z,[],1);
|
236 | 236 | V(:,:,z_c,jj)=Vtemp;
|
|
247 | 247 | EV_z(isnan(EV_z))=0; %multilications of -Inf with 0 gives NaN, this replaces them with zeros (as the zeros come from the transition probabilites)
|
248 | 248 | EV_z=sum(EV_z,3); % sum over z', leaving a singular second dimension
|
249 | 249 |
|
250 |
| - entireRHS_z=ReturnMatrix_z+DiscountFactorParamsVec*(reshape(EV_z,[N_d*N_a,N_a,1]); %.*ones(1,1,N_r)); |
251 |
| - |
| 250 | + entireRHS_z=ReturnMatrix_z+DiscountFactorParamsVec*(reshape(EV_z,[N_d*N_a,N_a,1])); |
| 251 | + |
252 | 252 | %Calc the max and it's index
|
253 | 253 | [Vtemp,maxindex]=max(entireRHS_z,[],1);
|
254 | 254 | V(:,:,z_c,jj)=Vtemp;
|
|
0 commit comments