/* * "Nash or Ramsey Inflation" by Sargent, Williams, and Zha (SWZ). * * Copywright (c) by Sargent, Williams, and Zha, June 2004. * Revisions, 03/17/05; */ //-------------- Model Economy as a Whole. --------------------- #include "swz_comfuns.h" FILE *fptr_debug = NULL; //Debug output file. #define SCALERANINI (1.0) //(0.5) Scale factor for indxStartValuesForMin == 1. typedef TSconstmodpars *TFDestroyTSconstmodpars(TSconstmodpars *); typedef TSgovprob *TFDestroyTSgovprob(TSgovprob *); typedef struct TSetc_swz_tag { //For optimization of the posterior or likelihood function. TSconstmodpars *constmodpars_ps; TSconstmodpars *(*DestroyTSconstmodpars)(TSconstmodpars *); TSgovprob *govprob_ps; TSgovprob *(*DestroyTSgovprob)(TSgovprob *); } TSetc_swz; //------ For the minimization problem. ------- static TSetc_swz *CreateTSetc_swz(TSconstmodpars **constmodpars_pps, TFDestroyTSconstmodpars *DestroyTSconstmodpars_func, TSgovprob **govprob_pps, TFDestroyTSgovprob *DestroyTSgovprob_func); static TSetc_swz *DestroyTSetc_swz(TSetc_swz *etc_swz_ps); //+ static void InitializeForMinproblem(struct TSminpack_tag *minpack_ps, TSinput *input_ps, char *filename_sp, int indxStartValuesForMin); static double minneglogpost(struct TSminpack_tag *minpack_ps); //+ static void ngo_InitializeForMinproblem(struct TSminpack_tag *minpack_ps, TSinput *input_ps, int indxStartValuesForMin); static double ngo_minneglogpost(struct TSminpack_tag *minpack_ps); //+ static void ftd_FprintOutput(TSinput *input_ps, TSminpack *minpack_ps); static void ftd_Fprint_uinf(FILE *fptr_inpfor_uinfs, TSminpack *minpack_ps); //static void ftd_priorsettings(TSconstmodpars *constmodpars_ps); //static double valuelogpost_refresh(struct TSminpack_tag *minpack_ps); //// //static void ftd_freepars2modpars(TSconstmodpars *constmodpars_ps); //static void ftd_modpars2freepars(TSconstmodpars *constmodpars_ps); //// //static ftd_normalizationforgov(TSconstmodpars *constmodpars_ps); //// //------ Revision 03/17/05: kth-step forecast of inflation. ------- static void ftd_kth_fcsts(FILE *fptr_k_infs, int ksteps_fcsts, int nlocs, int iniloc, struct TSinput_tag *input_ps, struct TSconstmodpars_tag *constmodpars_ps, struct TSgovprob_tag *govprob_ps, char *filename_fcsts); //---------------------------------------------------- // Main Program Begins Here. //---------------------------------------------------- int main(int n_arg, char **args_cl) { int indxStartValuesForMin; //0: randomly selects the initial starting values for the MLE or posterior estimate; //1: starts at the fixed values (a) manually keyed in (in the modeleconomy.c) if we solve for government optimization problem; // (b) from the input data file datainp_swz.prn if we do NOT solve for government optimization problem. //2: uses the starting piont (sp) file, filename_sp_vec_csminwel. int indxSwitchingModel; //1: switching model; 0: constant-parameter model. int simi; char *filenametag, //Point to the command line name tag. *filename_input, //Point to the command line input file name. *filename_fcsts, //Point to the command line output file name. filename_sp_vec_csminwel[128], //File name for starting point of vectorized (vec) parameters from the minimization problems with the /c 0 option. Must be allocated big enouch a string area. Increase the array length if necessary. //2 vectors. 1st row: gradient; 2nd row: vectorized parameters. filenamebuffer[128]; //Used for multiple file names, so must be allocated big enouch a string area. Increase the array length if necessary. //--- Added 03/17/05 for kth-step forecast of inflation. FILE *fptr_k_infs; int ksteps_fcsts = 48, //$$$$$$$Hard coded.$$$$$$$$$$ intloc = 0; //=== TSinput *input_ps = NULL; TSconstmodpars *constmodpars_ps = NULL; TSgovprob *govprob_ps = NULL; TSetc_swz *etc_swz_ps = NULL; TSminpack *minpack_csminwel_ps = NULL; FILE *fptr_input = NULL, //Input data file for basic data. *fptr_fcsts = NULL, //File pointer to output data file for forecasts of gov inflation, expected inflation, inflation, and unemployment. // *fptr_case = NULL, //Input data file for a specified case, such as constpce specified by filenametag. *fptr_inpfor_uinfs = NULL, //Writes inflation (and prediction) and Unemployment (and prediction) to a file for MCMC. *fptr_output = NULL; //Writes final output arguments to a file to be examined by us. //----------------- // Reads from the command line the user-specified input file and the most-often-used integer arguments such as sample size. //----------------- filenametag = fn_ParseCommandLine_String(n_arg,args_cl,'t',(char *)NULL); // File tag handle. if ( !filenametag ) fn_DisplayError("No case tag for file names is specified"); if (!strncmp("const", filenametag, 3)) indxSwitchingModel = 0; else fn_DisplayError(".../modeleconomy.c/main(): Make sure the filename tag on command line must contains const because we do not deal with regime switching type yet"); indxStartValuesForMin = fn_ParseCommandLine_Integer(n_arg,args_cl,'c',0); // Default number of states is 0. sprintf(filename_sp_vec_csminwel, "outdatasp_mle_%s.prn", filenametag); //+ filename_input = fn_ParseCommandLine_String(n_arg,args_cl,'i',"datainp_swz.prn"); // Input file handle. Default to datainp_swz.prn. fptr_input = tzFopen(filename_input,"r"); //+ filename_fcsts = fn_ParseCommandLine_String(n_arg,args_cl,'f',"outdataout_fcsts.prn"); // Input file handle. Default to outdataout_fcsts.prn // fptr_fcsts = tzFopen(filename_fcsts,"w"); // //+ // sprintf(filenamebuffer, "datainp_%s.prn", filenametag); // fptr_case = tzFopen(filenamebuffer,"r"); //Input data file for constant-parameter models. //+ sprintf(filenamebuffer, "outdata_debug_%s.prn", filenametag); fptr_debug = tzFopen(filenamebuffer,"w"); //Debug output file. //+ sprintf(filenamebuffer, "outdatainp_uinfs_%s.prn", filenametag); fptr_inpfor_uinfs = tzFopen(filenamebuffer, "w"); //+ sprintf(filenamebuffer, "outdataout_%s.prn", filenametag); fptr_output = tzFopen(filenamebuffer,"w"); //Final output file. //+ sprintf(filenamebuffer, "outdataout_%dth_fcstinfs%s.prn", ksteps_fcsts, filenametag); fptr_k_infs = tzFopen(filenamebuffer,"w"); //Final output file. //------- Memory allocation. ------- input_ps = CreateTSinput(fptr_input, fptr_output, filename_input, filenametag); if (!indxSwitchingModel) { constmodpars_ps = CreateTSconstmodpars(fptr_input, input_ps, (TFconstmodest *)NULL, (TFconstmodprob *)NULL); //fptr_input is added 03/17/05. //=== Added 03/17/05. if (constmodpars_ps->indxNoGovOpt) printf("\n\n******* First step: estimating V and P10 with no government optimization! *******\n\n"); else printf("\n\n******* Second step: estimating the parameters in the private sector with, perhaps, the government optimization! *******\n" "******* depending on the value of indxWhichModel. *******\n\n"); // if (constmodpars_ps->indxWhichModel & NGO_CGP2TP1TI0) //Reset to 1 (to read the MLEs for the first step produced by setting indxNoGovOpt is set to 1, 03/17/05. // indxStartValuesForMin = 1; constmodpars_ps->indxMLE = fn_ParseCommandLine_Integer(n_arg,args_cl,'m',1); // Default is set to ML estimation with no explicit prior. constmodpars_ps->indxStartValuesForMin = indxStartValuesForMin; govprob_ps = CreateTSgovprob(input_ps, constmodpars_ps, gensys_sims, govestimator, govoptimizer); //, 0); //Creates memory for government problem. etc_swz_ps = CreateTSetc_swz(&constmodpars_ps, (TFDestroyTSconstmodpars *)NULL, &govprob_ps, (TFDestroyTSgovprob *)NULL); if (constmodpars_ps->indxNoGovOpt) //Added 03/17/05. minpack_csminwel_ps = CreateTSminpack((TFminobj *)ngo_minneglogpost, (void **)&etc_swz_ps, (TFmindestroy_etcproject *)NULL, (TFmingrad *)NULL, filename_sp_vec_csminwel, constmodpars_ps->ngo_x_dv->n, MIN_CSMINWEL); else minpack_csminwel_ps = CreateTSminpack((TFminobj *)minneglogpost, (void **)&etc_swz_ps, (TFmindestroy_etcproject *)NULL, (TFmingrad *)NULL, filename_sp_vec_csminwel, constmodpars_ps->totnpars, MIN_CSMINWEL); } else fn_DisplayError("Swtiching case is not available yet"); //----------------- // Main matter. //----------------- time(&input_ps->prog_begtime); //Beginning time of the whole program. if (!indxSwitchingModel) { //=== Prior settings. Reallocates the memory to mean*set_dv and Var*Set_dm from CreateTSconstmodpars().. if (!constmodpars_ps->indxMLE) ftd_priorsettings(constmodpars_ps); //=== Finding the peak value of the logLH or logPosterior if (input_ps->indxEstFinder) { if (constmodpars_ps->indxNoGovOpt) //Added 03/17/05. { ngo_InitializeForMinproblem(minpack_csminwel_ps, input_ps, indxStartValuesForMin); //--- Getting the data for Kalman filtering; do not have time to get rid of solving the government's optiminization problem. govprob_ps->govestimator(govprob_ps, (void *)constmodpars_ps, POINTEST); minfinder(minpack_csminwel_ps); constmodpars_ps->ngo_maxLHvalue = ngo_value_loglh_refresh(constmodpars_ps, govprob_ps, minpack_csminwel_ps->x_dv); ftd_FprintOutput(input_ps, minpack_csminwel_ps); //Writes out the final output. return; //Early return for the 2nd step to find private-sector parameters. } else { InitializeForMinproblem(minpack_csminwel_ps, input_ps, filename_sp_vec_csminwel, indxStartValuesForMin); //--- Refreshing V and P10 using the non-government-optimization solution of P10 and V. Added 03/17/05. if (constmodpars_ps->indxWhichModel & NGO_CGP2TP1TI0) { ngo_freepars2modpars((void *)constmodpars_ps, POINTEST); ftd_freepars2modpars((void *)constmodpars_ps, POINTEST); } minfinder(minpack_csminwel_ps); } } else { if (constmodpars_ps->indxNoGovOpt) //Added 03/17/05. fn_DisplayError("main(): in first-step optimization: you must turn on indxEstFinder = 1 when indxNoGovOpt == 1"); InitializeForMinproblem(minpack_csminwel_ps, input_ps, filename_sp_vec_csminwel, 2); //--- Refreshing V and P10 using the non-government-optimization solution of P10 and V. Added 03/17/05. if (constmodpars_ps->indxWhichModel & NGO_CGP2TP1TI0) ngo_freepars2modpars((void *)constmodpars_ps, POINTEST); } //=== Refreshes government's controled inflation, expected inflation, copying x_dv to constmodpars_ps, etc. //=== Must get constmodpars_ps->upred_dv for historical decomposition in forecasting. constmodpars_ps->peaklogpost = value_logpostkernal_refresh(constmodpars_ps, (struct TSconstgibbs_tag *)NULL, POINTEST, govprob_ps, minpack_csminwel_ps->x_dv); //=== Forecasts of government inflation, expected inflation, inflation, and unemployment. if (input_ps->indxFcsts) { fptr_fcsts = tzFopen(filename_fcsts,"w"); //Output file for forecasts. InitializeGlobleSeed(input_ps->randomseed); //Initializing the seednumber. if (input_ps->store_sims) for (simi=input_ps->nsims-1; simi>=0; simi--) ftd_dynfores_uinfs(fptr_fcsts, input_ps->nsteps, input_ps->locti, constmodpars_ps, govprob_ps, (struct TSconstgibbs_tag *)NULL, POINTEST, input_ps->indxWhichModel, input_ps->store_sims); else ftd_dynfores_uinfs(fptr_fcsts, input_ps->nsteps, input_ps->locti, constmodpars_ps, govprob_ps, (struct TSconstgibbs_tag *)NULL, POINTEST, input_ps->indxWhichModel, input_ps->store_sims); tzFclose(fptr_fcsts); } //=== Quick fix 03/17/05: kth-step forecast of inflation. if (ksteps_fcsts) ftd_kth_fcsts(fptr_k_infs, ksteps_fcsts, constmodpars_ps->fss-ksteps_fcsts-intloc, intloc, input_ps, constmodpars_ps, govprob_ps, filename_fcsts); //=== Refreshes government's controled inflation, expected inflation, copying x_dv to constmodpars_ps, etc. //=== Must reset it to get the government's forecasts right because ftd_dynfores_uinfs() changes the steady state and other outputs of government's optimization. //=== Note Zpredtran_dm, Ppred_dc, and govprob_ps->govinf_dv are NOT changed. But we just want to be safe. constmodpars_ps->peaklogpost = value_logpostkernal_refresh(constmodpars_ps, (struct TSconstgibbs_tag *)NULL, POINTEST, govprob_ps, minpack_csminwel_ps->x_dv); } else fn_DisplayError("Swtiching case is not available yet"); time(&input_ps->prog_endtime); //Beginning time of the whole program. //=== Writes the data to a file to be used Matlab for graphs. ftd_Fprint_uinf(fptr_inpfor_uinfs, minpack_csminwel_ps); //=== Writes out the final output. ftd_FprintOutput(input_ps, minpack_csminwel_ps); //=== Prints out something for debugging purpose. // fprintf(fptr_debug, "\n********** Steady state solution to the government problem:\n\n"); // fprintf(fptr_debug, "Peak value of logLH: %g\n", constmodpars_ps->peaklogpost); // fprintf(fptr_debug, "Inflation: %g\n", govprob_ps->gpiss); //Inflation pi. // fprintf(fptr_debug, "Unemployment: %g\n", govprob_ps->uss); //Unemployment u. // fprintf(fptr_debug, "Government controlled inflation: %g\n", govprob_ps->xss); //Government's control variable x. // // // fprintf(fptr_debug, "\n********** gensys_sims results:\n\n"); // fprintf(fptr_debug, "eu_dv:\n"); // WriteVector(fptr_debug, govprob_ps->gensys_ps->eu_dv, " %10.4f "); // fprintf(fptr_debug, "Theta_dm:\n"); // WriteMatrix(fptr_debug, govprob_ps->gensys_ps->Theta_dm, " %10.4f "); // fprintf(fptr_debug, "c_dv:\n"); // WriteVector(fptr_debug, govprob_ps->gensys_ps->c_dv, " %10.4f "); // fprintf(fptr_debug, "Impact_dm:\n"); // WriteMatrix(fptr_debug, govprob_ps->gensys_ps->Impact_dm, " %10.4f "); // fprintf(fptr_debug, "Fmat_dzm:\n"); // WriteMatrix(fptr_debug, govprob_ps->gensys_ps->Fmat_dzm->real, " %10.4f "); // WriteMatrix(fptr_debug, govprob_ps->gensys_ps->Fmat_dzm->imag, " %10.4f "); // fprintf(fptr_debug, "Fwt_dzm:\n"); // WriteMatrix(fptr_debug, govprob_ps->gensys_ps->Fwt_dzm->real, " %10.4f "); // WriteMatrix(fptr_debug, govprob_ps->gensys_ps->Fwt_dzm->imag, " %10.4f "); // fprintf(fptr_debug, "Ywt_dzm:\n"); // WriteMatrix(fptr_debug, govprob_ps->gensys_ps->Ywt_dzm->real, " %10.4f "); // WriteMatrix(fptr_debug, govprob_ps->gensys_ps->Ywt_dzm->imag, " %10.4f "); // fprintf(fptr_debug, "Gev_dzm:\n"); // WriteMatrix(fptr_debug, govprob_ps->gensys_ps->Gev_dzm->real, " %10.4f "); // WriteMatrix(fptr_debug, govprob_ps->gensys_ps->Gev_dzm->imag, " %10.4f "); // // fprintf(fptr_debug, "\n********** Some matrices:\n\n"); // fprintf(fptr_debug, "Ppred_dc:\n"); // WriteCell(fptr_debug, govprob_ps->kalcvfurw_ps->Ppred_dc, " %10.4f "); // fprintf(fptr_debug, "Zpredtran_dm:\n"); // WriteMatrix(fptr_debug, govprob_ps->kalcvfurw_ps->Zpredtran_dm, " %10.4f "); // fprintf(fptr_debug, "zupdate_dv:\n"); // WriteVector(fptr_debug, govprob_ps->kalcvfurw_ps->zupdate_dv, " %10.4f "); // // fprintf(fptr_debug, "\n********** Some matrices such as Xrhtran and ylhtran:\n\n"); // fprintf(fptr_debug, "Xrhtran_dm:\n"); // WriteMatrix(fptr_debug, govprob_ps->kalcvfurw_ps->Xrhtran_dm, " %10.4f "); // fprintf(fptr_debug, "ylhtran_dv:\n"); // WriteVector(fptr_debug, govprob_ps->kalcvfurw_ps->ylhtran_dv, " %10.4f "); // // fprintf(fptr_debug, "\n********** Gov controled inflation (govinf_dv), expected inflation (expinf_dv):\n\n"); // WriteVector(fptr_debug, govprob_ps->govinf_dv, " %10.4f "); // WriteVector(fptr_debug, govprob_ps->expinf_dv, " %10.4f "); //=== Destroys memory allocated in this function. etc_swz_ps = DestroyTSetc_swz(etc_swz_ps); govprob_ps = DestroyTSgovprob(govprob_ps); constmodpars_ps = DestroyTSconstmodpars(constmodpars_ps); input_ps = DestroyTSinput(input_ps); // tzFclose(fptr_debug); tzFclose(fptr_input); // tzFclose(fptr_case); tzFclose(fptr_k_infs); tzFclose(fptr_inpfor_uinfs); tzFclose(fptr_output); //=== Done! printf("\n*** Program is successfully executed! ***\n"); return (EXIT_SUCCESS); } //=============================== // 03/17/05 revision -- ad hoc exercises. Making sure that indxCnterFact=0, indxNoUpdating=0, and store_sims = 0. // Longer-term (kth-step) forecasts of inflation and unemployment. //=============================== static void ftd_kth_fcsts(FILE *fptr_k_infs, int ksteps_fcsts, int nlocs, int iniloc, struct TSinput_tag *input_ps, struct TSconstmodpars_tag *constmodpars_ps, struct TSgovprob_tag *govprob_ps, char *filename_fcsts) { //filename_fcsts is used only because we call ftd_dynfores_uinfs(), which records different kinds of information. //ksteps_fcsts: k steps of forecasts; //nlocs: number of starting periods (starting locations) for forecasting; //iniloc: initial starting period (location) for forecasting. int locti, endloc; int simi; double mean_k_fcstinf, median_k_fcstinf; double inv_nsims = 1.0/(double)input_ps->nsims; TSkalcvfurw *kalcvfurw_ps = govprob_ps->kalcvfurw_ps; TSdmatrix *Xrhtran_dm = kalcvfurw_ps->Xrhtran_dm; //Order of the variables in Xrhtran_dm is dependent on the value of input_ps->indxWhichModel. //--- For long-run tradeoffs. int kx = constmodpars_ps->kx; TSdvector *k_fcstinf_z10_dv = constmodpars_ps->k_fcstinf_z10_dv; //TSdmatrix *Zpredtran_dm = govprob_ps->kalcvfurw_ps->Zpredtran_dm; //6-by-fss(T). double sumofcoeff_pi, sumofcoeff_u; //lrtradeoff, double mean_lrtradeoff, mean_sumofcoeff_pi, mean_sumofcoeff_u, mean_consterm; double median_lrtradeoff, median_sumofcoeff_pi, median_sumofcoeff_u, median_consterm; //=== int indxi; TSivector *sortindx_iv = NULL; TSdvector *draws_k_fcstinf_dv = NULL; TSdvector *draws_k_sumofcoeff_pi_dv = NULL; TSdvector *draws_k_sumofcoeff_u_dv = NULL; TSdvector *draws_k_consterm_dv = NULL; TSdvector *draws_k_lrtradeoff_dv = NULL; FILE *fptr_fcsts = NULL; if (constmodpars_ps->fss != constmodpars_ps->sampledates_dv->n) fn_DisplayError("main.c/ftd_kth_fcsts(): make sure yrstart:qmstart and yrfin:qmfin in input data file match fss (effective sample size)"); sortindx_iv = CreateConstantVector_int((input_ps->nsims<1 ? 1 : input_ps->nsims), 0); draws_k_fcstinf_dv = CreateVector_lf((input_ps->nsims<1 ? 1 : input_ps->nsims)); draws_k_sumofcoeff_pi_dv = CreateVector_lf((input_ps->nsims<1 ? 1 : input_ps->nsims)); draws_k_sumofcoeff_u_dv = CreateVector_lf((input_ps->nsims<1 ? 1 : input_ps->nsims)); draws_k_consterm_dv = CreateVector_lf((input_ps->nsims<1 ? 1 : input_ps->nsims)); draws_k_lrtradeoff_dv = CreateVector_lf((input_ps->nsims<1 ? 1 : input_ps->nsims)); fptr_fcsts = tzFopen(filename_fcsts,"w"); //Output file for forecasts. InitializeGlobleSeed(input_ps->randomseed); //Initializing the seednumber. rewind(fptr_k_infs); endloc = iniloc + nlocs - 1; if ((endloc+ksteps_fcsts) > constmodpars_ps->fss) fn_DisplayError("main.c/ftd_kth_fcsts(): values of iniloc, nlocs, and ksteps_fcsts must be within the sample to compare with actual data"); //+ for (locti=iniloc; locti<=endloc; locti++) //Note <=, NOT <. { mean_k_fcstinf = 0.0; mean_lrtradeoff = 0.0; mean_sumofcoeff_pi = 0.0; mean_sumofcoeff_u = 0.0; for (simi=input_ps->nsims-1; simi>=0; simi--) { //--- Inflation forecasts. ftd_dynfores_uinfs(fptr_fcsts, ksteps_fcsts, locti, constmodpars_ps, govprob_ps, (struct TSconstgibbs_tag *)NULL, POINTEST, input_ps->indxWhichModel, 0); mean_k_fcstinf += constmodpars_ps->draw_k_fcstinf; draws_k_fcstinf_dv->v[simi] = constmodpars_ps->draw_k_fcstinf; //--- Computing long-run tradeoffs under Ramsey policy. // sumofcoeff_pi = k_fcstinf_z10_dv->v[0] + k_fcstinf_z10_dv->v[1] + k_fcstinf_z10_dv->v[3]; // sumofcoeff_u = 1.0 - k_fcstinf_z10_dv->v[2] - k_fcstinf_z10_dv->v[4]; // lreudraw_dv->v[0] = (constmodpars_ps->govpitarget*sumofcoeff_pi + k_fcstinf_z10_dv->v[5]) / sumofcoeff_u - constmodpars_ps->ustar; mean_sumofcoeff_pi += (draws_k_sumofcoeff_pi_dv->v[simi] = sumofcoeff_pi = k_fcstinf_z10_dv->v[0] + k_fcstinf_z10_dv->v[1] + k_fcstinf_z10_dv->v[3]); mean_sumofcoeff_u += (draws_k_sumofcoeff_u_dv->v[simi] = sumofcoeff_u = 1.0 - k_fcstinf_z10_dv->v[2] - k_fcstinf_z10_dv->v[4]); mean_consterm += (draws_k_consterm_dv->v[simi] = k_fcstinf_z10_dv->v[5]); mean_lrtradeoff += (draws_k_lrtradeoff_dv->v[simi] = (constmodpars_ps->govpitarget*sumofcoeff_pi + k_fcstinf_z10_dv->v[5]) / sumofcoeff_u - constmodpars_ps->ustar); // mean_sumofcoeff_pi += (draws_k_sumofcoeff_pi_dv->v[simi] = sumofcoeff_pi = Zpredtran_dm->M[mos(0,locti+ksteps_fcsts,kx)] + Zpredtran_dm->M[mos(1,locti+ksteps_fcsts,kx)] + Zpredtran_dm->M[mos(3,locti+ksteps_fcsts,kx)]); // mean_sumofcoeff_u += (draws_k_sumofcoeff_u_dv->v[simi] = sumofcoeff_u = 1.0 - Zpredtran_dm->M[mos(2,locti+ksteps_fcsts,kx)] - Zpredtran_dm->M[mos(4,locti+ksteps_fcsts,kx)]); // mean_lrtradeoff += (draws_k_lrtradeoff_dv->v[simi] = (constmodpars_ps->govpitarget*sumofcoeff_pi + Zpredtran_dm->M[mos(5,locti+ksteps_fcsts,kx)]) / sumofcoeff_u - constmodpars_ps->ustar); } draws_k_sumofcoeff_pi_dv->flag = V_DEF; draws_k_sumofcoeff_u_dv->flag = V_DEF; draws_k_consterm_dv->flag = V_DEF; draws_k_lrtradeoff_dv->flag = V_DEF; draws_k_fcstinf_dv->flag = V_DEF; //--- Sorting indexes according to draws_k_lrtradeoff_dv. for (indxi=input_ps->nsims-1; indxi>=0; indxi--) sortindx_iv->v[indxi] = indxi; //Initializating. tz_sortindex_lf(sortindx_iv, draws_k_fcstinf_dv, 'A'); //--- Finishing up inflation forecasts. mean_k_fcstinf *= inv_nsims; // tz_sort(draws_k_fcstinf_dv, 'A'); median_k_fcstinf = draws_k_fcstinf_dv->v[sortindx_iv->v[(int)(0.5*input_ps->nsims)]]; //--- Finishing up computing long-run tradeoffs under Ramsey policy. mean_sumofcoeff_pi *= inv_nsims; mean_sumofcoeff_u *= inv_nsims; mean_consterm *= inv_nsims; mean_lrtradeoff *= inv_nsims; median_sumofcoeff_pi = draws_k_sumofcoeff_pi_dv->v[sortindx_iv->v[(int)(0.5*input_ps->nsims)]]; median_sumofcoeff_u = draws_k_sumofcoeff_u_dv->v[sortindx_iv->v[(int)(0.5*input_ps->nsims)]]; median_consterm = draws_k_consterm_dv->v[sortindx_iv->v[(int)(0.5*input_ps->nsims)]]; median_lrtradeoff = draws_k_lrtradeoff_dv->v[sortindx_iv->v[(int)(0.5*input_ps->nsims)]]; //=== Recording the date, forecast, and actual. fprintf(fptr_k_infs, " %.16e ", constmodpars_ps->sampledates_dv->v[locti+ksteps_fcsts]); fprintf(fptr_k_infs, " %.16e ", Xrhtran_dm->M[mos(0, locti+ksteps_fcsts, Xrhtran_dm->nrows)]); fprintf(fptr_k_infs, " %.16e ", median_k_fcstinf); fprintf(fptr_k_infs, " %.16e ", median_sumofcoeff_pi); fprintf(fptr_k_infs, " %.16e ", median_sumofcoeff_u); fprintf(fptr_k_infs, " %.16e ", median_consterm); fprintf(fptr_k_infs, " %.16e \n", median_lrtradeoff); // fprintf(fptr_k_infs, " %.16e \n", mean_k_fcstinf); fflush(fptr_k_infs); } DestroyVector_int(sortindx_iv); DestroyVector_lf(draws_k_fcstinf_dv); DestroyVector_lf(draws_k_sumofcoeff_pi_dv); DestroyVector_lf(draws_k_sumofcoeff_u_dv); DestroyVector_lf(draws_k_consterm_dv); DestroyVector_lf(draws_k_lrtradeoff_dv); tzFclose(fptr_fcsts); } static TSetc_swz *CreateTSetc_swz(TSconstmodpars **constmodpars_pps, TFDestroyTSconstmodpars *DestroyTSconstmodpars_func, TSgovprob **govprob_pps, TFDestroyTSgovprob *DestroyTSgovprob_func) { TSetc_swz *etc_swz_ps = tzMalloc(1, TSetc_swz); //=== Initialization. etc_swz_ps->constmodpars_ps = *constmodpars_pps; etc_swz_ps->DestroyTSconstmodpars = DestroyTSconstmodpars_func; if (DestroyTSconstmodpars_func) *constmodpars_pps = (TSconstmodpars *)NULL; //If destroy function makes this structure responsible to free memory of the passing pointer, reset this passing pointer to NULL to avoid double destroying actions and cause memory problem. // etc_swz_ps->govprob_ps = *govprob_pps; etc_swz_ps->DestroyTSgovprob = DestroyTSgovprob_func; if (DestroyTSgovprob_func) *govprob_pps = (TSgovprob *)NULL; //If destroy function makes this structure responsible to free memory of the passing pointer, reset this passing pointer to NULL to avoid double destroying actions and cause memory problem. return (etc_swz_ps); } //--- static TSetc_swz *DestroyTSetc_swz(TSetc_swz *etc_swz_ps) { if (etc_swz_ps) { if (etc_swz_ps->DestroyTSconstmodpars) etc_swz_ps->DestroyTSconstmodpars(etc_swz_ps->constmodpars_ps); //If destroy function is active, destroy it here; ohterwise, it will be destroyed somewhere else. if (etc_swz_ps->DestroyTSgovprob) etc_swz_ps->DestroyTSgovprob(etc_swz_ps->govprob_ps); //If destroy function is active, destroy it here; ohterwise, it will be destroyed somewhere else. //=== free(etc_swz_ps); return ((TSetc_swz *)NULL); } else return (etc_swz_ps); } static void InitializeForMinproblem(struct TSminpack_tag *minpack_ps, TSinput *input_ps, char *filename_sp, int indxStartValuesForMin) { //For indxStartValuesForMin, // 0: randomly selects the initial starting values for the MLE or posterior estimate; // 1: starts from the fixed values manually keyed in this .c file. // 2: uses the starting piont (sp) file, filename_sp_vec_csminwel. FILE *fptr_sp = NULL; int _n, _i; TSdvector *x_dv = minpack_ps->x_dv; TSconstmodpars *constmodpars_ps = ((TSetc_swz *)minpack_ps->etc_project_ps)->constmodpars_ps; //=== TSdvector *ones_dv = NULL; if (indxStartValuesForMin == 1) { ftd_modpars2freepars((void *)constmodpars_ps, POINTEST); CopyVector0(x_dv, constmodpars_ps->x_dv); } else if (indxStartValuesForMin == 2) { fptr_sp = tzFopen(filename_sp,"r"); rewind(fptr_sp); //Must put the pointer at the beginning of the file. for (_n=x_dv->n, _i=0; _i<_n; _i++) { if (fscanf(fptr_sp, " %lf ", x_dv->v+_i) != 1) { printf("Fatal Error: InitializeForMinproblem(() -- cannot read the number from the file %s. Check the data file", filename_sp); exit(EXIT_FAILURE); } } x_dv->flag = V_DEF; CopyVector0(constmodpars_ps->x_dv, x_dv); //Copying it to constmodpars_ps->x_dv. tzFclose(fptr_sp); } else { if (1) { InitializeGlobleSeed(input_ps->randomseed); //Initializing the seednumber. UniformVector(x_dv); // ScalarTimesVector(x_dv, SCALERANINI, x_dv, 0.0); ones_dv = CreateConstantVector_lf(x_dv->n, 1.0); VectorPlusMinusVectorUpdate(x_dv, ones_dv, SCALERANINI); } else InitializeConstantVector_lf(x_dv, 0.8); CopyVector0(constmodpars_ps->x_dv, x_dv); //Copying it to constmodpars_ps->x_dv. } //=== DestroyVector_lf(ones_dv); } //--- static void ngo_InitializeForMinproblem(struct TSminpack_tag *minpack_ps, TSinput *input_ps, int indxStartValuesForMin) { //For indxStartValuesForMin, // 0: randomly selects the initial starting values for the MLE or posterior estimate; // 1: starts at the fixed values from the input data file datainp_swz.prn. FILE *fptr_sp = NULL; // int _n, _i; TSdvector *x_dv = minpack_ps->x_dv; TSconstmodpars *constmodpars_ps = ((TSetc_swz *)minpack_ps->etc_project_ps)->constmodpars_ps; //=== TSdvector *ones_dv = NULL; if (indxStartValuesForMin == 1) { CopyVector0(x_dv, constmodpars_ps->ngo_x_dv); ngo_freepars2modpars((void *)constmodpars_ps, POINTEST); } // else if (indxStartValuesForMin == 2) { // fptr_sp = tzFopen(filename_sp,"r"); // rewind(fptr_sp); //Must put the pointer at the beginning of the file. // for (_n=x_dv->n, _i=0; _i<_n; _i++) { // if (fscanf(fptr_sp, " %lf ", x_dv->v+_i) != 1) { // printf("Fatal Error: InitializeForMinproblem(() -- cannot read the number from the file %s. Check the data file", filename_sp); // exit(EXIT_FAILURE); // } // } // x_dv->flag = V_DEF; // CopyVector0(constmodpars_ps->ngo_x_dv, x_dv); //Copying it to constmodpars_ps->x_dv. // tzFclose(fptr_sp); // } else if (indxStartValuesForMin == 0) { if (1) { InitializeGlobleSeed(input_ps->randomseed); //Initializing the seednumber. UniformVector(x_dv); if (1) ScalarTimesVector(x_dv, SCALERANINI, x_dv, 0.0); else { ones_dv = CreateConstantVector_lf(x_dv->n, 1.0); VectorPlusMinusVectorUpdate(x_dv, ones_dv, SCALERANINI); } } else InitializeConstantVector_lf(x_dv, 0.8); CopyVector0(constmodpars_ps->ngo_x_dv, x_dv); //Copying it to constmodpars_ps->x_dv. ngo_freepars2modpars((void *)constmodpars_ps, POINTEST); } else fn_DisplayError("ngo_InitializeForMinproblem(): indxStartValuesForMin has only two options: 0 or 1"); //=== DestroyVector_lf(ones_dv); } //----------------------- // Minimization objective function: following the function protocal TFminobj in optpackage.h. //----------------------- static double minneglogpost(struct TSminpack_tag *minpack_ps) { //Returns the negative value of log LH or log PosteriorFunction. See p.20a. return ( -value_logpostkernal_refresh(((TSetc_swz *)minpack_ps->etc_project_ps)->constmodpars_ps, (struct TSconstgibbs_tag *)NULL, POINTEST, ((TSetc_swz *)minpack_ps->etc_project_ps)->govprob_ps, minpack_ps->xtemp_dv) ); } static double ngo_minneglogpost(struct TSminpack_tag *minpack_ps) { //Returns the negative value of log LH or log PosteriorFunction. See p.20a. return ( -ngo_value_loglh_refresh(((TSetc_swz *)minpack_ps->etc_project_ps)->constmodpars_ps, ((TSetc_swz *)minpack_ps->etc_project_ps)->govprob_ps, minpack_ps->xtemp_dv) ); } //------------------- // Prints final results to an output file for eye examination. //------------------- #define RFORMAT " %10.5f\n " //R: return carriage. #define NFORMAT " %10.5f " //N: no return carriage. #define AFORMAT " %.16e " //A: accurate (most accurate). #define ARFORMAT " %.16e\n " //A: accurate (most accurate) with carriage return. static void ftd_FprintOutput(TSinput *input_ps, TSminpack *minpack_ps) { static int header1=0; FILE *fptr_output = input_ps->fptr_output; //--- Initialization. The order matters! TSdvector *x_dv = minpack_ps->x_dv; TSdvector *g_dv = minpack_ps->g_dv; TSetc_csminwel *etc_csminwel_ps = (TSetc_csminwel *)minpack_ps->etc_package_ps; TSconstmodpars *constmodpars_ps = ((TSetc_swz *)minpack_ps->etc_project_ps)->constmodpars_ps; TSgovprob *govprob_ps = ((TSetc_swz *)minpack_ps->etc_project_ps)->govprob_ps; TSkalcvfurw *kalcvfurw_ps = govprob_ps->kalcvfurw_ps; TSdvector *ylhtran_dv = kalcvfurw_ps->ylhtran_dv; TSdmatrix *Xrhtran_dm = kalcvfurw_ps->Xrhtran_dm; //Order of the variables in Xrhtran_dm is dependent on the value of input_ps->indxWhichModel. TSdvector *govupred_dv = kalcvfurw_ps->ylhtranpred_dv; //fss-by-1 government forecasts of unemployment from their misspecified Phillips equation. 03/17/05. int nrhvars = Xrhtran_dm->nrows; TSdvector *expinf_dv = govprob_ps->expinf_dv; if (header1==0) { fprintf(fptr_output, "Reporting final results.\n\n\n"); header1=1; //After this reset, when this function is called second time, this header will not be printed again. } input_ps->program_hours = difftime(input_ps->prog_endtime,input_ps->prog_begtime)/60.0/60.0; if (constmodpars_ps->indxNoGovOpt) //Added 03/17/05 { fprintf(fptr_output, "\n******* First step of optimization to estimate V and P10 with no government optimization problem. *******\n"); fprintf(fptr_output, "MLE: %10.5f\n", constmodpars_ps->ngo_maxLHvalue); fprintf(fptr_output, "Free parameters of chol(V) and chol(P10):\n"); WriteVector(fptr_output, constmodpars_ps->ngo_x_dv, " %.16e "); return; //Early exit. } else fprintf(fptr_output, "\n******* Second step of optimization: either full government optimzation solution or private-sector parameters *******\n" "******* with V and P10 estimated igoring the government's Phelps problem. *******\nn"); //--------------------------- Printing final outputs. --------------------------- fprintf(fptr_output, "Type of model (classical 1 == CGP2TP1TI0 and Keynesian 2 == KGP2TP1TI0 and NGO 4 == NGO_CGP2TP1TI0): %d\n", input_ps->indxWhichModel); fprintf(fptr_output, "Starting-value method is %d. If the method is indexed by 0, the random seed number is %d\n", constmodpars_ps->indxStartValuesForMin, constmodpars_ps->randomseed); fprintf(fptr_output, "Index for the MLE is %d (0: posterior estimates; 1: MLE with no prior)\n", constmodpars_ps->indxMLE); fprintf(fptr_output, "Total computing hours for the whole program: %10.3f\n", input_ps->program_hours); fprintf(fptr_output, "Posterior estimates of free parameters x_dv:\n"); WriteVector(fptr_output, x_dv, AFORMAT); fprintf(fptr_output, "Numerical gradient associated with the posterior estimates g_dv:\n"); WriteVector(fptr_output, g_dv, AFORMAT); fprintf(fptr_output, "Peak value of logPosterior is: " RFORMAT, constmodpars_ps->peaklogpost); fprintf(fptr_output, "LH (pdf) value at the posterior peak: " RFORMAT, constmodpars_ps->LHvalatpostpeak); fprintf(fptr_output, "Return code for the terminating condition: %d\n", etc_csminwel_ps->retcode); fprintf(fptr_output, "Overall convergence criterion for the function value: %.5e\n", etc_csminwel_ps->crit); fprintf(fptr_output, "Fixed z10 and P10 (if so, the value is 1): %d\n", constmodpars_ps->indxFixz10P10); fprintf(fptr_output, "Scaler factor for P10 if z10 and P10 are fixed: %g\n", constmodpars_ps->tc_P10); fprintf(fptr_output, "Initial value for the diagonal of inverse Hessian in the quasi-Newton search: %.5e\n", etc_csminwel_ps->ini_h_csminwel); fprintf(fptr_output, "Step size of non-automatic portion of numerical gradient: %.5e\n", etc_csminwel_ps->gradstps_csminwel); fprintf(fptr_output, "Method of numerical gradient is: %d, where 1 represents forward difference and 2 represents central difference\n", etc_csminwel_ps->indxnumgrad_csminwel); fprintf(fptr_output, "Number of iterations taken by csminwel: %d\n", etc_csminwel_ps->niter); fprintf(fptr_output, "Number of function evaluations used by csminwel: %d\n", etc_csminwel_ps->fcount); fprintf(fptr_output, "\n"); fprintf(fptr_output, "ustar: " ARFORMAT, constmodpars_ps->ustar); fprintf(fptr_output, "gtheta0: " ARFORMAT, constmodpars_ps->gtheta0); fprintf(fptr_output, "gtheta1: " ARFORMAT, constmodpars_ps->gtheta1); fprintf(fptr_output, "gtau1: " ARFORMAT, constmodpars_ps->gtau1); fprintf(fptr_output, "gzeta1: " ARFORMAT, constmodpars_ps->gzeta1); fprintf(fptr_output, "gzeta2: " ARFORMAT, constmodpars_ps->gzeta2); fprintf(fptr_output, "gzeta: " ARFORMAT, constmodpars_ps->gzeta); fprintf(fptr_output, "\n\n******* Government optimizing results (for Keynesian fit, steady state results are meaningless because we did not compute them): *******\n"); fprintf(fptr_output, "\n--- Steady State ---:\n"); fprintf(fptr_output, "Inflation: %g\n", govprob_ps->gpiss); //Inflation pi. fprintf(fptr_output, "Unemployment: %g\n", govprob_ps->uss); //Unemployment u. fprintf(fptr_output, "Government controlled inflation: %g\n", govprob_ps->xss); //Government's control variable x. fprintf(fptr_output, "eu_dv:\n"); WriteVector(fptr_output, govprob_ps->gensys_ps->eu_dv, NFORMAT); fprintf(fptr_output, "Theta_dm:\n"); WriteMatrix(fptr_output, govprob_ps->gensys_ps->Theta_dm, NFORMAT); fprintf(fptr_output, "c_dv:\n"); WriteVector(fptr_output, govprob_ps->gensys_ps->c_dv, NFORMAT); fprintf(fptr_output, "Impact_dm:\n"); WriteMatrix(fptr_output, govprob_ps->gensys_ps->Impact_dm, NFORMAT); fprintf(fptr_output, "Fmat_dzm:\n"); WriteMatrix(fptr_output, govprob_ps->gensys_ps->Fmat_dzm->real, NFORMAT); WriteMatrix(fptr_output, govprob_ps->gensys_ps->Fmat_dzm->imag, NFORMAT); fprintf(fptr_output, "Fwt_dzm:\n"); WriteMatrix(fptr_output, govprob_ps->gensys_ps->Fwt_dzm->real, NFORMAT); WriteMatrix(fptr_output, govprob_ps->gensys_ps->Fwt_dzm->imag, NFORMAT); fprintf(fptr_output, "Ywt_dzm:\n"); WriteMatrix(fptr_output, govprob_ps->gensys_ps->Ywt_dzm->real, NFORMAT); WriteMatrix(fptr_output, govprob_ps->gensys_ps->Ywt_dzm->imag, NFORMAT); fprintf(fptr_output, "Gev_dzm:\n"); WriteMatrix(fptr_output, govprob_ps->gensys_ps->Gev_dzm->real, NFORMAT); WriteMatrix(fptr_output, govprob_ps->gensys_ps->Gev_dzm->imag, NFORMAT); fprintf(fptr_output, "\n********** Some matrices:\n\n"); fprintf(fptr_output, "Ppred_dc (P_{2|1}, ..., P_{T+1|T}):\n"); WriteCell(fptr_output, govprob_ps->kalcvfurw_ps->Ppred_dc, AFORMAT); fprintf(fptr_output, "Zpredtran_dm (z_{2|1}, ..., z_{T+1|T}):\n"); WriteMatrix(fptr_output, govprob_ps->kalcvfurw_ps->Zpredtran_dm, AFORMAT); fprintf(fptr_output, "zupdate_dv (z_{T+1|T}):\n"); WriteVector(fptr_output, govprob_ps->kalcvfurw_ps->zupdate_dv, AFORMAT); fprintf(fptr_output, "z10_dv:\n"); WriteVector(fptr_output, govprob_ps->kalcvfurw_ps->z10_dv, AFORMAT); fprintf(fptr_output, "P10_dm:\n"); WriteMatrix(fptr_output, govprob_ps->kalcvfurw_ps->P10_dm, AFORMAT); fprintf(fptr_output, "V_dm:\n"); WriteMatrix(fptr_output, govprob_ps->kalcvfurw_ps->V_dm, AFORMAT); fprintf(fptr_output, "\n********** Data for government's model, such as Xrhtran and ylhtran:\n\n"); fprintf(fptr_output, "For classical regression, column of Xrhtran_dm is pi_t, pi_{t-1}, u_{t-1}, pi_{t-2}, u_{t-2}, and 1.0:\n"); fprintf(fptr_output, "For Keynesian regression, column of Xrhtran_dm is u_t, u_{t-1}, pi_{t-1}, u_{t-2}, pi_{t-2}, and 1.0:\n"); WriteMatrix(fptr_output, govprob_ps->kalcvfurw_ps->Xrhtran_dm, AFORMAT); fprintf(fptr_output, "ylhtran_dv (u_t for classical and pi_t for Keynesian):\n"); WriteVector(fptr_output, govprob_ps->kalcvfurw_ps->ylhtran_dv, AFORMAT); fprintf(fptr_output, "\n********** Gov controled inflation (govinf_dv), expected inflation (expinf_dv), predicted U (upred_dv) from the true Phillips curve, and predicted U (govupred_dv) from the government's Phillips curve:\n\n"); WriteVector(fptr_output, govprob_ps->govinf_dv, AFORMAT); WriteVector(fptr_output, govprob_ps->expinf_dv, AFORMAT); WriteVector(fptr_output, constmodpars_ps->upred_dv, AFORMAT); WriteVector(fptr_output, govupred_dv, AFORMAT); } //------- Writes out actual value and one-step forecast of both inflation and the unemployment rate. ------- static void ftd_Fprint_uinf(FILE *fptr_inpfor_uinfs, TSminpack *minpack_ps) { // TSdvector expinf_sdv; //--- Initialization. The order matters! TSconstmodpars *constmodpars_ps = ((TSetc_swz *)minpack_ps->etc_project_ps)->constmodpars_ps; TSgovprob *govprob_ps = ((TSetc_swz *)minpack_ps->etc_project_ps)->govprob_ps; TSkalcvfurw *kalcvfurw_ps = govprob_ps->kalcvfurw_ps; TSdvector *ylhtran_dv = kalcvfurw_ps->ylhtran_dv; TSdmatrix *Xrhtran_dm = kalcvfurw_ps->Xrhtran_dm; //Order of the variables in Xrhtran_dm is dependent on the value of input_ps->indxWhichModel. TSdvector *sampledates_dv = constmodpars_ps->sampledates_dv; //Dates. int fss = Xrhtran_dm->ncols; int nrhvars = Xrhtran_dm->nrows; TSdvector *expinf_dv = govprob_ps->expinf_dv; TSdvector *upred_dv = constmodpars_ps->upred_dv; //=== TSdmatrix *MTby2_dm = CreateMatrix_lf(fss,3); //0: dates; 1: actual inflation (unemployment); 2: one-step forecasts of inflation (unemployment). //=== Dates. if (fss != sampledates_dv->n) fn_DisplayError(".../ftd_Fprint_uinf(): yrstart and qmstart do not match the effective sample size constmodpars_ps->fss"); CopySubvector2matrix(MTby2_dm, 0, 0, sampledates_dv, 0, fss); //=== Actual and expected inflation. if (constmodpars_ps->indxWhichModel & (CGP2TP1TI0 | NGO_CGP2TP1TI0)) //NGO_CGP2TP1TI0 is added 03/17/05. CopySubrowmatrix2matrix(MTby2_dm, 0, 1, Xrhtran_dm, 0, 0, 1, fss); else if (constmodpars_ps->indxWhichModel & KGP2TP1TI0) CopySubvector2matrix(MTby2_dm, 0, 1, ylhtran_dv, 0, fss); else fn_DisplayError(".../modeleconomy.c/ftd_Fprint_uinf(): type of model, indxWhichModel, must be either CGP2TP1TI0 or KGP2TP1TI0 or NGO_CGP2TP1TI0 defined in swz_comfuns.h"); CopySubvector2matrix(MTby2_dm, 0, 2, expinf_dv, 0, fss); //%%%% Writes to a file. WriteMatrix(fptr_inpfor_uinfs, MTby2_dm, AFORMAT); //=== Actual and expected unemployment rate. if (constmodpars_ps->indxWhichModel & (CGP2TP1TI0 | NGO_CGP2TP1TI0)) //NGO_CGP2TP1TI0 is added 03/17/05. CopySubvector2matrix(MTby2_dm, 0, 1, ylhtran_dv, 0, fss); else if (constmodpars_ps->indxWhichModel & KGP2TP1TI0) CopySubrowmatrix2matrix(MTby2_dm, 0, 1, Xrhtran_dm, 0, 0, 1, fss); else fn_DisplayError(".../modeleconomy.c/ftd_Fprint_uinf(): type of model, indxWhichModel, must be either CGP2TP1TI0 or KGP2TP1TI0 or NGO_CGP2TP1TI0 defined in swz_comfuns.h"); CopySubvector2matrix(MTby2_dm, 0, 2, upred_dv, 0, fss); //%%%% Writes to a file. WriteMatrix(fptr_inpfor_uinfs, MTby2_dm, AFORMAT); //=== DestroyMatrix_lf(MTby2_dm); } #undef RFORMAT #undef NFORMAT #undef AFORMAT #undef ARFORMAT //TSdvector *CreateDatesVector_lf(int nq_m, int yrstart, int qmstart, int yrend, int qmend) //{ // //If nq_m==4, quarterly data; nq_m==12, monthly data. // int _t; // int samplesize = fn_locofyearqm(nq_m, yrstart, qmstart, yrend, qmend); // // // TSdvector *dates_dv = tzMalloc(1, TSdvector); // if (nq_m==4 || nq_m==12) { // `statement` // } // else fn_DisplayError(".../tzmatlab.c/CreateDatesVector_lf(): Dates have to be either monthly or quarterly"); // for (_t=samplesize-1; _t>=0; _t--) dates_dv->v[_t] = (double)yrstart + (double)(qmstart+_t-1)/(double)nq_m; // dates_dv->flag = V_DEF; // return (dates_dv); //} ////--- //#define DestroyDatesVector_lf DestroyVector_lf //TSdvector *DestroyDatesVector_lf(TSdvector *dates_dv) //{ // return (DestroyVector_lf(dates_dv)); //} /** static void ftd_add_dates(TSpointargs1 *pointargs1_ps) { int samplesize = pointargs1_ps->Qsos_pnt_wdates_dm->nrows, yrstart = pointargs1_ps->yrstart, qmstart = pointargs1_ps->qmstart, nq_m = pointargs1_ps->nq_m, _t; TSdvector *dates_dv = NULL; //=== Memory allocated for this function. dates_dv = CreateVector_lf(samplesize); for (_t=0; _tv[_t] = (double)yrstart + (double)(qmstart+_t-1)/nq_m; dates_dv->flag = V_DEF; CopySubvector2matrix(pointargs1_ps->Qsos_pnt_wdates_dm, 0, 0, dates_dv, 0, samplesize); //=== Destroys memory allocated for this function. dates_dv = DestroyVector_lf(dates_dv); } /**/