| 1 |
/* |
| 2 |
* Copyright (C) 1996-2011 Daniel Waggoner and Tao Zha |
| 3 |
* |
| 4 |
* This free software: you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation, either version 3 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* It is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* If you did not received a copy of the GNU General Public License |
| 15 |
* with this software, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "dw_state_space_command_line_output.h" |
| 19 |
#include "dw_state_space_historical_decomposition.h" |
| 20 |
#include "dw_state_space_forecast.h" |
| 21 |
#include "dw_state_space_counterfactual.h" |
| 22 |
#include "dw_state_space_variance_decomposition.h" |
| 23 |
#include "dw_state_space_impulse_response.h" |
| 24 |
#include "dw_MSStateSpace.h" |
| 25 |
#include "dw_metropolis_simulation.h" |
| 26 |
#include "dw_parse_cmd.h" |
| 27 |
#include "dw_ascii.h" |
| 28 |
#include "dw_array.h" |
| 29 |
#include "dw_rand.h" |
| 30 |
#include "dw_std.h" |
| 31 |
#include "dw_histogram.h" |
| 32 |
#include "dw_math.h" |
| 33 |
#include "dw_error.h" |
| 34 |
#include "dw_mdd_switch.h" |
| 35 |
|
| 36 |
#include <math.h> |
| 37 |
#include <string.h> |
| 38 |
|
| 39 |
// Get tag from command line |
| 40 |
char* GetTag(int nargs, char **args) |
| 41 |
{ |
| 42 |
char *tag; |
| 43 |
tag=dw_ParseString(nargs,args,'t',(char*)NULL); |
| 44 |
tag=dw_ParseString_String(nargs,args,"ft",tag); |
| 45 |
tag=dw_ParseString_String(nargs,args,"outtag",tag); |
| 46 |
return tag; |
| 47 |
} |
| 48 |
|
| 49 |
/* |
| 50 |
Returns 1 if model is a T_MSStateSpace model and 0 otherwise |
| 51 |
*/ |
| 52 |
int IsStateSpaceModel(TStateModel *model) |
| 53 |
{ |
| 54 |
char *model_id=ModelType(model); |
| 55 |
if (!model_id || strcmp(model_id,"T_MSStateSpace")) |
| 56 |
{ |
| 57 |
printf("Expecting T_MSStateSpace model - Model type = %s\n",model_id ? model_id : "null"); |
| 58 |
return 0; |
| 59 |
} |
| 60 |
else |
| 61 |
return 1; |
| 62 |
} |
| 63 |
|
| 64 |
/* |
| 65 |
Returns 1 if -parmfile flag is not present. |
| 66 |
Returns 2 if parameters successfully read. |
| 67 |
Returns 0 otherwise. |
| 68 |
|
| 69 |
offset should generally be 2 because first two elements are the log posterior and log likelihood. |
| 70 |
*/ |
| 71 |
int ReadParameters(int nargs, char **args, TStateModel *model, int offset, int verbose) |
| 72 |
{ |
| 73 |
FILE *f_in; |
| 74 |
char *filename; |
| 75 |
TVector parameters; |
| 76 |
if (filename=dw_ParseString_String(nargs,args,"parmfile",(char*)NULL)) |
| 77 |
if (f_in=fopen(filename,"rt")) |
| 78 |
{ |
| 79 |
if (!dw_ReadVector(f_in,parameters=CreateVector(offset + NumberFreeParametersTheta(model) + NumberFreeParametersQ(model)))) |
| 80 |
{ |
| 81 |
printf("Unable to read parameters file - %s.\n",filename); |
| 82 |
return 0; |
| 83 |
} |
| 84 |
else |
| 85 |
{ |
| 86 |
ConvertFreeParametersToTheta(model,pElementV(parameters)+offset); |
| 87 |
ConvertFreeParametersToQ(model,pElementV(parameters)+offset+NumberFreeParametersTheta(model)); |
| 88 |
if (verbose) |
| 89 |
{ |
| 90 |
printf("Parameter file: %s\n",filename); |
| 91 |
if (offset > 1) |
| 92 |
printf("Log Likelihood: %le - %le\n",ElementV(parameters,1),LogLikelihood_StatesIntegratedOut(model)); |
| 93 |
if (offset > 0) |
| 94 |
printf("Log Posterior: %le - %le\n",ElementV(parameters,0),LogPosterior_StatesIntegratedOut(model)); |
| 95 |
} |
| 96 |
} |
| 97 |
FreeVector(parameters); |
| 98 |
fclose(f_in); |
| 99 |
} |
| 100 |
else |
| 101 |
{ |
| 102 |
printf("Unable to open parameters file - %s.\n",filename); |
| 103 |
return 0; |
| 104 |
} |
| 105 |
return 1; |
| 106 |
} |
| 107 |
|
| 108 |
/* |
| 109 |
Attempts to read delimited file containing a matrix. |
| 110 |
*/ |
| 111 |
TMatrix dw_ReadDelimitedFile_matrix(FILE *f, char* filename, char delimiter, int flag, double invalid_identifier) |
| 112 |
{ |
| 113 |
int nrows, ncols, i, j; |
| 114 |
double **M=dw_ReadDelimitedFile_double(f,filename,delimiter,flag,invalid_identifier); |
| 115 |
TMatrix D; |
| 116 |
if (!M) return (TMatrix)NULL; |
| 117 |
nrows=dw_DimA(M); |
| 118 |
ncols=dw_DimA(M[0]); |
| 119 |
for (i=nrows-1; i > 0; i--) |
| 120 |
if (ncols != dw_DimA(M[0])) |
| 121 |
{ |
| 122 |
dw_FreeArray(M); |
| 123 |
return (TMatrix)NULL; |
| 124 |
} |
| 125 |
D=CreateMatrix(nrows,ncols); |
| 126 |
for (i=nrows-1; i >= 0; i--) |
| 127 |
for (j=ncols-1; j >= 0; j--) |
| 128 |
ElementM(D,i,j)=M[i][j]; |
| 129 |
dw_FreeArray(M); |
| 130 |
return D; |
| 131 |
} |
| 132 |
|
| 133 |
/* |
| 134 |
Attempts to read percentiles from command line. Searches for command line argument of the form |
| 135 |
|
| 136 |
-percentiles n p[0] p[1] ... p[n-1] |
| 137 |
|
| 138 |
If -percentiles is not present, and -error_bands is present, returns default percentiles which |
| 139 |
are (0.16 0.50 0.84). |
| 140 |
*/ |
| 141 |
TVector ReadPercentiles(int nargs, char** args) |
| 142 |
{ |
| 143 |
int i, j, n; |
| 144 |
TVector percentiles=(TVector)NULL; |
| 145 |
if ((i=dw_FindArgument_String(nargs,args,"percentiles")) != -1) |
| 146 |
{ |
| 147 |
if ((i+1 < nargs) && dw_IsInteger(args[i+1]) && ((n=atoi(args[i+1])) > 0) && (i+1+n < nargs)) |
| 148 |
{ |
| 149 |
percentiles=CreateVector(n); |
| 150 |
for (j=0; j < n; j++) |
| 151 |
if (!dw_IsFloat(args[i+2+j])|| ((ElementV(percentiles,j)=atof(args[i+2+j])) <= 0.0) || (ElementV(percentiles,j) >= 1.0)) |
| 152 |
{ |
| 153 |
FreeVector(percentiles); |
| 154 |
dw_UserError("Error parsing percentiles\n"); |
| 155 |
return (TVector)NULL; |
| 156 |
} |
| 157 |
} |
| 158 |
else |
| 159 |
dw_UserError("Error parsing percentiles\n"); |
| 160 |
} |
| 161 |
else |
| 162 |
if (dw_FindArgument_String(nargs,args,"error_bands") != -1) |
| 163 |
{ |
| 164 |
percentiles=CreateVector(3); |
| 165 |
ElementV(percentiles,0)=0.16; ElementV(percentiles,1)=0.5; ElementV(percentiles,2)=0.84; |
| 166 |
} |
| 167 |
return percentiles; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
/* |
| 172 |
Command line parameters |
| 173 |
|
| 174 |
General parameters |
| 175 |
-t : filename tag |
| 176 |
-ft : filename tag - supersedes -t |
| 177 |
-outtag : filename tag - supersedes -t and -ft |
| 178 |
|
| 179 |
Adaptive jump ratio parameters |
| 180 |
-cs <real>: target acceptance rate for single variable calibrations (default = 0.20) |
| 181 |
-ca <real> : target acceptance rate for overall calibrations (default = 0.25) |
| 182 |
-ps <integer> : the initial period for the single variable calibrations (default = 20) |
| 183 |
-pa <integer> : the initial period for the overall calibrations (default = 20) |
| 184 |
-mps <integer> : the maximum period for the single variable calibrations (default = 8*ps) |
| 185 |
-mpa <integer> : the maximum period for the overall calibrations (default = 16*mps) |
| 186 |
-diagonal : Forces calibration using two-pass diagonal, even if calibration has alread been performed. |
| 187 |
This is the default option. |
| 188 |
-variance <filename> : Forces calibration using two-pass variance, even if calibration has already |
| 189 |
been performed. Reads draws from filename. |
| 190 |
-hessian : Forces calibration using two-pass hessian, even if calibration has already been performed. |
| 191 |
-special : Forces calibration using two-pass with custom directions (calls SetupDirections()), even if |
| 192 |
calibration has already been performed. |
| 193 |
-af <filename> : file for storing the calibrated metropolis parameters. (default = metropolis_theta_<tag>.out) |
| 194 |
-hf <filename> : file containing the hessian matrix. (default = outdataout_<tag>.prn) |
| 195 |
-database : write to the database instead of a file. |
| 196 |
|
| 197 |
Simulation parameters |
| 198 |
-seed : seed value for the random number generator (default = 0 - uses clock and pid) |
| 199 |
-ndraws : number of draws to save (default = 1000) |
| 200 |
-burnin : number of burn-in draws (default = 0.1 * ndraws) |
| 201 |
-thin : thinning factor. Total number of draws made is thin*ndraws + burnin (default = 1) |
| 202 |
-of <filename> : output filename (default = simulation_<tag>.out) |
| 203 |
-parmfile <parameter filename> : parameter filename |
| 204 |
-random <filename> : Reads previous simulation output and randomly selects a starting value. |
| 205 |
-database : Saves draws to database - not currently implemented |
| 206 |
|
| 207 |
Attempts to setup metropolis parameters from command line for simulating theta. Note if none of -diagonal, |
| 208 |
-hessian, or -special are specified, the default behavior is to first look for calibration file and it is |
| 209 |
not present to use the two-pass diagonal method. |
| 210 |
*/ |
| 211 |
void dw_state_space_simulate_command_line(int n_args, char **args, TStateModel *model) |
| 212 |
{ |
| 213 |
FILE *f_out, *f_start; |
| 214 |
char *tag, *default_filename, *filename, *fmt; |
| 215 |
int j, row, ndraws, burn_in, thin, default_period=20, n_theta=NumberFreeParametersTheta(model), |
| 216 |
n_q=NumberFreeParametersQ(model); |
| 217 |
TMatrix draws; |
| 218 |
TVector parameters; |
| 219 |
PRECISION logposterior, loglikelihood; |
| 220 |
|
| 221 |
// Initialize generator |
| 222 |
dw_initialize_generator(dw_ParseInteger_String(n_args,args,"seed",0)); |
| 223 |
|
| 224 |
// Get tag from command line |
| 225 |
tag=dw_ParseString(n_args,args,'t',(char*)NULL); |
| 226 |
tag=dw_ParseString_String(n_args,args,"ft",tag); |
| 227 |
tag=dw_ParseString_String(n_args,args,"outtag",tag); |
| 228 |
|
| 229 |
// Create parameters vector |
| 230 |
parameters=CreateVector(2+n_theta+n_q); |
| 231 |
|
| 232 |
// Write initial value |
| 233 |
fmt="simulation_startmax_%s.out"; |
| 234 |
sprintf(filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 235 |
if (!(f_start=fopen(filename,"wt"))) |
| 236 |
{ |
| 237 |
printf("Unable to open %s\n",filename); |
| 238 |
dw_free(filename); |
| 239 |
} |
| 240 |
else |
| 241 |
{ |
| 242 |
dw_free(filename); |
| 243 |
ElementV(parameters,0)=LogPosterior_StatesIntegratedOut(model); |
| 244 |
ElementV(parameters,1)=LogLikelihood_StatesIntegratedOut(model); |
| 245 |
if (n_theta) ConvertThetaToFreeParameters(model,pElementV(parameters)+2); |
| 246 |
if (n_q) ConvertQToFreeParameters(model,pElementV(parameters)+2+n_theta); |
| 247 |
dw_PrintVector(f_start,parameters," %.14le"); |
| 248 |
|
| 249 |
// Push starting value into model and write new initial value |
| 250 |
switch (ReadParameters(n_args,args,model,2,0)) |
| 251 |
{ |
| 252 |
case 0: |
| 253 |
break; |
| 254 |
case 2: |
| 255 |
if (f_start) |
| 256 |
{ |
| 257 |
ElementV(parameters,0)=LogPosterior_StatesIntegratedOut(model); |
| 258 |
ElementV(parameters,1)=LogLikelihood_StatesIntegratedOut(model); |
| 259 |
if (n_theta) ConvertThetaToFreeParameters(model,pElementV(parameters)+2); |
| 260 |
if (n_q) ConvertQToFreeParameters(model,pElementV(parameters)+2+n_theta); |
| 261 |
dw_PrintVector(f_start,parameters," %.14le"); |
| 262 |
} |
| 263 |
case 1: |
| 264 |
// Random starting values |
| 265 |
if (filename=dw_ParseString_String(n_args,args,"random",(char*)NULL)) |
| 266 |
if (draws=dw_ReadPosteriorDraws((FILE*)NULL,filename,(char*)NULL,n_theta+n_q)) |
| 267 |
{ |
| 268 |
row=(int)floor(dw_uniform_rnd()*RowM(draws)); |
| 269 |
if (row >= RowM(draws)) row=RowM(draws); |
| 270 |
RowVector(parameters,draws,row); |
| 271 |
if (n_theta) ConvertFreeParametersToTheta(model,pElementV(parameters)+2); |
| 272 |
if (n_q) ConvertFreeParametersToQ(model,pElementV(parameters)+2+n_theta); |
| 273 |
printf("Using row %d as random starting value from %s\n",row,filename); |
| 274 |
printf("initial log posterior = %le - %le\n",logposterior=LogPosterior_StatesIntegratedOut(model),ElementV(parameters,0)); |
| 275 |
printf("initial log likelihood = %le - %le\n",loglikelihood=LogLikelihood_StatesIntegratedOut(model),ElementV(parameters,1)); |
| 276 |
ElementV(parameters,0)=logposterior; |
| 277 |
ElementV(parameters,1)=loglikelihood; |
| 278 |
if (f_start) dw_PrintVector(f_start,parameters," %.14le"); |
| 279 |
FreeMatrix(draws); |
| 280 |
} |
| 281 |
else |
| 282 |
{ |
| 283 |
printf("Unable to open %s\n",filename); |
| 284 |
break; |
| 285 |
} |
| 286 |
|
| 287 |
// Set maximum posterior |
| 288 |
model->max_log_posterior=LogPosterior_StatesIntegratedOut(model); |
| 289 |
if (model->max_posterior_theta) ConvertThetaToFreeParameters(model,pElementV(model->max_posterior_theta)); |
| 290 |
if (model->max_posterior_q) ConvertQToFreeParameters(model,pElementV(model->max_posterior_q)); |
| 291 |
|
| 292 |
if (SetUpMetropolisSimulation(n_args,args,tag,model,default_period)) |
| 293 |
{ |
| 294 |
// simulation parameters |
| 295 |
ndraws=dw_ParseInteger_String(n_args,args,"ndraws",1000); |
| 296 |
burn_in=dw_ParseInteger_String(n_args,args,"burnin",ndraws/10); |
| 297 |
thin=dw_ParseInteger_String(n_args,args,"thin",1); |
| 298 |
|
| 299 |
// Starting Simulation |
| 300 |
if (dw_FindArgument_String(n_args,args,"database") == -1) |
| 301 |
{ |
| 302 |
|
| 303 |
// output filename |
| 304 |
fmt="simulation_%s.out"; |
| 305 |
sprintf(default_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 306 |
filename=dw_ParseString_String(n_args,args,"fo",default_filename); |
| 307 |
|
| 308 |
// Jake's Modifications to take an input and output file |
| 309 |
char *tmp_name = NULL; |
| 310 |
int i=0; |
| 311 |
for (i=0;i< n_args;i++) { |
| 312 |
if (strstr(args[i],"-o") != NULL || strstr(args[i],"/o") != NULL || strstr(args[i],"--output") != NULL) { |
| 313 |
// Change the output file for the estimation to the passed argument |
| 314 |
if ((tmp_name=strstr(args[i],"=")) != NULL) { |
| 315 |
tmp_name+=1; |
| 316 |
} else { |
| 317 |
tmp_name = args[i+1]; |
| 318 |
} |
| 319 |
filename = tmp_name; |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
if (f_out=fopen(filename,"wt")) |
| 324 |
{ |
| 325 |
Simulate(burn_in,ndraws,thin,1000,model,f_out); |
| 326 |
if (f_start) |
| 327 |
{ |
| 328 |
if (n_theta) ConvertFreeParametersToTheta(model,pElementV(model->max_posterior_theta)); |
| 329 |
if (n_q) ConvertFreeParametersToQ(model,pElementV(model->max_posterior_q)); |
| 330 |
fprintf(f_start,"%.14le %.14le",model->max_log_posterior,LogLikelihood_StatesIntegratedOut(model)); |
| 331 |
if (model->max_posterior_theta) |
| 332 |
for (j=0; j < n_theta; j++) fprintf(f_start," %.14le",ElementV(model->max_posterior_theta,j)); |
| 333 |
if (model->max_posterior_q) |
| 334 |
dw_PrintVector(f_start,model->max_posterior_q," %.14le"); |
| 335 |
else |
| 336 |
fprintf(f_start,"\n"); |
| 337 |
} |
| 338 |
fclose(f_out); |
| 339 |
} |
| 340 |
else |
| 341 |
printf("Unable to open %s\n",filename); |
| 342 |
|
| 343 |
dw_free(default_filename); |
| 344 |
} |
| 345 |
else |
| 346 |
{ |
| 347 |
f_out=(FILE*)NULL; |
| 348 |
// initialize sdsm |
| 349 |
//sdsm_init(1001,100,100,1,0,1,1); |
| 350 |
printf("-database not yet supported\n"); |
| 351 |
break; |
| 352 |
} |
| 353 |
} |
| 354 |
else |
| 355 |
printf("Error setting up Metropolis adaptive simulation\n"); |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
if (f_start) fclose(f_start); |
| 360 |
FreeVector(parameters); |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
/* |
| 365 |
Command line parameters |
| 366 |
|
| 367 |
-t <tag> : input and output tag |
| 368 |
|
| 369 |
-ft <tag> : takes precedence over -t |
| 370 |
|
| 371 |
-outtag <tag> : takes presedence over -t and -ft |
| 372 |
|
| 373 |
-parmfile <parameter filename> : parameter filename |
| 374 |
|
| 375 |
-horizon : The horizon over which to compute the forecasts. (default = 12) |
| 376 |
|
| 377 |
-data : Number of actual data points to include. (default = 0) |
| 378 |
|
| 379 |
-mean : Produces mean forecast. (default = off) |
| 380 |
|
| 381 |
-error_bands : Output error bands. (default = off - only median is computed) |
| 382 |
|
| 383 |
-percentiles n p_1 p_2 ... p_n : Percentiles to compute. The first parameter |
| 384 |
after percentiles must be the number of percentiles and the following |
| 385 |
values are the actual percentiles. (default = 3 0.16 0.50 0.84 if |
| 386 |
error_bands flag is set and default = 1 0.50 otherwise) |
| 387 |
|
| 388 |
-parameter_uncertainty : Apply parameter uncertainty when computing error bands. |
| 389 |
|
| 390 |
-thin : Thinning factor. Only 1/thin of the draws in posterior draws file |
| 391 |
are used. (default = 1) |
| 392 |
|
| 393 |
-shocks_per_parameter : Number of shocks and regime paths to draw for each |
| 394 |
parameter draw. (default = 1 if parameter_uncertainty is set and |
| 395 |
default = 10,000 otherwise) |
| 396 |
|
| 397 |
-regimes : Produces forecasts as if each regime were permanent. |
| 398 |
|
| 399 |
-regime s : Produces forecasts as if regime s were permanent. |
| 400 |
|
| 401 |
-special : Products conditional forecast - hard coded shocks, make changes to Forecast_ConditionalShocks_Special |
| 402 |
|
| 403 |
*/ |
| 404 |
void dw_state_space_forecast_command_line(int nargs, char **args, TStateModel *model) |
| 405 |
{ |
| 406 |
FILE *f_out; |
| 407 |
char *out_filename, *fmt, *tag; |
| 408 |
TMatrix posterior_draws=(TMatrix)NULL, Fs; |
| 409 |
TVector *F, percentiles=(TVector)NULL; |
| 410 |
int s, i, j, n, t, horizon, thin, draws, plotdata, |
| 411 |
nparameters=NumberFreeParametersTheta(model) + NumberFreeParametersQ(model); |
| 412 |
T_MSStateSpace *statespace; |
| 413 |
|
| 414 |
if (!IsStateSpaceModel(model)) return; |
| 415 |
|
| 416 |
statespace=(T_MSStateSpace*)(model->theta); |
| 417 |
|
| 418 |
tag=GetTag(nargs,args); |
| 419 |
|
| 420 |
ReadParameters(nargs,args,model,2,0); |
| 421 |
|
| 422 |
// Get horizon from command line |
| 423 |
horizon=dw_ParseInteger_String(nargs,args,"horizon",12); |
| 424 |
|
| 425 |
// Get number of data points to plot |
| 426 |
plotdata=dw_ParseInteger_String(nargs,args,"data",0); |
| 427 |
|
| 428 |
// Mean forecast |
| 429 |
if (dw_FindArgument_String(nargs,args,"mean") != -1) |
| 430 |
{ |
| 431 |
fmt="forecasts_mean_%s.prn"; |
| 432 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 433 |
f_out=fopen(out_filename,"wt"); |
| 434 |
dw_free(out_filename); |
| 435 |
printf("Constructing mean forecast\n"); |
| 436 |
if (F=dw_state_space_mean_unconditional_forecast((TVector*)NULL,horizon,statespace->nobs,model)) |
| 437 |
{ |
| 438 |
for (t=statespace->nobs-plotdata+1; t <= statespace->nobs; t++) |
| 439 |
{ |
| 440 |
fprintf(f_out,"%d ",t); |
| 441 |
dw_PrintVector(f_out,statespace->y[t],"%le "); |
| 442 |
} |
| 443 |
for (i=0; i < horizon; i++) |
| 444 |
{ |
| 445 |
fprintf(f_out,"%d ",t++); |
| 446 |
dw_PrintVector(f_out,F[i],"%le "); |
| 447 |
} |
| 448 |
dw_FreeArray(F); |
| 449 |
} |
| 450 |
fclose(f_out); |
| 451 |
return; |
| 452 |
} |
| 453 |
|
| 454 |
// Special forecast |
| 455 |
if (dw_FindArgument_String(nargs,args,"special") != -1) |
| 456 |
{ |
| 457 |
fmt="forecasts_special_%s.prn"; |
| 458 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 459 |
f_out=fopen(out_filename,"wt"); |
| 460 |
dw_free(out_filename); |
| 461 |
printf("Constructing special forecast\n"); |
| 462 |
if (Fs=Forecast_ConditionalShocks_Special(horizon,model)) |
| 463 |
{ |
| 464 |
for (t=statespace->nobs-plotdata+1; t <= statespace->nobs; t++) |
| 465 |
{ |
| 466 |
fprintf(f_out,"%d ",t); |
| 467 |
dw_PrintVector(f_out,statespace->y[t],"%le "); |
| 468 |
} |
| 469 |
for (i=0; i < horizon; i++) |
| 470 |
{ |
| 471 |
fprintf(f_out,"%d ",t++); |
| 472 |
for (j=0; j < ColM(Fs); j++) fprintf(f_out,"%le ",ElementM(Fs,i,j)); |
| 473 |
fprintf(f_out,"\n"); |
| 474 |
} |
| 475 |
FreeMatrix(Fs); |
| 476 |
} |
| 477 |
fclose(f_out); |
| 478 |
return; |
| 479 |
} |
| 480 |
|
| 481 |
if (dw_FindArgument_String(nargs,args,"parameter_uncertainty") != -1) |
| 482 |
{ |
| 483 |
// Read posterior draws |
| 484 |
printf("Reading posterior draws\n"); |
| 485 |
posterior_draws=dw_ReadPosteriorDraws((FILE*)NULL,(char*)NULL,tag,nparameters); |
| 486 |
if (!posterior_draws) |
| 487 |
{ |
| 488 |
printf("dw_state_space_forecast_command_line(): Unable to read posterior draws\n"); |
| 489 |
printf(" tag: %s\n",tag ? tag : "null"); |
| 490 |
dw_exit(0); |
| 491 |
} |
| 492 |
|
| 493 |
// Get thinning factor from command line |
| 494 |
thin=dw_ParseInteger_String(nargs,args,"thin",1); |
| 495 |
|
| 496 |
// Get shocks_per_parameter from command line |
| 497 |
draws=dw_ParseInteger_String(nargs,args,"shocks_per_parameter",1); |
| 498 |
} |
| 499 |
else |
| 500 |
{ |
| 501 |
// Using posterior estimate |
| 502 |
posterior_draws=(TMatrix)NULL; |
| 503 |
|
| 504 |
// thinning factor not used |
| 505 |
thin=1; |
| 506 |
|
| 507 |
// Get shocks_per_parameter from command line |
| 508 |
draws=dw_ParseInteger_String(nargs,args,"shocks_per_parameter",10000); |
| 509 |
} |
| 510 |
|
| 511 |
// Setup percentiles |
| 512 |
if ((i=dw_FindArgument_String(nargs,args,"percentiles")) == -1) |
| 513 |
if (dw_FindArgument_String(nargs,args,"error_bands") == -1) |
| 514 |
{ |
| 515 |
percentiles=CreateVector(1); |
| 516 |
ElementV(percentiles,0)=0.5; |
| 517 |
} |
| 518 |
else |
| 519 |
{ |
| 520 |
percentiles=CreateVector(3); |
| 521 |
ElementV(percentiles,0)=0.16; ElementV(percentiles,1)=0.5; ElementV(percentiles,2)=0.84; |
| 522 |
} |
| 523 |
else |
| 524 |
if ((i+1 < nargs) && dw_IsInteger(args[i+1]) && ((n=atoi(args[i+1])) > 0) && (i+1+n < nargs)) |
| 525 |
{ |
| 526 |
percentiles=CreateVector(n); |
| 527 |
for (j=0; j < n; j++) |
| 528 |
if (!dw_IsFloat(args[i+2+j])|| ((ElementV(percentiles,j)=atof(args[i+2+j])) <= 0.0) |
| 529 |
|| (ElementV(percentiles,j) >= 1.0)) break; |
| 530 |
if (j < n) |
| 531 |
{ |
| 532 |
FreeVector(percentiles); |
| 533 |
printf("dw_state_space_forecast_command_line(): Error parsing percentiles\n"); |
| 534 |
dw_exit(0); |
| 535 |
} |
| 536 |
} |
| 537 |
else |
| 538 |
{ |
| 539 |
printf("dw_state_space_forecast_command_line(): Error parsing percentiles\n"); |
| 540 |
dw_exit(0); |
| 541 |
} |
| 542 |
|
| 543 |
if (dw_FindArgument_String(nargs,args,"regimes") != -1) |
| 544 |
for (s=0; s < statespace->nbasestates; s++) |
| 545 |
{ |
| 546 |
fmt="forecasts_percentiles_regime_%d_%s.prn"; |
| 547 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 3),fmt,s,tag); |
| 548 |
f_out=fopen(out_filename,"wt"); |
| 549 |
dw_free(out_filename); |
| 550 |
printf("Constructing percentiles for forecasts - regime %d\n",s); |
| 551 |
dw_state_space_forecast_percentile_regime(f_out,percentiles,draws,posterior_draws,thin,s,model->nobs,horizon,model,plotdata); |
| 552 |
fclose(f_out); |
| 553 |
} |
| 554 |
else |
| 555 |
if (((s=dw_ParseInteger_String(nargs,args,"regime",-1)) >= 0) && (s < statespace->nbasestates)) |
| 556 |
{ |
| 557 |
fmt="forecasts_percentiles_regime_%d_%s.prn"; |
| 558 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 3),fmt,s,tag); |
| 559 |
f_out=fopen(out_filename,"wt"); |
| 560 |
dw_free(out_filename); |
| 561 |
printf("Constructing percentiles for forecasts - regime %d\n",s); |
| 562 |
dw_state_space_forecast_percentile_regime(f_out,percentiles,draws,posterior_draws,thin,s,model->nobs,horizon,model,plotdata); |
| 563 |
fclose(f_out); |
| 564 |
} |
| 565 |
else |
| 566 |
{ |
| 567 |
fmt="forecasts_percentiles_%s.prn"; |
| 568 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 569 |
f_out=fopen(out_filename,"wt"); |
| 570 |
dw_free(out_filename); |
| 571 |
printf("Constructing percentiles for forecasts - %d draws of shocks per posterior value\n",draws); |
| 572 |
dw_state_space_forecast_percentile(f_out,percentiles,draws,posterior_draws,thin,model->nobs,horizon,model,plotdata); |
| 573 |
fclose(f_out); |
| 574 |
} |
| 575 |
|
| 576 |
FreeMatrix(posterior_draws); |
| 577 |
FreeVector(percentiles); |
| 578 |
} |
| 579 |
|
| 580 |
/* |
| 581 |
Command line parameters |
| 582 |
|
| 583 |
-t <tag> : input and output tag |
| 584 |
|
| 585 |
-ft <tag> : takes precedence over -t |
| 586 |
|
| 587 |
-outtag <tag> : takes presedence over -t and -ft |
| 588 |
|
| 589 |
-parmfile <parameter filename> : parameter filename |
| 590 |
|
| 591 |
-horizon : The horizon over which to compute the forecast historical decompostion. (default = 12) |
| 592 |
|
| 593 |
-startdate : The period in which to begin the historical decomposition (default = 2); |
| 594 |
|
| 595 |
-observables : Produces historical decomposition of observables (default = off) |
| 596 |
|
| 597 |
-states : Produces historical decomposition of states. (default = off) |
| 598 |
*/ |
| 599 |
void dw_state_space_historical_decomposition_command_line(int nargs, char **args, TStateModel *model) |
| 600 |
{ |
| 601 |
FILE *f_out; |
| 602 |
char *out_filename, *fmt, *tag; |
| 603 |
TMatrix historical_decomposition; |
| 604 |
int i, j, k, t, horizon, start_date; |
| 605 |
T_MSStateSpace *statespace; |
| 606 |
|
| 607 |
if (!IsStateSpaceModel(model)) return; |
| 608 |
|
| 609 |
statespace=(T_MSStateSpace*)(model->theta); |
| 610 |
|
| 611 |
tag=GetTag(nargs,args); |
| 612 |
|
| 613 |
ReadParameters(nargs,args,model,2,0); |
| 614 |
|
| 615 |
// Get horizon from command line |
| 616 |
horizon=dw_ParseInteger_String(nargs,args,"horizon",12); |
| 617 |
|
| 618 |
// Get start date |
| 619 |
start_date=dw_ParseInteger_String(nargs,args,"startdate",2); |
| 620 |
|
| 621 |
if (dw_FindArgument_String(nargs,args,"observables") != -1) |
| 622 |
{ |
| 623 |
fmt="historical_%s.out"; |
| 624 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 625 |
f_out=fopen(out_filename,"wt"); |
| 626 |
dw_free(out_filename); |
| 627 |
printf("Constructing historical decompositions - observables\n"); |
| 628 |
historical_decomposition=dw_state_space_historical_decomposition((TMatrix)NULL,start_date,horizon,model); |
| 629 |
for (t=0; t < RowM(historical_decomposition); t++) |
| 630 |
{ |
| 631 |
fprintf(f_out,"%d, ",start_date+t); |
| 632 |
for (k=0, i=0; i < statespace->ny; i++) |
| 633 |
{ |
| 634 |
for (j=0; j < statespace->nepsilon+statespace->nu+2; j++, k++) |
| 635 |
fprintf(f_out,"%.14le, ",ElementM(historical_decomposition,t,k)); |
| 636 |
fprintf(f_out,", , "); |
| 637 |
} |
| 638 |
fprintf(f_out,"\n"); |
| 639 |
} |
| 640 |
fclose(f_out); |
| 641 |
|
| 642 |
/***** Debugging output *****/ |
| 643 |
CheckHistoricalDecomposition(historical_decomposition,1,model); |
| 644 |
Check_SmoothedInfo(model,0.1); |
| 645 |
Check_FilteredInfo(model,0.1); |
| 646 |
/****************************/ |
| 647 |
|
| 648 |
FreeMatrix(historical_decomposition); |
| 649 |
} |
| 650 |
|
| 651 |
if (dw_FindArgument_String(nargs,args,"states") != -1) |
| 652 |
{ |
| 653 |
fmt="historicalstates_%s.out"; |
| 654 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 655 |
f_out=fopen(out_filename,"wt"); |
| 656 |
dw_free(out_filename); |
| 657 |
printf("Constructing historical decompositions - states\n"); |
| 658 |
historical_decomposition=dw_state_space_historical_decomposition_states((TMatrix)NULL,start_date,horizon,model); |
| 659 |
for (t=0; t < RowM(historical_decomposition); t++) |
| 660 |
{ |
| 661 |
fprintf(f_out,"%d, ",start_date+t); |
| 662 |
for (k=0, i=0; i < statespace->nz; i++) |
| 663 |
{ |
| 664 |
for (j=0; j < statespace->nepsilon+2; j++, k++) |
| 665 |
fprintf(f_out,"%.14le, ",ElementM(historical_decomposition,t,k)); |
| 666 |
fprintf(f_out,", , "); |
| 667 |
} |
| 668 |
fprintf(f_out,"\n"); |
| 669 |
} |
| 670 |
fclose(f_out); |
| 671 |
FreeMatrix(historical_decomposition); |
| 672 |
} |
| 673 |
} |
| 674 |
|
| 675 |
/* |
| 676 |
Command line parameters |
| 677 |
|
| 678 |
-t <tag> : input and output tag |
| 679 |
|
| 680 |
-ft <tag> : takes precedence over -t |
| 681 |
|
| 682 |
-outtag <tag> : takes presedence over -t and -ft |
| 683 |
|
| 684 |
-parmfile <parameter filename> : parameter filename |
| 685 |
|
| 686 |
-horizon : The horizon over which to compute the impulse responses. (default = 12) |
| 687 |
|
| 688 |
-parameter_uncertainty : Use posterior draws to compute error bands for the impulse responses |
| 689 |
|
| 690 |
-percentiles n p_1 p_2 ... p_n : Percentiles to compute. The first parameter |
| 691 |
after percentiles must be the number of percentiles and the following |
| 692 |
values are the actual percentiles. (default = 3 0.16 0.50 0.84) |
| 693 |
|
| 694 |
-thin : Thinning factor. Only 1/thin of the draws in posterior draws file are used. (default = 1) |
| 695 |
|
| 696 |
-states : Print impluse responses of state variables to shocks (default = off) |
| 697 |
|
| 698 |
-observables : Print impulse responses of observable variables to shocks (default = off) |
| 699 |
|
| 700 |
-ergodic : Print impuluse responses using ergodic distribution as initial condition for shocks. |
| 701 |
|
| 702 |
-regimes : Print impulse responses as if each regime were permanent. |
| 703 |
|
| 704 |
-regime s : Print impulse responses as if regime s were permanent. |
| 705 |
|
| 706 |
*/ |
| 707 |
void dw_state_space_impulse_response_command_line(int nargs, char **args, TStateModel *model) |
| 708 |
{ |
| 709 |
FILE *f_out; |
| 710 |
char *out_filename, *fmt, *tag; |
| 711 |
TMatrix posterior_draws; |
| 712 |
TVector percentiles=(TVector)NULL, init_prob=(TVector)NULL; |
| 713 |
int s, i, j, n, nparameters=NumberFreeParametersTheta(model) + NumberFreeParametersQ(model), h, thin, states, observables, |
| 714 |
parameter_uncertainty; |
| 715 |
T_MSStateSpace *statespace; |
| 716 |
|
| 717 |
if (!IsStateSpaceModel(model)) return; |
| 718 |
|
| 719 |
statespace=(T_MSStateSpace*)(model->theta); |
| 720 |
|
| 721 |
tag=GetTag(nargs,args); |
| 722 |
|
| 723 |
ReadParameters(nargs,args,model,2,0); |
| 724 |
|
| 725 |
// Read posterior draws |
| 726 |
if (parameter_uncertainty=(dw_FindArgument_String(nargs,args,"parameter_uncertainty") == -1) ? 0 : 1) |
| 727 |
{ |
| 728 |
printf("Reading posterior draws\n"); |
| 729 |
posterior_draws=dw_ReadPosteriorDraws((FILE*)NULL,(char*)NULL,tag,nparameters); |
| 730 |
if (!posterior_draws) |
| 731 |
{ |
| 732 |
printf("dw_state_space_impulse_response_command_line(): Unable to read posterior draws\n"); |
| 733 |
printf(" tag: %s\n",tag ? tag : "null"); |
| 734 |
dw_exit(0); |
| 735 |
} |
| 736 |
} |
| 737 |
else |
| 738 |
{ |
| 739 |
posterior_draws=(TMatrix)NULL; |
| 740 |
} |
| 741 |
|
| 742 |
// Setup percentiles, horizon, thinning factor |
| 743 |
if ((i=dw_FindArgument_String(nargs,args,"percentiles")) == -1) |
| 744 |
if (parameter_uncertainty) |
| 745 |
{ |
| 746 |
percentiles=CreateVector(3); |
| 747 |
ElementV(percentiles,0)=0.16; ElementV(percentiles,1)=0.5; ElementV(percentiles,2)=0.84; |
| 748 |
} |
| 749 |
else |
| 750 |
{ |
| 751 |
percentiles=CreateVector(1); |
| 752 |
ElementV(percentiles,0)=0.5; |
| 753 |
} |
| 754 |
else |
| 755 |
if ((i+1 < nargs) && dw_IsInteger(args[i+1]) && ((n=atoi(args[i+1])) > 0) && (i+1+n < nargs)) |
| 756 |
{ |
| 757 |
percentiles=CreateVector(n); |
| 758 |
for (j=0; j < n; j++) |
| 759 |
if (!dw_IsFloat(args[i+2+j])|| ((ElementV(percentiles,j)=atof(args[i+2+j])) <= 0.0) |
| 760 |
|| (ElementV(percentiles,j) >= 1.0)) break; |
| 761 |
if (j < n) |
| 762 |
{ |
| 763 |
FreeVector(percentiles); |
| 764 |
printf("dw_state_space_impulse_response_command_line(): Error parsing percentiles\n"); |
| 765 |
dw_exit(0); |
| 766 |
} |
| 767 |
} |
| 768 |
else |
| 769 |
{ |
| 770 |
printf("dw_state_space_impulse_response_command_line(): Error parsing percentiles\n"); |
| 771 |
dw_exit(0); |
| 772 |
} |
| 773 |
h=dw_ParseInteger_String(nargs,args,"horizon",8); |
| 774 |
thin=dw_ParseInteger_String(nargs,args,"thin",1); |
| 775 |
|
| 776 |
// print impulse response of states |
| 777 |
states=(dw_FindArgument_String(nargs,args,"states") == -1) ? 0 : 1; |
| 778 |
|
| 779 |
// print impulse response of observables |
| 780 |
observables=(dw_FindArgument_String(nargs,args,"observables") == -1) ? 0 : 1; |
| 781 |
|
| 782 |
// ergodic impulse responses |
| 783 |
if (dw_FindArgument_String(nargs,args,"ergodic") != -1) |
| 784 |
{ |
| 785 |
if (states) |
| 786 |
{ |
| 787 |
// Open output file for impulse responses of states |
| 788 |
fmt="ir_states_percentiles_ergodic_%s.prn"; |
| 789 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 790 |
f_out=fopen(out_filename,"wt"); |
| 791 |
dw_free(out_filename); |
| 792 |
|
| 793 |
// Compute percentiles for impulse responses of states |
| 794 |
printf("Constructing percentiles for impulse responses of states - ergodic\n"); |
| 795 |
dw_state_space_impulse_response_states_percentile_ergodic(f_out,percentiles,posterior_draws,thin,init_prob,h,model); |
| 796 |
fclose(f_out); |
| 797 |
} |
| 798 |
|
| 799 |
if (observables) |
| 800 |
{ |
| 801 |
// Open output file for impulse responses of observables |
| 802 |
fmt="ir_observables_percentiles_ergodic_%s.prn"; |
| 803 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 804 |
f_out=fopen(out_filename,"wt"); |
| 805 |
dw_free(out_filename); |
| 806 |
|
| 807 |
// Compute percentiles for impulse responses of observables |
| 808 |
printf("Constructing percentiles for impulse responses of observables - ergodic\n"); |
| 809 |
dw_state_space_impulse_response_observables_percentile_ergodic(f_out,percentiles,posterior_draws,thin,init_prob,h,model); |
| 810 |
fclose(f_out); |
| 811 |
} |
| 812 |
} |
| 813 |
|
| 814 |
if (dw_FindArgument_String(nargs,args,"regimes") != -1) |
| 815 |
for (s=0; s < statespace->nbasestates; s++) |
| 816 |
{ |
| 817 |
if (states) |
| 818 |
{ |
| 819 |
// Open output file for impulse responses of states |
| 820 |
fmt="ir_states_percentiles_regime_%d_%s.prn"; |
| 821 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) + 10),fmt,s,tag); |
| 822 |
f_out=fopen(out_filename,"wt"); |
| 823 |
dw_free(out_filename); |
| 824 |
|
| 825 |
// Compute percentiles for impulse responses of states |
| 826 |
printf("Constructing percentiles for impulse responses of states - regime %d\n",s); |
| 827 |
dw_state_space_impulse_response_states_percentile_regime(f_out,s,percentiles,posterior_draws,thin,h,model); |
| 828 |
fclose(f_out); |
| 829 |
} |
| 830 |
|
| 831 |
if (observables) |
| 832 |
{ |
| 833 |
// Open output file for impulse responses of observables |
| 834 |
fmt="ir_observables_percentiles_regime_%d_%s.prn"; |
| 835 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) + 10),fmt,s,tag); |
| 836 |
f_out=fopen(out_filename,"wt"); |
| 837 |
dw_free(out_filename); |
| 838 |
|
| 839 |
// Compute percentiles for impulse responses of observables |
| 840 |
printf("Constructing percentiles for impulse responses of observables - regime %d\n",s); |
| 841 |
dw_state_space_impulse_response_observables_percentile_regime(f_out,s,percentiles,posterior_draws,thin,h,model); |
| 842 |
fclose(f_out); |
| 843 |
} |
| 844 |
} |
| 845 |
else |
| 846 |
if (((s=dw_ParseInteger_String(nargs,args,"regime",-1)) >= 0) && (s < statespace->nbasestates)) |
| 847 |
{ |
| 848 |
if (states) |
| 849 |
{ |
| 850 |
// Open output file for impulse responses of states |
| 851 |
fmt="ir_states_percentiles_regime_%d_%s.prn"; |
| 852 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) + 10),fmt,s,tag); |
| 853 |
f_out=fopen(out_filename,"wt"); |
| 854 |
dw_free(out_filename); |
| 855 |
|
| 856 |
// Compute percentiles for impulse responses of states |
| 857 |
printf("Constructing percentiles for impulse responses of states - regime %d\n",s); |
| 858 |
dw_state_space_impulse_response_states_percentile_regime(f_out,s,percentiles,posterior_draws,thin,h,model); |
| 859 |
fclose(f_out); |
| 860 |
} |
| 861 |
|
| 862 |
if (observables) |
| 863 |
{ |
| 864 |
// Open output file for impulse responses of observables |
| 865 |
fmt="ir_observables_percentiles_regime_%d_%s.prn"; |
| 866 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) + 10),fmt,s,tag); |
| 867 |
f_out=fopen(out_filename,"wt"); |
| 868 |
dw_free(out_filename); |
| 869 |
|
| 870 |
// Compute percentiles for impulse responses of observables |
| 871 |
printf("Constructing percentiles for impulse responses of observables - regime %d\n",s); |
| 872 |
dw_state_space_impulse_response_observables_percentile_regime(f_out,s,percentiles,posterior_draws,thin,h,model); |
| 873 |
fclose(f_out); |
| 874 |
} |
| 875 |
} |
| 876 |
|
| 877 |
FreeMatrix(posterior_draws); |
| 878 |
FreeVector(percentiles); |
| 879 |
} |
| 880 |
|
| 881 |
/* |
| 882 |
Command line parameters |
| 883 |
|
| 884 |
-t <tag> : input and output tag |
| 885 |
|
| 886 |
-ft <tag> : takes precedence over -t |
| 887 |
|
| 888 |
-outtag <tag> : takes presedence over -t and -ft |
| 889 |
|
| 890 |
-parmfile <parameter filename> |
| 891 |
default = simulation_<tag>.out if parameter_uncertainty is set |
| 892 |
|
| 893 |
-states |
| 894 |
Print variance decomposition of state variables. (default = off) |
| 895 |
|
| 896 |
-observables |
| 897 |
Print variance decomposition of observable variables. (default = on unless |
| 898 |
-states is set) |
| 899 |
|
| 900 |
-horizon <integer> |
| 901 |
If this argument exists, then the forecast horizon is given by the passed |
| 902 |
integer. The default value is 12. |
| 903 |
|
| 904 |
-filtered |
| 905 |
Uses filtered probabilities at the end of the sample as initial conditions |
| 906 |
for regime probabilities. The default behavior is to us the erogdic |
| 907 |
distribution for the initial conditions. This flag only applies if neither |
| 908 |
-regimes nor -regime is specified. |
| 909 |
|
| 910 |
-parameter_uncertainty |
| 911 |
Use posterior draws to compute error bands for the variance decomposition. |
| 912 |
|
| 913 |
-shocks_per_parameter <integer> |
| 914 |
Number of regime paths to draw for each parameter draw. The default value |
| 915 |
is 10 if parameter_uncertainty is set and 10,000 otherwise. |
| 916 |
|
| 917 |
-error_bands |
| 918 |
Output percentile error bands. (default = off - mean is computed) |
| 919 |
|
| 920 |
-percentiles n p_1 p_2 ... p_n |
| 921 |
Percentiles to compute. The first parameter after percentiles must be the |
| 922 |
number of percentiles and the following values are the actual percentiles. |
| 923 |
(default = 3 0.16 0.50 0.84 - only meaningful if -error_bands is set) |
| 924 |
|
| 925 |
-thin |
| 926 |
Thinning factor. Only 1/thin of the draws in posterior draws file are |
| 927 |
used. The default value is 1. |
| 928 |
|
| 929 |
-regimes |
| 930 |
Produces forecasts as if each regime were permanent. (default = off) |
| 931 |
|
| 932 |
-regime <integer> |
| 933 |
Produces forecasts as if the given regime were permanent. Regime numbers |
| 934 |
are zero based. (default = off) |
| 935 |
*/ |
| 936 |
static void PrintVarianceDecomposition(int horizon, int observables, TVector percentiles, int draws, FILE *posterior_file, int thin, int regime, int ergodic, char *tag, TStateModel *model) |
| 937 |
{ |
| 938 |
T_MSStateSpace *statespace=(T_MSStateSpace*)(model->theta); |
| 939 |
FILE *f_out; |
| 940 |
char filename[1024]; |
| 941 |
int i, flag=observables ? IR_OBSERVABLES : IR_STATES, nvars=observables ? statespace->ny : statespace->nz, nshocks=observables ? statespace->nepsilon+statespace->nu : statespace->nepsilon; |
| 942 |
TMatrixHistogram *histogram; |
| 943 |
TMatrix tvd; |
| 944 |
|
| 945 |
// reset posterior file |
| 946 |
if (posterior_file) rewind(posterior_file); |
| 947 |
|
| 948 |
// open output file |
| 949 |
strcpy(filename,"vd_"); |
| 950 |
strcat(filename,observables ? "observables_" : "states_"); |
| 951 |
strcat(filename,percentiles ? "percentiles_" : "mean_"); |
| 952 |
if (regime >= 0) |
| 953 |
sprintf(filename+strlen(filename),"regime%d_",regime); |
| 954 |
else |
| 955 |
strcat(filename,ergodic ? "ergodic_" : "filtered_"); |
| 956 |
if (strlen(filename) + strlen(tag) < 1020) |
| 957 |
{ |
| 958 |
strcat(filename,tag); |
| 959 |
strcat(filename,".out"); |
| 960 |
} |
| 961 |
else |
| 962 |
{ |
| 963 |
printf("PrintVarianceDecomposition(): filename too long, increase buffer size."); |
| 964 |
return; |
| 965 |
} |
| 966 |
|
| 967 |
if (f_out=fopen(filename,"wt")) |
| 968 |
{ |
| 969 |
// percentiles or mean |
| 970 |
if (percentiles) |
| 971 |
{ |
| 972 |
if (histogram=(regime >= 0) ? state_space_variance_decomposition_percentiles_regime(posterior_file,thin,regime,horizon,model,flag) |
| 973 |
: state_space_variance_decomposition_percentiles(draws,posterior_file,thin,ergodic,horizon,model,flag)) |
| 974 |
{ |
| 975 |
tvd=CreateMatrix(horizon,nvars*nshocks); |
| 976 |
for (i=0; i < DimV(percentiles); i++) |
| 977 |
{ |
| 978 |
MatrixPercentile(tvd,ElementV(percentiles,i),histogram); |
| 979 |
dw_PrintMatrix(f_out,tvd,"%lg "); |
| 980 |
fprintf(f_out,"\n"); |
| 981 |
} |
| 982 |
FreeMatrix(tvd); |
| 983 |
FreeMatrixHistogram(histogram); |
| 984 |
} |
| 985 |
} |
| 986 |
else |
| 987 |
{ |
| 988 |
if (tvd=(regime >= 0) ? state_space_variance_decomposition_mean_regime(posterior_file,thin,regime,horizon,model,flag) |
| 989 |
: state_space_variance_decomposition_mean(draws,posterior_file,thin,ergodic,horizon,model,flag)) |
| 990 |
{ |
| 991 |
NormalizeVarianceDecomposition(tvd,observables ? statespace->ny : statespace->nz); |
| 992 |
dw_PrintMatrix(f_out,tvd,"%lg "); |
| 993 |
FreeMatrix(tvd); |
| 994 |
} |
| 995 |
} |
| 996 |
|
| 997 |
fclose(f_out); |
| 998 |
} |
| 999 |
} |
| 1000 |
void dw_state_space_variance_decomposition_command_line(int nargs, char **args, TStateModel *model) |
| 1001 |
{ |
| 1002 |
T_MSStateSpace *statespace=(T_MSStateSpace*)(model->theta); |
| 1003 |
FILE *f_posterior; |
| 1004 |
char *filename, *fmt, *tag; |
| 1005 |
TVector percentiles=(TVector)NULL; |
| 1006 |
int s, horizon, thin, states, observables, ergodic, draws; |
| 1007 |
|
| 1008 |
if (!IsStateSpaceModel(model)) return; |
| 1009 |
|
| 1010 |
tag=GetTag(nargs,args); |
| 1011 |
|
| 1012 |
// Parameter uncertainty |
| 1013 |
if (dw_FindArgument_String(nargs,args,"parameter_uncertainty") != -1) |
| 1014 |
{ |
| 1015 |
if (filename=dw_ParseString_String(nargs,args,"parmfile",(char*)NULL)) |
| 1016 |
{ |
| 1017 |
if (!(f_posterior=fopen(filename,"rt"))) |
| 1018 |
{ |
| 1019 |
printf("dw_state_space_variance_decomposition_command line(): Unable to open posterior draws file: %s\n",filename); |
| 1020 |
return; |
| 1021 |
} |
| 1022 |
} |
| 1023 |
else |
| 1024 |
{ |
| 1025 |
fmt="simulation_%s.out"; |
| 1026 |
sprintf(filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 1027 |
if (!(f_posterior=fopen(filename,"rt"))) |
| 1028 |
{ |
| 1029 |
printf("dw_state_space_variance_decomposition_command line(): Unable to open posterior draws file: %s\n",filename); |
| 1030 |
dw_free(filename); |
| 1031 |
return; |
| 1032 |
} |
| 1033 |
dw_free(filename); |
| 1034 |
} |
| 1035 |
thin=dw_ParseInteger_String(nargs,args,"thin",1); |
| 1036 |
draws=dw_ParseInteger_String(nargs,args,"shocks_per_parameter",10); |
| 1037 |
} |
| 1038 |
else |
| 1039 |
{ |
| 1040 |
f_posterior=(FILE*)NULL; |
| 1041 |
thin=1; |
| 1042 |
draws=dw_ParseInteger_String(nargs,args,"shocks_per_parameter",10000); |
| 1043 |
if (!ReadParameters(nargs,args,model,2,0)) |
| 1044 |
{ |
| 1045 |
printf("dw_state_space_variance_decomposition_command line(): Unable to open posterior draws file: %s\n",dw_ParseString_String(nargs,args,"parmfile",(char*)NULL)); |
| 1046 |
return; |
| 1047 |
} |
| 1048 |
} |
| 1049 |
|
| 1050 |
// Error bands and percentiles |
| 1051 |
percentiles=ReadPercentiles(nargs,args); |
| 1052 |
|
| 1053 |
// horizon |
| 1054 |
horizon=dw_ParseInteger_String(nargs,args,"horizon",12); |
| 1055 |
|
| 1056 |
// print variance decomposition of states |
| 1057 |
states=(dw_FindArgument_String(nargs,args,"states") == -1) ? 0 : 1; |
| 1058 |
|
| 1059 |
// print variance decomposition of observables |
| 1060 |
observables=(dw_FindArgument_String(nargs,args,"observables") == -1) ? 1-states : 1; |
| 1061 |
|
| 1062 |
// ergodic variance decomposition |
| 1063 |
ergodic=(dw_FindArgument_String(nargs,args,"filtered") != -1) ? 0 : 1; |
| 1064 |
|
| 1065 |
if (dw_FindArgument_String(nargs,args,"regimes") != -1) |
| 1066 |
for (s=0; s < statespace->nbasestates; s++) |
| 1067 |
{ |
| 1068 |
if (states) PrintVarianceDecomposition(horizon,0,percentiles,draws,f_posterior,thin,s,-1,tag,model); |
| 1069 |
if (observables) PrintVarianceDecomposition(horizon,1,percentiles,draws,f_posterior,thin,s,-1,tag,model); |
| 1070 |
} |
| 1071 |
else |
| 1072 |
if (((s=dw_ParseInteger_String(nargs,args,"regime",-1)) >= 0) && (s < statespace->nbasestates)) |
| 1073 |
{ |
| 1074 |
if (states) PrintVarianceDecomposition(horizon,0,percentiles,draws,f_posterior,thin,s,-1,tag,model); |
| 1075 |
if (observables) PrintVarianceDecomposition(horizon,1,percentiles,draws,f_posterior,thin,s,-1,tag,model); |
| 1076 |
} |
| 1077 |
else |
| 1078 |
{ |
| 1079 |
if (states) PrintVarianceDecomposition(horizon,0,percentiles,draws,f_posterior,thin,-1,ergodic,tag,model); |
| 1080 |
if (observables) PrintVarianceDecomposition(horizon,1,percentiles,draws,f_posterior,thin,-1,ergodic,tag,model); |
| 1081 |
} |
| 1082 |
|
| 1083 |
if (f_posterior) fclose(f_posterior); |
| 1084 |
FreeVector(percentiles); |
| 1085 |
} |
| 1086 |
|
| 1087 |
|
| 1088 |
/* |
| 1089 |
Command line parameters |
| 1090 |
|
| 1091 |
-t <tag> : input and output tag |
| 1092 |
|
| 1093 |
-ft <tag> : takes precedence over -t |
| 1094 |
|
| 1095 |
-outtag <tag> : takes presedence over -t and -ft |
| 1096 |
|
| 1097 |
-parmfile <parameter filename> : parameter filename |
| 1098 |
*/ |
| 1099 |
void dw_state_space_smoothed_shocks_command_line(int nargs, char **args, TStateModel *model) |
| 1100 |
{ |
| 1101 |
FILE *f_out; |
| 1102 |
char *out_filename, *fmt, *tag; |
| 1103 |
TVector *smoothed_shocks; |
| 1104 |
int t; |
| 1105 |
T_MSStateSpace *statespace; |
| 1106 |
|
| 1107 |
if (!IsStateSpaceModel(model)) return; |
| 1108 |
|
| 1109 |
statespace=(T_MSStateSpace*)(model->theta); |
| 1110 |
|
| 1111 |
tag=GetTag(nargs,args); |
| 1112 |
|
| 1113 |
ReadParameters(nargs,args,model,2,0); |
| 1114 |
|
| 1115 |
printf("Constructing smoothed shocks\n"); |
| 1116 |
fmt="smoothedshocks_%s.out"; |
| 1117 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 1118 |
f_out=fopen(out_filename,"wt"); |
| 1119 |
dw_free(out_filename); |
| 1120 |
smoothed_shocks=SmoothedShocks(model); |
| 1121 |
for (t=2; t <= statespace->nobs; t++) |
| 1122 |
{ |
| 1123 |
fprintf(f_out,"%d",t); |
| 1124 |
dw_PrintVector(f_out,smoothed_shocks[t],", %lf"); |
| 1125 |
} |
| 1126 |
fclose(f_out); |
| 1127 |
dw_FreeArray(smoothed_shocks); |
| 1128 |
} |
| 1129 |
|
| 1130 |
/* |
| 1131 |
Command line parameters |
| 1132 |
|
| 1133 |
-t <tag> : input and output tag |
| 1134 |
|
| 1135 |
-ft <tag> : takes precedence over -t |
| 1136 |
|
| 1137 |
-outtag <tag> : takes presedence over -t and -ft |
| 1138 |
|
| 1139 |
-parmfile <parameter filename> : parameter filename |
| 1140 |
*/ |
| 1141 |
void dw_state_space_smoothed_states_command_line(int nargs, char **args, TStateModel *model) |
| 1142 |
{ |
| 1143 |
FILE *f_out; |
| 1144 |
char *out_filename, *fmt, *tag; |
| 1145 |
int t; |
| 1146 |
T_MSStateSpace *statespace; |
| 1147 |
TVector *smoothed_states; |
| 1148 |
|
| 1149 |
if (!IsStateSpaceModel(model)) return; |
| 1150 |
|
| 1151 |
statespace=(T_MSStateSpace*)(model->theta); |
| 1152 |
|
| 1153 |
tag=GetTag(nargs,args); |
| 1154 |
|
| 1155 |
ReadParameters(nargs,args,model,2,0); |
| 1156 |
|
| 1157 |
fmt="smoothedstates_%s.out"; |
| 1158 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 1159 |
f_out=fopen(out_filename,"wt"); |
| 1160 |
dw_free(out_filename); |
| 1161 |
printf("Constructing smoothed states\n"); |
| 1162 |
smoothed_states=SmoothedStates(model); |
| 1163 |
//Smooth_MSStateSpace(model); |
| 1164 |
for (t=1; t <= statespace->nobs; t++) |
| 1165 |
{ |
| 1166 |
fprintf(f_out,"%d",t); |
| 1167 |
dw_PrintVector(f_out,smoothed_states[t],", %lf"); |
| 1168 |
} |
| 1169 |
fclose(f_out); |
| 1170 |
dw_FreeArray(smoothed_states); |
| 1171 |
} |
| 1172 |
|
| 1173 |
/* |
| 1174 |
Command line parameters |
| 1175 |
|
| 1176 |
-t <tag> : input and output tag |
| 1177 |
|
| 1178 |
-ft <tag> : takes precedence over -t |
| 1179 |
|
| 1180 |
-outtag <tag> : takes presedence over -t and -ft |
| 1181 |
|
| 1182 |
-parmfile <parameter filename> : parameter filename |
| 1183 |
|
| 1184 |
-smoothed : produces smoothed probabilities |
| 1185 |
|
| 1186 |
-filtered : produces filtered probabilities |
| 1187 |
|
| 1188 |
-base : produces base probabilities |
| 1189 |
*/ |
| 1190 |
void dw_state_space_probabilities_command_line(int nargs, char **args, TStateModel *model) |
| 1191 |
{ |
| 1192 |
char *out_filename, *fmt, *tag; |
| 1193 |
FILE *f_out; |
| 1194 |
int t; |
| 1195 |
T_MSStateSpace *statespace; |
| 1196 |
TVector *base; |
| 1197 |
|
| 1198 |
if (!IsStateSpaceModel(model)) return; |
| 1199 |
|
| 1200 |
statespace=(T_MSStateSpace*)(model->theta); |
| 1201 |
|
| 1202 |
tag=GetTag(nargs,args); |
| 1203 |
|
| 1204 |
ReadParameters(nargs,args,model,2,0); |
| 1205 |
|
| 1206 |
if (dw_FindArgument_String(nargs,args,"smoothed") != -1) |
| 1207 |
if (dw_FindArgument_String(nargs,args,"base") != -1) |
| 1208 |
{ |
| 1209 |
printf("Constructing smoothed base probabilities\n"); |
| 1210 |
fmt="smoothbaseprob_%s.out"; |
| 1211 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 1212 |
if (f_out=fopen(out_filename,"wt")) |
| 1213 |
{ |
| 1214 |
if (ComputeSmoothedProbabilities(model)) |
| 1215 |
{ |
| 1216 |
base=sv_FullBaseProbabilities(model->SP,model->sv); |
| 1217 |
for (t=0; t <= statespace->nobs; t++) |
| 1218 |
{ |
| 1219 |
fprintf(f_out,"%d",t); |
| 1220 |
dw_PrintVector(f_out,base[t],", %lf"); |
| 1221 |
} |
| 1222 |
dw_FreeArray(base); |
| 1223 |
} |
| 1224 |
fclose(f_out); |
| 1225 |
} |
| 1226 |
dw_free(out_filename); |
| 1227 |
} |
| 1228 |
else |
| 1229 |
{ |
| 1230 |
printf("Constructing smoothed probabilities\n"); |
| 1231 |
fmt="smoothprob_%s.out"; |
| 1232 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 1233 |
if (f_out=fopen(out_filename,"wt")) |
| 1234 |
{ |
| 1235 |
if (ComputeSmoothedProbabilities(model)) |
| 1236 |
{ |
| 1237 |
for (t=0; t <= statespace->nobs; t++) |
| 1238 |
{ |
| 1239 |
fprintf(f_out,"%d",t); |
| 1240 |
dw_PrintVector(f_out,model->SP[t],", %lf"); |
| 1241 |
} |
| 1242 |
} |
| 1243 |
fclose(f_out); |
| 1244 |
} |
| 1245 |
dw_free(out_filename); |
| 1246 |
} |
| 1247 |
|
| 1248 |
if (dw_FindArgument_String(nargs,args,"filtered") != -1) |
| 1249 |
{ |
| 1250 |
printf("Constructing filtered probabilities\n"); |
| 1251 |
fmt="filterprob_%s.out"; |
| 1252 |
sprintf(out_filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 1253 |
if (f_out=fopen(out_filename,"wt")) |
| 1254 |
{ |
| 1255 |
if (ForwardRecursion(model->nobs,model)) |
| 1256 |
{ |
| 1257 |
for (t=0; t <= statespace->nobs; t++) |
| 1258 |
{ |
| 1259 |
fprintf(f_out,"%d",t); |
| 1260 |
dw_PrintVector(f_out,model->V[t],", %lf"); |
| 1261 |
} |
| 1262 |
} |
| 1263 |
fclose(f_out); |
| 1264 |
} |
| 1265 |
dw_free(out_filename); |
| 1266 |
} |
| 1267 |
} |
| 1268 |
|
| 1269 |
/* |
| 1270 |
Command line parameters |
| 1271 |
|
| 1272 |
-t <tag> : input and output tag |
| 1273 |
|
| 1274 |
-ft <tag> : takes precedence over -t |
| 1275 |
|
| 1276 |
-outtag <tag> : takes presedence over -t and -ft |
| 1277 |
|
| 1278 |
-parmfile <parameter filename> |
| 1279 |
|
| 1280 |
-shocks <epsilon shocks filename> : default smoothedshocks_<tag>.out |
| 1281 |
|
| 1282 |
-prob <marginal regime probabilities filename> : default smoothbaseprob_<tag>.out |
| 1283 |
|
| 1284 |
-states <states filename> : default smoothedstates_<tag>.out |
| 1285 |
|
| 1286 |
-t0 <integer> : first period to produce counterfactual data (default = 1) |
| 1287 |
*/ |
| 1288 |
void dw_state_space_counterfactual_command_line(int nargs, char **args, TStateModel *model) |
| 1289 |
{ |
| 1290 |
char *filename, *fmt, *tag, *shocks_filename, *prob_filename, *states_filename; |
| 1291 |
FILE *f_out; |
| 1292 |
int t0; |
| 1293 |
T_MSStateSpace *statespace; |
| 1294 |
TMatrix data, shocks, prob, states; |
| 1295 |
|
| 1296 |
printf("Constructing counterfactual experiment\n"); |
| 1297 |
|
| 1298 |
if (!IsStateSpaceModel(model)) return; |
| 1299 |
|
| 1300 |
statespace=(T_MSStateSpace*)(model->theta); |
| 1301 |
|
| 1302 |
tag=GetTag(nargs,args); |
| 1303 |
|
| 1304 |
ReadParameters(nargs,args,model,2,0); |
| 1305 |
|
| 1306 |
t0=dw_ParseInteger_String(nargs,args,"t0",1); |
| 1307 |
|
| 1308 |
// shocks |
| 1309 |
fmt="smoothedshocks_%s.out"; |
| 1310 |
sprintf(filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 1311 |
shocks_filename=dw_ParseString_String(nargs,args,"shocks",filename); |
| 1312 |
shocks=dw_ReadDelimitedFile_matrix((FILE*)NULL,shocks_filename,',',REMOVE_EMPTY_FIELDS | STRIP_WHITESPACE,-1.0e-300); |
| 1313 |
|
| 1314 |
if (shocks) |
| 1315 |
{ |
| 1316 |
printf("shocks file: %s\n",shocks_filename); |
| 1317 |
dw_free(filename); |
| 1318 |
// base probabilities |
| 1319 |
fmt="smoothbaseprob_%s.out"; |
| 1320 |
sprintf(filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 1321 |
prob_filename=dw_ParseString_String(nargs,args,"prob",filename); |
| 1322 |
prob=dw_ReadDelimitedFile_matrix((FILE*)NULL,prob_filename,',',REMOVE_EMPTY_FIELDS | STRIP_WHITESPACE,-1.0e-300); |
| 1323 |
|
| 1324 |
if (prob) |
| 1325 |
{ |
| 1326 |
printf("probabilities file: %s\n",prob_filename); |
| 1327 |
dw_free(filename); |
| 1328 |
// states |
| 1329 |
fmt="smoothedstates_%s.out"; |
| 1330 |
sprintf(filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 1331 |
states_filename=dw_ParseString_String(nargs,args,"states",filename); |
| 1332 |
states=dw_ReadDelimitedFile_matrix((FILE*)NULL,states_filename,',',REMOVE_EMPTY_FIELDS | STRIP_WHITESPACE,-1.0e-300); |
| 1333 |
|
| 1334 |
if (states) |
| 1335 |
{ |
| 1336 |
printf("states file: %s\n",states_filename); |
| 1337 |
dw_free(filename); |
| 1338 |
fmt="counterfactual_%s.out"; |
| 1339 |
sprintf(filename=(char*)dw_malloc(strlen(fmt) + strlen(tag) - 1),fmt,tag); |
| 1340 |
if (f_out=fopen(filename,"wt")) |
| 1341 |
{ |
| 1342 |
if (data=dw_state_space_counterfactual((TMatrix)NULL,t0,states,shocks,prob,model)) |
| 1343 |
{ |
| 1344 |
dw_PrintMatrix(f_out,data,"%lg, "); |
| 1345 |
FreeMatrix(data); |
| 1346 |
} |
| 1347 |
else |
| 1348 |
printf("Error producing counterfactual\n"); |
| 1349 |
fclose(f_out); |
| 1350 |
} |
| 1351 |
else |
| 1352 |
printf("Unable to create output file: %s\n",filename); |
| 1353 |
dw_free(filename); |
| 1354 |
FreeMatrix(states); |
| 1355 |
} |
| 1356 |
else |
| 1357 |
{ |
| 1358 |
printf("Unable to open smoothed states file: %s\n",states_filename); |
| 1359 |
dw_free(filename); |
| 1360 |
} |
| 1361 |
FreeMatrix(prob); |
| 1362 |
} |
| 1363 |
else |
| 1364 |
{ |
| 1365 |
printf("Unable to open smoothed probabilities file: %s\n",prob_filename); |
| 1366 |
dw_free(filename); |
| 1367 |
} |
| 1368 |
FreeMatrix(shocks); |
| 1369 |
} |
| 1370 |
else |
| 1371 |
{ |
| 1372 |
printf("Unable to open smoothed shocks file: %s\n",shocks_filename); |
| 1373 |
dw_free(filename); |
| 1374 |
} |
| 1375 |
} |
| 1376 |
|
| 1377 |
/* |
| 1378 |
Command line parameter - see each function for specific parameters |
| 1379 |
|
| 1380 |
-forecast : produce forecast |
| 1381 |
-ir : produce impulse responses |
| 1382 |
-historical : produce historical decomposition |
| 1383 |
-smoothedshocks : produce smoothed shocks |
| 1384 |
-smoothedstates : produce smoothed states |
| 1385 |
-probabilties : produce smoothed or filtered probabilities |
| 1386 |
-counterfactual : produce counterfactual experiment |
| 1387 |
*/ |
| 1388 |
void dw_command_line_statespace_output(int nargs, char** args, TStateModel *model) |
| 1389 |
{ |
| 1390 |
// forecasts |
| 1391 |
if (dw_FindArgument_String(nargs,args,"forecast") != -1) |
| 1392 |
dw_state_space_forecast_command_line(nargs,args,model); |
| 1393 |
|
| 1394 |
// impulse responses - requires posterior draws |
| 1395 |
if (dw_FindArgument_String(nargs,args,"ir") != -1) |
| 1396 |
dw_state_space_impulse_response_command_line(nargs,args,model); |
| 1397 |
|
| 1398 |
// historical decomposition |
| 1399 |
if (dw_FindArgument_String(nargs,args,"historical") != -1) |
| 1400 |
dw_state_space_historical_decomposition_command_line(nargs,args,model); |
| 1401 |
|
| 1402 |
// smoothed shocks |
| 1403 |
if (dw_FindArgument_String(nargs,args,"smoothedshocks") != -1) |
| 1404 |
dw_state_space_smoothed_shocks_command_line(nargs,args,model); |
| 1405 |
|
| 1406 |
// smoothed states |
| 1407 |
if (dw_FindArgument_String(nargs,args,"smoothedstates") != -1) |
| 1408 |
dw_state_space_smoothed_states_command_line(nargs,args,model); |
| 1409 |
|
| 1410 |
// probabilities |
| 1411 |
if (dw_FindArgument_String(nargs,args,"probabilities") != -1) |
| 1412 |
dw_state_space_probabilities_command_line(nargs,args,model); |
| 1413 |
|
| 1414 |
// counterfactual |
| 1415 |
if (dw_FindArgument_String(nargs,args,"counterfactual") != -1) |
| 1416 |
dw_state_space_counterfactual_command_line(nargs,args,model); |
| 1417 |
|
| 1418 |
// simulation |
| 1419 |
if (dw_FindArgument_String(nargs,args,"simulation") != -1) |
| 1420 |
dw_state_space_simulate_command_line(nargs,args,model); |
| 1421 |
|
| 1422 |
// mdd |
| 1423 |
if (dw_FindArgument_String(nargs,args,"mdd") != -1) |
| 1424 |
dw_marginal_data_density_command_line(nargs,args,model,0); |
| 1425 |
|
| 1426 |
// variance decomposition |
| 1427 |
if (dw_FindArgument_String(nargs,args,"variance_decomposition") != -1) |
| 1428 |
dw_state_space_variance_decomposition_command_line(nargs,args,model); |
| 1429 |
} |