//Revisions, 03/17/05; //-------------- Model Economy as a Whole. --------------------- #ifndef __SWZ_COMFUNS_H__ #define __SWZ_COMFUNS_H__ #include "govprob.h" //#define DEGUG_SWZ //If define, in debug mode; else (undef), in a normal running mode. //--- Types of models. #define CGP2TP1TI0 0x0001 //1: government's classical (C) model with 2-lag government Phillips (GP2), the 1-lag true Phillips curve (TP1), and 0-lag true inflation process (TI0). #define KGP2TP1TI0 0x0002 //2: government's Keynesian (K) model with 2-lag government Phillips (GP2), the 1-lag true Phillips curve (TP1), and 0-lag true inflation process (TI0). #define NGO_CGP2TP1TI0 0x0004 //4: government's classical (C) but no-government-optimization (NGO) model with 2-lag government Phillips (GP2), the 1-lag true Phillips curve (TP1), and 0-lag true inflation process (TI0). //************************************************************ // III. For the posterior probability (inferences). //************************************************************ typedef struct TSconstgibbs_tag { //Collection of all constant-parameter model parameters to be drawn, whereas some paramters like the discount factor are simply given. int indxWhichModel; //1: CGP2TP1TI0 defined in swz_conmfuns.h (classical direction of fit); 2: KGP2TP1TI0 defined in swz_conmfuns.h (Keynesian direction of fit). //4: NGO_CGP2TP1TI0 defined in swz_conmfuns.h (no government optimization classical direction of fit). Added, 03/17/05. int indxFixz10P10; //2: fix z_{1|0} but not P_{1|0}; 1: fix z_{1|0} or alpha_{1|0} when doing estimation; 0: must estimate z_{1|0} or alpha_{1|0}. int indxCnterFact; //Only used in ftd_dynfores_uinfs() in swz_comfuns.c. 1: do counterfactual exercises (check ); 0: do not do such exercises. int indxNoUpdating; //Only used in ftd_dynfores_uinfs() in swz_comfuns.c. 1: no Kalman updating for government; 0: Kalman updating as usual. TSdvector *sclhistshocks_dv; //Only used in ftd_dynfores_uinfs() in swz_comfuns.c. Scaling up or down the historical residuals. double scl_epsilon; //== scl_epsilon ==// //Scale factor espilon for the covariance matrix V in the government's regression when indxFcsts == 1. //=== Fixed values used for evaluating the logLH or logPosterior that is formed according to nlagstrue. // int govmodel; //== govmodel ==// //Government's model (0: Classical direction or regresssion; 1: Keynesian direction). int kx; //== kx ==// //Number of right-hand regressors in the government's Phillips curve. int nlagsinflation; //== nlagsinflation ==// //Number of lags or lag length for the inflation process. int nlagstrue; //== nlagstrue ==// //Number of lags or lag length for the true Phillips curve. int fss; //Effective sample size (i.e., excluding max lag length in the whole model). double govpitarget; //Government's targeted inflation. //=== Draws of free parameters. int ndraws1; //Number of draws to be tossed away. int ndraws2; //Number of draws to be used. int ndrawsq; //Number of draws to compute the normalizing constant q when restricting the region for the Gaussian weight function. int napartsave; //Number of draws apart between saving or writing a draw to an output file for statistical inferences. Purpose is to (1) save disk space and (2) get less dependent draws. int totnpars; //Total number of free parameters. If rho1=rho2=0, equals to 6+kx+(kx+1)*kx. TSdvector *x_dv; //totnpars-by-1 vector of free parameters. For indxWhichModel = CGP2TP1TI0, we have 6+kx+(kx+1)*kx variables in the order of //vstar, theta0, theta1, tau1, sqrt(zeta1), sqrt(zeta2), (z10 (k-by-1) is not here in general), c_p1, ..., cpf (upper triangular of P10), c_v1, ..., c_vf (upper triangular of V). //--- For the 1st set of parameters: x_dv->v[0:3]. vstar, theta0, theta1, and tau1. TSdvector *postmean1stset_dv; //Posterior mean. TSdmatrix *postCov1stSetinv_dm; //Inverse of posterior covaraince matrix. TSdmatrix *cholpostCov1stSetinv_dm; //Choleski of inverse of posterior covaraince matrix. //--- For the 4th, 5th, and 6th sets of parameters: x_dv->v[6:end-1]: z_{1|0} and only upper triangular parts of the Choleski decompostions of P_{1|0} and V, See p.20d. // TSdvector *postmean4a5a6thsets_dv; //Posterior mean. // TSdmatrix *postCov4a5a6thSetsinv_dm; //Inverse of posterior covaraince matrix. // TSdmatrix *cholpostCov4a5a6thSetsinv_dm; //Choleski of inverse of posterior covaraince matrix. int indxHess; double jumpingratio; double sf_mtpl; //Scale factor for sqrt(covariance matrix) in the Metropolis algorithm. Thus, the smaller the number, the smaller the covariance. double sf_mhm; //Scale factor for importance covariance matrix used for the MHM method. int indx_readgibbs; //1: reads Gibbs draws from the file outdatainp_for_prob_constpce.prn; 0: simulates Gibbs draws. int indx_lrsacrats; //1: computing and writing to the file outdatainp_for_lreudraws_TAG.prn draws of long-run sacrifice ratios; 0: no such computation or writing. int indx_mhm; //1: computing marginal likelihood using the MHM method; 0: no such computation. int indxRecord; //1: record the xmax_dv that has the max of logPostKernel for the Gibbs draws; 0: no such recording. int indxMHMPeak; //1: using the posterior peak as the mean of the impoartance Gaussian pdf; 0: using the posterior mean as the mean of the impoartance Gaussian pdf; double cutval_logpost; //Added 03/17/05. double maxgibbs_logpostkernel; double mingibbs_logpostkernel; TSdvector *xmax_dv; //totnpars-by-1 vector of free parameters at the maximum during the Gibbs run. TSdvector *xmin_dv; //totnpars-by-1 vector of free parameters at the minimum during the Gibbs run. TSdmatrix *CovMplsinv_dm; //Inverse of the covaraince for the Jumping kernel in the Metropolis algorithm when drawing the 4th, 5th, and 6th sets of parmeters (i.e., z_{1|0} and upper Choleski decomposition parts of P_{1|0} and V). TSdmatrix *cholCovMplsinv_dm; //Upper Choleski of inverse of the covaraince for the Jumping kernel in the Metropolis algorithm. //=== Private-sector parameters, pp.20-20a. //--- True Phillips curve. double ustar; //Natural rate of unemployment. double gtheta0; double gtheta1; double gtau1; double gzeta1; //Inverse of residual variance in the true Phillips curve. //--- True inflation process. double grho1; //Coefficient on 1st lag of inflation in the true inflatin process. double grho2; //Coefficient on 1st lag of unemployment in the true inflation process. double gzeta2; //Inverse of residual variance in the true inflation process. //=== Government parameters, but will be estimated outside of the government problem. double gzeta; //Normalized to be equal to gzeta1. Inverse of residual variance in the government's mis-specified Phillips curve. TSdvector *z10_dv; //kx-by-1. Initial condition for the coefficient: z_{1|0} -- coefficients on pi_t, pi_{t-1}, U_{t-1}, pi_{t-2}, U_{t-2}, and Constant. TSdmatrix *P10_dm; //kx-by-kx symmetric matrix. Initial condition for the variance of the coefficient: P_{1|0}. TSdmatrix *V_dm; //kx-by-kx. Covariance (symmetric and positive definite) matrix for the residual of the drifting parameters in the government's Phillips curve. //=== For computing marginal likelihood using the MHM method. TSdvector *xzetapostest_dv; //Ajusted posterior estimate from constmodpars_ps->x_dv where the 4th and 5th element will be squared to be zeta1 and zeta2. TSdvector *xzeta_dv; //Ajusted x_dv where the 4th and 5th element will be squared to be zeta1 and zeta2. //vstar, theta0, theta1, tau1, zeta1, zeta2, (z10 (k-by-1) is not here in general), c_p1, ..., cpf (upper triangular of P10), c_v1, ..., c_vf (upper triangular of V). TSdvector *xmean_dv; //Mean of draws of xzeta_dv. TSdmatrix *cholXcov_dm; //Choleski of covariance of draws of xzeta_dv. TSdvector *pcuts_dv; //For the modified harmonic mean (MHM) method, a vector of probabilities for the right-truncated chi-square distribution (a joint normal) of free parameters. TSdvector *zeta1cuts_dv; //Added 03/17/05. For the MHM method, [lower bound, upper bound] for gzetadraws which are always in (0, \infty). TSdvector *zeta2cuts_dv; //Added 03/17/05. For the MHM method, [lower bound, upper bound] for gzetadraws which are always in (0, \infty). TSdvector *logqvals_dv; //Added 03/17/05. For the (MHM) method, an pcuts_dv->n-by-1 vector of the log normalizing constants for the weight function in the restricted region other than standard p-cuts. TSdvector *logpcuts_dv; double neghalfklog2pi_minus_dethalfcholXcov; double logLHtimespriorpdf_lastval; TSivector *nzeros_pdf_iv; //pcuts_dv->n-by-1. Number of (truncated) zero values of importance density function h(\theta). Must be less than ndraws2. See p. 0.13.a in TVBVAR NOTES. struct TSveclogsum_tag *veclogMLH_ps; //See cstz.h and cstz.c. //=== Other useful variables. TSdvector *upred_dv; //T-by-1 or fss-by-1 vector of one-step predicted unemployment rate. TSdmatrix *StrResidstran_dm; //2-by-T vector of backed-out residuals. 1st row: true Phillips equation; 2nd row: true inflation process. TSdvector *lreu_dv; //T-by-1 or fss-by-1 vector of perceived long-run excess unemployment under Ramsey policy with \pi = govpitarget. time_t prog_begtime; time_t prog_endtime; double program_hours; //Hours spent on the program. } TSconstgibbs; //+ struct TSconstgibbs_tag *CreateTSconstgibbs(struct TSinput_tag *input_ps, struct TSconstmodpars_tag *constmodpars_ps); struct TSconstgibbs_tag *DestroyTSconstgibbs(struct TSconstgibbs_tag *constgibbs_ps); void RefreshWPosteriorEstimates(struct TSconstmodpars_tag *constmodpars_ps, TSinput *input_ps, TSgovprob *govprob_ps, FILE *fptr_sp); void GibbsSimulations(struct TSconstgibbs_tag *constgibbs_ps, struct TSgovprob_tag *govprob_ps, struct TSconstmodpars_tag *constmodpars_ps, struct TSinput_tag *input_ps, char *filename_sp, FILE *fptr_inpfor_matlab, char *filename_hess); void ReadGibbsDraws_Compute(struct TSconstgibbs_tag *constgibbs_ps, struct TSgovprob_tag *govprob_ps, struct TSconstmodpars_tag *constmodpars_ps, struct TSinput_tag *input_ps, char *filename_sp, char *filename_readgibbs, FILE *fptr_lreutradeoffs, FILE *fptr_inpfor_maxGibbs); //fptr_inpfor_maxGibbs is added 03/17/05. //************************************************************ // I. For both estimation and posterior draws. //************************************************************ #define POINTEST 0x0001 //1: for point estimates only. #define GIBBSDRAWS 0x0002 //2: for Gibbs draws of parameters only. // #define SHOCKS_POINT 0x0004 //4: simulations of shocks based on the point estimate only. // #define SHOCKS_GIBBS 0x0008 //8: simulations of shocks and Gibbs draws simultaneously. TSinput *CreateTSinput(FILE *fptr_input, FILE *fptr_output, const char *filename_input, const char *filenametag); TSinput *DestroyTSinput(TSinput *input_ps); //TSconstmodpars *CreateTSconstmodpars(TSinput *input_ps, TFconstmodest *est_func, TFconstmodprob *prob_func); TSconstmodpars *CreateTSconstmodpars(FILE *fptr_input, TSinput *input_ps, TFconstmodest *est_func, TFconstmodprob *prob_func); //fptr_input is added 03/17/05. //####### Some initializations of the parameters for both the private and government sectors. ####### TSconstmodpars *DestroyTSconstmodpars(TSconstmodpars *constmodpars_ps); void ftd_freepars2modpars(void *, int); void ftd_modpars2freepars(void *, int); void updatemodfreepars5govfreepars(void *modpars_ps, int pointflag, TSdvector *xgov_dv); void updategovfreepars5modfreepars(void *modpars_ps, int pointflag, TSdvector *xgov_dv); void ftd_normalizationforgov(void *, int); double value_logpriorpdf(struct TSconstmodpars_tag *, struct TSconstgibbs_tag *, int); void updatefreepars5govfreepars(void *modpars_ps, int pointflag, TSdvector *xgov_dv); double value_logpostkernal_refresh(struct TSconstmodpars_tag *, struct TSconstgibbs_tag *, int pointflag, struct TSgovprob_tag *, TSdvector *); //************************************************************ // II. For the minimization (estimation) problem only. //************************************************************ // void ftd_freepars2modpars(TSconstmodpars *constmodpars_ps); // void ftd_modpars2freepars(TSconstmodpars *constmodpars_ps); // ftd_normalizationforgov(TSconstmodpars *constmodpars_ps); void ftd_priorsettings(TSconstmodpars *constmodpars_ps); // double value_logpriorpdf(TSconstmodpars *constmodpars_ps); // double value_logpostkernal_refresh(TSconstmodpars *constmodpars_ps, TSgovprob *govprob_ps, TSdvector *xchange_dv); //************************************************************ // III. For forecasts of inflation and unemployment only. //************************************************************ void ftd_dynfores_uinfs(FILE *fptr_fcsts, int nsteps, int locti, struct TSconstmodpars_tag *constmodpars_ps, struct TSgovprob_tag *govprob_ps, struct TSconstgibbs_tag *constgibbs_ps, int pointflag, int indxWhichModel, int store_sims); //************************************************************ // 03/17/05 Revisions. //************************************************************ void ngo_freepars2modpars(void *constmod_ps, int pointflag); void ngo_modpars2freepars(void *constmod_ps, int pointflag); double ngo_value_loglh_refresh(struct TSconstmodpars_tag *constmodpars_ps, TSgovprob *govprob_ps, TSdvector *xchange_dv); #endif