%% Driver for SMMF
clear all; close all; home();

%% II. Settings

% Data file and number of observations
data_file = 'GPMdata'; 
nobs = 69;

% Beginning of forecasting horizon
forecastdd='2011Q2'; %tunes
forecastdd_res = '2011Q4'; %shocks

% Define the model to use
md = 'GPM6.mod';
% Definition of the Basename used in estimation
bs = 'May19';
%Definition of the current Basename
bs_baseline = 'Oct14';
%Defintion of Previous Basename for comparison
bs_oldver = 'Aug9';

% Forecast and Reporting related
numper=100;
qrng=qq(2010,4):qq(2012,4);	% quarterly ; tables
arng=yy(2010):yy(2013);	 	% annual; tables
prng=qq(2007,1):qq(2012,4); % range for plots
frng = str2dat(forecastdd):qq(2014,4); % range for potential tunes in plan
outfile1= 'Oct14'; % filename
title1= 'GPM Oct14'; % title

%% III. Prepare and run smoother before plans

%Tune some historical trends to values from previous baseline
d15   = dbload('tunes.csv');
dfix  = dbempty();

% historical range
hrng = str2dat(forecastdd)-nobs:str2dat(forecastdd)-1;

% output gap
dfix.Y_US = d15.Y_US{hrng(end-15)};
dfix.Y_EU = d15.Y_EU{hrng(end-15)};
dfix.Y_JA = d15.Y_JA{hrng(end-15)};
dfix.Y_LA6 = d15.Y_LA6{hrng(end-8)};
dfix.Y_RC6 = d15.Y_RC6{hrng(end-15)};
dfix.Y_EA6 = d15.Y_EA6{hrng(end-1)};

% potential growth
dfix.GROWTH_BAR_US = d15.GROWTH_BAR_US{hrng};
dfix.GROWTH_BAR_EU = d15.GROWTH_BAR_EU{hrng};
dfix.GROWTH_BAR_JA = d15.GROWTH_BAR_JA{hrng};
dfix.GROWTH_BAR_LA6 = d15.GROWTH_BAR_LA6{hrng};
dfix.GROWTH_BAR_EA6 = d15.GROWTH_BAR_EA6{hrng};
dfix.GROWTH_BAR_RC6 = d15.GROWTH_BAR_RC6{hrng};

% nairu 
dfix.UNR_BAR_US = d15.UNR_BAR_US{hrng};
dfix.UNR_BAR_EU = d15.UNR_BAR_EU{hrng};
dfix.UNR_BAR_JA = d15.UNR_BAR_JA{hrng};

% % rr_bar
dfix.RR_BAR_US = d15.RR_BAR_US{hrng(end)};

parset = struct();

vcovset = struct(); 

corr = struct();
corr.RES_BLT_US__RES_G_US  = 0.8759;
corr.RES_LGDP_BAR_US__RES_PIE_US  = 0.0915;
corr.RES_Y_JA__RES_G_JA  = 0.2156;
corr.RES_LGDP_BAR_JA__RES_PIE_JA  = 0.0917;
corr.RES_Y_EU__RES_G_EU  = 0.2476;
corr.RES_LGDP_BAR_EU__RES_PIE_EU  = 0.0961;
corr.RES_Y_EA6__RES_G_EA6 = 0.25;
corr.RES_LGDP_BAR_EA6__RES_PIE_EA6 = 0.1;
corr.RES_Y_LA6__RES_G_LA6 = 0.25;
corr.RES_LGDP_BAR_LA6__RES_PIE_LA6 = 0.1;
corr.RES_Y_RC6__RES_G_RC6 = 0.25;
corr.RES_LGDP_BAR_RC6__RES_PIE_RC6 = 0.1;

PP = {'DOLRR', 'DOINCLUDEREPORTVARS',...
    '@@@histfixvars@@@= Y_JA Y_EU Y_US Y_EA6 Y_LA6 Y_RC6 GROWTH_BAR_US GROWTH_BAR_EU GROWTH_BAR_JA GROWTH_BAR_LA6 GROWTH_BAR_EA6 GROWTH_BAR_RC6 UNR_BAR_US UNR_BAR_EU UNR_BAR_JA RR_BAR_US',...
    'FINALPARAMSETTING','FINALVCOVSETTING'...
    ['@@@final_vcov_setting@@@=' make_setting_str(vcovset,'stderrs') make_setting_str(corr,'corr')],...
    ['@@@final_param_setting@@@=' make_setting_str(parset,'params')]};

PPsmoother = {PP{:}, 'DORMSE'};
run_smoother('PP', PPsmoother, 'data', data_file,...
     'basename', bs,...
     'forecastdate', forecastdd,...
     'model', md,...
     'nobs', nobs,...
     'histfix', dfix,...
     'dynwkspace', [bs '_dynare_workspace.mat'],...
     'runsirsmooth', true, 'doreport', true);
