diff --git a/parser.src/d.y b/parser.src/d.y index 59f3504b3d45696e0e5f96f3fcfb65a4b84eea2b..e4124ee5c7617d1342b9f3013a0f1fba3d8a05a0 100644 --- a/parser.src/d.y +++ b/parser.src/d.y @@ -46,7 +46,7 @@ %token CORR MOMENTS FUNCTIONS DIAGNOSTIC PRINT GRAPH %token NOCORR NOMOMENTS NOFUNCTIONS NODIAGNOSTIC NOPRINT NOGRAPH %token MODEL_COMPARISON MODEL_COMPARISON_APPROXIMATION LAPLACE -%token MODIFIEDHARMONICMEAN +%token MODIFIEDHARMONICMEAN SHOCKS_FILE IRF_TYPE %token COMPILE_DEFINE COMPILE_IF COMPILE_ELSEIF COMPILE_ELSE COMPILE_ENDIF %token <string> INUMBER DNUMBER NAME OPERATORS POUND EOL INDEX EQ NE LE GE %token <p_tok> VAR_ID @@ -110,6 +110,7 @@ | unit_root_vars | model_comparison | compile_statement + | forecast ; longnames : LONGNAMES ';' @@ -160,11 +161,21 @@ varexo_det : VAREXO_DET {varlist_flag=5;} varlist ';' {print_exo_det();} ; shocks: SHOCKS ';' {ms_flag=0;p_i_shocks();} shock_list END {p_e_shocks();} - ; + | SHOCKS '(' options_shocks ')' ';' + {ms_flag=0;p_i_shocks();} shock_list END {p_e_shocks();} + ; mshocks: MSHOCKS ';' {ms_flag=1;p_i_shocks();} shock_list END {p_e_shocks();} + | MSHOCKS '(' options_shocks ')' ';' + {ms_flag=1;p_i_shocks();} shock_list END {p_e_shocks();} ; + options_shocks: option_shocks + | options_shocks ',' option_shocks + ; + + option_shocks: o_shocks_file ; + equation_list : equation_list equation {$$=add_to_queue($1,$2);} | equation_list other_inst {$$=add_to_queue($1,$2);} | equation_list do_loop {$$=copy_queue($$,$2);} @@ -418,8 +429,9 @@ varexo_det : VAREXO_DET {varlist_flag=5;} varlist ';' {print_exo_det();} o_nk : NK '=' INUMBER {p_option("nk",$3);}; o_model_comparison_approximation: MODEL_COMPARISON_APPROXIMATION '=' LAPLACE {p_s_option("model_comparison_approximation","Laplace");} | MODEL_COMPARISON_APPROXIMATION '=' MODIFIEDHARMONICMEAN {p_s_option("model_comparison_approximation","ModifiedHarmonicMean");} - o_olr_beta : OLR_BETA '=' value {p_option("olr_beta",$3);} - ; + o_olr_beta : OLR_BETA '=' value {p_option("olr_beta",$3);}; + o_shocks_file : SHOCKS_FILE '=' NAME {p_s_option("file",$3);}; + optim_option1: '\'' NAME '\'' ',' '\'' NAME '\'' {p_optim_options($2,$6,2);} | '\'' NAME '\'' ',' value {p_optim_options($2,$5,2);} @@ -843,6 +855,21 @@ varexo_det : VAREXO_DET {varlist_flag=5;} varlist ';' {print_exo_det();} compile_elseif_statement: COMPILE_ELSEIF NAME compile_operator INUMBER ';' {compile_elseif($2,$3,$4);}; + forecast: FORECAST ';' {p_forecast();} + | FORECAST '(' forecast_options ')' ';' {p_forecast();} + | FORECAST varlist4 ';' {p_forecast();} + | FORECAST '(' forecast_options ')' varlist4 ';' {p_forecast();} + ; + + forecast_options: forecast_option + | forecast_options ',' forecast_option + ; + + forecast_option: o_periods + | o_conf_sig + ; + + %% int yyerror (char *s) diff --git a/parser.src/dyn.l b/parser.src/dyn.l index 9e57cc7e778eca0ff00a690a32c63e36fc5eadf4..6d91ee4be094450dd42ae1d4db4252338637be28 100644 --- a/parser.src/dyn.l +++ b/parser.src/dyn.l @@ -73,6 +73,7 @@ estimated_params_bounds {BEGIN DYNARE2; return ESTIMATED_PARAMS_BOUNDS;} estimated_params {BEGIN DYNARE2; return ESTIMATED_PARAMS;} unit_root_vars {BEGIN DYNARE1; return UNIT_ROOT_VARS;} model_comparison {BEGIN DYNARE1; return MODEL_COMPARISON;} +forecast {BEGIN DYNARE1; return FORECAST;} <*>@define {yy_push_state(DYNARE1); return COMPILE_DEFINE;} <*>@if {yy_push_state(DYNARE1); return COMPILE_IF;} @@ -148,14 +149,16 @@ model_comparison {BEGIN DYNARE1; return MODEL_COMPARISON;} <DYNARE1>functions {return FUNCTIONS;} <DYNARE1>nofunctions {return NOFUNCTIONS;} <DYNARE1>irf {return IRF;} +<DYNARE1>irf_type {return IRF_TYPE;} <DYNARE1>hp_filter {return HP_FILTER;} <DYNARE1>hp_ngrid {return HP_NGRID;} <DYNARE1>simul_seed {return SIMUL_SEED;} <DYNARE1>simul {return SIMUL;} <DYNARE1>periods {return PERIODS;} <DYNARE1>qz_criterium {return QZ_CRITERIUM;} -<DYNARE1>optim {return OPTIM; -} +<DYNARE1>optim {return OPTIM;} +<DYNARE1>shocks_file {return SHOCKS_FILE;} + /* calib options */ <DYNARE2>autocorr {return AUTOCORR;} diff --git a/parser.src/dynare.c b/parser.src/dynare.c index b761785cc15908828f036773caf846ad370c07b5..4e47647e242b1d1c8b394755c18e4bb23a028bca 100644 --- a/parser.src/dynare.c +++ b/parser.src/dynare.c @@ -398,7 +398,7 @@ void p_shocks(struct token *var, struct queue *per, struct queue *val, int ms_fl int i,j,i1,i2,i_par,flag; struct queue *p_q; struct token **p_t; - char buffer[200]; + char buffer[2000]; char* name; check.determ = 1; @@ -1346,6 +1346,7 @@ void p_i_shocks(void) #elif defined MATLAB str_output("% (M)SHOCKS \n"); str_output("make_ex_;\n"); + str_output("shocks_file;\n"); #elif defined SCILAB str_output("// (M)SHOCKS \n"); str_output("make_ex_();\n"); @@ -1356,8 +1357,11 @@ void p_e_shocks(void) { char buffer[2000]; #if defined MATLAB || defined SCILAB - sprintf(buffer,"M_.ex_det_length = %d;\n",ex_det_length); - str_output(buffer); + if (ex_det_length > 0) + { + sprintf(buffer,"M_.ex_det_length = %d;\n",ex_det_length); + str_output(buffer); + } #endif } @@ -1386,7 +1390,7 @@ void dynare_init(char* fname,struct s_runtime_options runtime_options) { str_output("clear all\n"); } - str_output("global scalv_ ex_ ex_det_ recur_ recurs_ ys_ y_ exe_ exe_det_ lgy_ lgx_ lgr_ dsmpl_ endval_\n"); + str_output("global scalv_ ex_ ex_det_ recur_ recurs_ ys_ y_ exe_ exe_det_ lgy_ lgx_ lgx_det_ lgr_ dsmpl_ endval_\n"); str_output("global endo_nbr exo_nbr exo_det_nbr iy_ ykmin_ ykmax_ xkmin_ xkmax_ zkmin_ zkmax_ iter_\n"); str_output("global dynatol_ slowc_ maxit_ valf_ ys0_ recurs0_ ex0_ timing_ ct_ gstep_ Sigma_e_ fname_ lgx_orig_ord_ iter_ options_ dr_ oo_ trend_coeff_ eigenvalues_\n"); str_output("global M_\n"); @@ -3132,6 +3136,50 @@ void p_model_comparison(int flag_model_prior) str_output("model_comparison(ModelNames_,ModelPriors_);\n"); } +void p_forecast() +{ + char buffer[2000]; + int i; +#ifdef SCILAB + str_output("global "); + for(i=0;i < var_nbr; i++) + { + if (var_list[i].endo_exo == 1) + { + str_output(var_list[i].name); + str_output(" "); + } + } + str_output("\n"); +#endif +#if defined MATLAB || defined SCILAB + if (nbr_tmpvar == 0) + { + str_output("var_list_ = [];\n"); + } + else + { + strcpy(buffer,"var_list_ = '"); + strcat(buffer,tmpvar_list[0]); + strcat(buffer,"';\n"); + for(i=2;i<nbr_tmpvar;i+=2) + { +#ifdef MATLAB + strcat(buffer,"var_list_ = str2mat(var_list_,'"); + strcat(buffer,tmpvar_list[i]); + strcat(buffer,"');\n"); +#else + strcat(buffer,"var_list_ = [var_list_;'"); + strcat(buffer,tmpvar_list[i]); + strcat(buffer,"'];\n"); +#endif + } + str_output(buffer); + } + str_output("forecast(var_list_);\n"); +#endif +} + /* 02/22/01 MJ added test for nbr of equations != nbr endogenous variables replaced stderr_ by Sigma_e_