Commits

stevejb committed ff55642

Fixed a boundary error. Define BARR_FIXINDEX to see the debug information

Comments (0)

Files changed (1)

 ////////////////////////////////////////////////////////////////////////////////
 //  DEBUG STUFF
 
+#undef BARR_FIXINDEX
+
 #undef DOTRENDPRINT
 #define TRENDPRINT false
 #define DBGPRINT false
       }    // end if mapping
     } // end for t in T
   } // end for n in N
-
+  cout << "Pathsim is over" << endl;
+  cout << "Pathsim is " << pathsim.rows() << "x" << pathsim.cols() << endl;
+  cout << "Shockstates is " << shockstates.rows() << "x" << shockstates.cols() << endl;
   MatrixRMXd ztrend_mat  = cumprod_rows(epsP.array().exp());
 
-  #pragma omp parallel for private(adj_cost, adjustment, cur_value, d_indic, debt, e_gross_eq, egross2, exp_theta_frac_z, ext_equity_cost, inv, k_cur, k_nt, k_prev, k_prev_idx, leverage, operating_income_val, Phi_e, p_cur, p_nt, p_prev, p_prev_idx, profit, shockidx, value_cur, zp_nt, zt_nt)
+#pragma omp parallel for private(adj_cost, adjustment, cur_value, d_indic, debt, e_gross_eq, egross2, exp_theta_frac_z, ext_equity_cost, inv, k_cur, k_nt, k_prev, k_prev_idx, leverage, operating_income_val, Phi_e, p_cur, p_nt, p_prev, p_prev_idx, profit, shockidx, value_cur, zp_nt, zt_nt)
   for(int n = 0; n < Nsim; n++) {
     double zpp_TRENDED_initial = 0.0;
     for(int t = 0; t < T; t++) {
 
+#ifdef BARR_FIXINDEX
+      cout << "start mapping" << endl;
+#endif
+#ifdef BARR_FIXINDEX
+      if( mapping == NULL) {
+	cout << "NULL MAP" << endl;
+      } else {
+	cout << "A MAP" << endl;
+      }
+#endif
       // DUE TO SOME POOR NAMING, zp_nt is actually epsilon^P_nt
       if( mapping == NULL) {
+#ifdef BARR_FIXINDEX
+	cout << "Pathsim N: " << n << " T: " << t  << endl;
+	cout << "   pathsim(n,t): " << pathsim(n,t) << endl;
+#endif
         zt_nt = shockstates(pathsim(n,t),0);
         zp_nt = shockstates(pathsim(n,t),1);
       } else {
         zt_nt = shockstates(mapping[pathsim(n,t)],0);
         zp_nt = shockstates(mapping[pathsim(n,t)],1);
       }
-
+#ifdef BARR_FIXINDEX
+      cout << "end mapping" << endl;
+#endif
 
       // get k,k',p,p', lag of zp
       if(t > 0) {
 	p_prev	= p_prev * ztrend_mat(n, (t-1));
 	p_nt	= p_nt   * ztrend_mat(n, t);
 
+#ifdef BARR_FIXINDEX
+      cout << "done with kp" << endl;
+#endif
+
         exp_theta_frac_z = exp(theta_frac * zp_nt);
 
         // FIX THE INDEXING OF -- DONE
 
       if(t > 0) {
 
+#ifdef BARR_FIXINDEX
+      cout << "start quantities" << endl;
+#endif
         // CALC INTERTEMPORAL MOMENTS
         value_cur = value(pathsim(n,t), sim_control(n,t-1));
 
         ext_equity_cost = par.lambda_1 * e_gross_eq;
 
 
+#ifdef BARR_FIXINDEX
+      cout << "end quantities" << endl;
+#endif
 	// // THIS IS PROBABLY FOOLISH
         // inv =  (k_nt / exp_theta_frac_z) - (1.0 -  par.delta) * k_prev;
         // debt = p_nt * exp(zpp_TRENDED_cur) - R * p_prev;
         // e_gross_eq = profit - inv + debt - adj_cost;
         // ext_equity_cost = par.lambda_1 * e_gross_eq;
 
-
+#ifdef BARR_FIXINDEX
+      cout << "Equity issuance" << endl;
+#endif
         // AM I ISSUING EQUITY?
         if(e_gross_eq < 0) {
           Phi_e = 1.0;
 
       // RECORD THE MOMENTS
       if(t > 0) {
+#ifdef BARR_FIXINDEX
+	cout << "[START] Recording moments at t=" << t << endl;
+#endif
         inv_MOMENT(n, t-1) = inv / k_prev;
         lev_MOMENT(n, t-1) = leverage;
         eq_issuance_MOMENT(n, t-1) = e_gross_eq / k_prev;
 	epsilon_P_RAW(n,t-1) = zp_nt;
 #endif
 
-	debt_RAW(n,t) = debt / k_prev;
+	debt_RAW(n,t-1) = debt / k_prev;
         // // cash balance
         // if(debt < 0) {
         //   cash_balance_MOMENT.push_back(debt/k_prev);
         // }
+#ifdef BARR_FIXINDEX
+	cout << "[END] Recording moments at t=" << t << endl;
+#endif
 
       } // END IF ( t > 0 )
 
     //cout << endl << endl;
   } // end for n in Nsim
   // END PARALLEL FOR
-
+  cout << "end of the parallel for" << endl;
   // populate the cash balances
   cout << "Start CBM" << endl;
+#ifdef BARR_FIXINDEX
+  cout << "debt_RAW is " << debt_RAW.rows() << "x" << debt_RAW.cols() << endl;
+#endif
   for(int n = 0; n < Nsim; n++) {
-    for(int t = 0; t < T; t++) {
+    for(int t = 0; t < (T-1); t++) {
       if(debt_RAW(n,t) < 0) {
 	cash_balance_MOMENT.push_back(debt_RAW(n,t));
       }