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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
/*
* CALCULATE THE VALUE OF CHOOSING CAPITAL K'(M) AND ASSET HOLDINGS B'(N) WHEN THE INITIAL STATE IS
* GIVEN BY (L,J,I)
*/
skip=0;
test2=switching;
/* A. calculate labor, int'l inputs allocations for given K(I), S(IS) assuming credit constraint does
not bind; note that they are independent of K' and B' */
for(i=0;i<ne;i=i+1){
for(j=0;j<nb;j=j+1){
for(l=0;l<nk;l=l+1){
kzt[i][j][l]=-999999999;
kz2[i][j][l]=-999999999;
}
}
} // initialize the values of kzt and kz2 to make sure that we don't stop at the first iteration
for(con5=0;con5<all;con5=con5+1){ // every 26 iterations
con=con+1; // add one every time it loops
while(con<maxit){ // whenever con<2000
if(test2<switching){
skip=1; // when V is similar to VA, restart maximization
}
for(i=0;i<ne;i=i+1){ // this period's shocks
tempa=sa[i]; // the value of TFP for this specific combination of shocks
tempr=sr[i]-1; // the value of world interest rate
tempqb=qb[i]; // the value of bond price
tempp=sp[i]; // the value of int'l goods price
for(j=0;j<nb;j=j+1){ // this period's bond
for(l=0;l<nk;l=l+1){ // this period's capital
tempk=k[l]; // the value of capital
templ=pow(tempp/eta,eta)*pow(alpha/(1+taxbar),eta-1)*pow((1+phi*tempr)/(tempa*a*pow(tempk,beta)),1/(omega*(eta-1)+alpha)); // the value of labor
tempv=pow(tempp/eta,1-alpha/omega)*pow(alpha/(1+taxbar),-alpha/omega)*pow((1+phi*tempr)/(tempa*a*pow(tempk,beta)),omega/(omega*(eta-1)+alpha)); // the value of imported goods
tempy=tempa*A*pow(tempk,beta)*pow(templ,alpha)*pow(tempv,eta); // the value of output
tempi=(alpha*tempa*A*pow(tempk,beta)*pow(templ,alpha-1)*pow(tempv,eta))/(1+taxbar)-tempp*tempv*(1+phi*tempr); // the value of investment
/* conventional maximization step of the Bellman equation (done each "FULL" of "ALL" VF iterations) */
kkn[l][j][i]=1; // get ready to start keeping track of where I am in that matrix
bbn[l][j][i]=1; // get ready to start keeping track of where I am in that matrix
VA[l][j][i]=-999999999; // set the value function to equal to negative infinity
for(n=0;n<nb;n=n+1){ // next period's bond
for(m=0;m<nk;m=m+1){ // next period's capital
tempq=(k[m]-k[l])/k[l]; // the value of the price of equity
/* check first if at candidate kkn and bbn the constraint binds, if it does, recalculate L, V, and Y for binding case */
if(binding=1){ // if the collateral constraint is binding
tempcolat=-(1-kappa)*(1+a*tempq)*k[m]; // the collateral constraint
if(tempqb*bond[n]-phi*(1+tempr)*(tempp*tempv+(1+taxbar)*pow(templ,omega))<=tempcolat){ // if the collateral constraint is binding
templb=pow((tempqb*bond[n]-tempcolat)/(phi*(1+tempr)*(1+taxbar)*(1+eta/alpha)),1/omega); // labor with collateral constraint binding
tempvb=(tempqb*bond[n]-tempcolat)/(phi*(1+tempr)*tempp*(1+alpha/eta)); // foreign inputs under collateral constraint
if(templb>=0 & tempvb>=0){
tempyb=tempa*A*pow(tempk,beta)*pow(templb,alpha)*pow(tempvb,eta); // output under collateral constraint
p1nval=(tempyb-tempp*tempvb-(k[m]-k[l])*(1+a*tempq/2)-phi*tempr*(tempp*tempvb+(1+taxbar)*pow(templb,omega))-k[l]*delta+bond[j]-tempqb*bond[n])/(1+taxbar)-pow(templb,omega)/omega; // the value in the utility function with the collateral constraint binding
}
} // when the constraint binds, what the value in the utility function is
} // if the collateral constraint is binding, use the values of variables under the binding constraint
else{
p1nval=(tempy-tempp*tempv-(k[m]-k[l])*(1+a*tempq/2)-phi*tempr*(tempp*tempv+(1+taxbar)*pow(templ,omega))-tempk*delta+bond[j]-tempqb*bond[n])/(1+taxbar)-pow(templ,omega)/omega; // the value in the utility function when the collateral constraint is not binding
} // when the constraint doesn't bind, what the value in the utility function is
if(p1nval > 0){ // this is when the situation is normal; otherwise we don't consider this situation
expv=0;
for(o=0;o<ne;o=o+1){
if(V[m][n][o]>=-999999999){
expv=pi[o][i]*V[m][n][o]+expv; // p are the transition probabilities, V are the value functions
}
} // get the expected value
p1n[m][n]=pow(p1nval,1-sigma)/(1-sigma)+pow(1+p1nval,-gamma)*expv; //
if(p1n[m][n]>=VA[l][j][i]){
kkn[l][j][i]=m; // keep track of the largest value; which value of capital achieves this
bbn[l][j][i]=n; // keep track of the largest value; which value of bond achieves this
VA[l][j][i]=p1n[m][n];
} // if the value function has a larger value for these values of next period's k and b, then the value function takes this larger value; otherwise, the value function stays the same
}
} // loop for next period's capital
} // loop for next period's bond
if(skip==1){ // if V is similar to VA, change to a new k
continue;
}
if(con5<full){ // for the first two of 26 iterations, change to a new k
continue;
}
// VA[l][j][i]=(tempy-tempp*tempv-(k[m]-k[l])*(1+a/2*(k[m]-k[l])/k[l])-phi*tempr*(tempp*tempv+(1+taxbar)*pow(templ,omega))-k[l]*delta+bond[j]-bond[n]/(tempr+1))/(1+taxbar)-pow(templ,omega)/omega;
if(VA[l][j][i]<0){
VA[l][j][i]=-999999999;
continue; // pick a new k
}
expv=0;
for(o=0;o<ne;o=o+1){
if(V[m][n][o]<-999999999){
VA[l][j][i]=-999999999;
continue;
}
expv=pi[o][i]*V[m][n][o]+expv;
}
VA[l][j][i]=pow(VA[l][j][i],1-sigma)/(1-sigma)+expv/pow(1+VA[l][j][i],gamma);
} // loop for this period's capital
} // loop for this period's bonds
} // loop for this period's shocks
|